Merge pull request #375 from corrscope/update-deps

pull/377/head
nyanpasu64 2021-06-14 15:26:21 -07:00 zatwierdzone przez GitHub
commit f80730ffd7
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
7 zmienionych plików z 718 dodań i 450 usunięć

Wyświetl plik

@ -59,7 +59,7 @@ class MainWindow(QWidget):
width = 1280 width = 1280
height = 0 height = 0
MainWindow.resize(width * scale, height * scale) MainWindow.resize(int(width * scale), int(height * scale))
s = LayoutStack(MainWindow) s = LayoutStack(MainWindow)

965
poetry.lock wygenerowano

Plik diff jest za duży Load Diff

Wyświetl plik

@ -19,34 +19,30 @@ repository = "https://github.com/corrscope/corrscope/"
documentation = "https://corrscope.github.io/corrscope/" documentation = "https://corrscope.github.io/corrscope/"
[tool.poetry.dependencies] [tool.poetry.dependencies]
python = "^3.6" python = "^3.6.2"
"ruamel.yaml" = "^0.16" "ruamel.yaml" = "^0.17"
numpy = "^1.15" numpy = "^1.15"
click = "^7.0" click = "^8.0.1"
matplotlib = "^3.1" matplotlib = "^3.1"
attrs = "^18.2.0" attrs = "^21.2.0"
PyQt5 = "^5.11" PyQt5 = "^5.15.4"
appdirs = "^1.4" appdirs = "^1.4.4"
[tool.poetry.dev-dependencies] [tool.poetry.dev-dependencies]
pytest = "^4.0" pytest = "^6.2.4"
pytest_mock = "^1.10" pytest-mock = "^3.6.1"
hypothesis = "^3.84" hypothesis = "^6.14.0"
delayed-assert = "^0.2.3" delayed-assert = "^0.3.5"
pyinstaller = "^3.6" pyinstaller = "^4.3"
# poetry fails to pick up pyinstaller's dependencies. pefile = {version = "^2021.5.24", platform = "win32"}
# https://github.com/python-poetry/poetry/issues/1431#issuecomment-571661982
# https://github.com/pyinstaller/pyinstaller/issues/4609 fixed in pyinstaller, but not released yet.
pywin32-ctypes = {version = ">=0.2.0", platform = "win32"}
pefile = {version = ">=2017.8.1", platform = "win32"}
coverage = "^4.5" coverage = "^5.5"
pytest-cov = "^2.6" pytest-cov = "^2.12.1"
codecov = "^2.1" codecov = "^2.1.11"
pytest_cases = "^1.2" pytest-cases = "^3.6.1"
black = {version = "^18.3-alpha.0", allow-prereleases = true} black = "^21.6b0"
[tool.poetry.scripts] [tool.poetry.scripts]
corr = 'corrscope.cli:main' corr = 'corrscope.cli:main'

Wyświetl plik

@ -1,10 +1,11 @@
from contextlib import ExitStack
from typing import Optional from typing import Optional
import hypothesis.strategies as hs import hypothesis.strategies as hs
import numpy as np import numpy as np
import pytest import pytest
from hypothesis import given from hypothesis import given
from pytest_mock import MockFixture from unittest.mock import patch
import corrscope.channel import corrscope.channel
import corrscope.corrscope import corrscope.corrscope
@ -49,7 +50,6 @@ def test_config_channel_integration(
rsub: int, rsub: int,
default_label: DefaultLabel, default_label: DefaultLabel,
override_label: bool, override_label: bool,
mocker: MockFixture,
): ):
"""(Tautologically) verify: """(Tautologically) verify:
- channel. r_samp (given cfg) - channel. r_samp (given cfg)
@ -59,77 +59,80 @@ def test_config_channel_integration(
- rendered label (channel.label, given cfg, corr_cfg.default_label) - rendered label (channel.label, given cfg, corr_cfg.default_label)
""" """
# region setup test variables with ExitStack() as stack:
corrscope.corrscope.PRINT_TIMESTAMP = False # Cleanup Hypothesis testing logs # region setup test variables
corrscope.corrscope.PRINT_TIMESTAMP = False # Cleanup Hypothesis testing logs
Wave = mocker.patch.object(corrscope.channel, "Wave") Wave = stack.enter_context(patch.object(corrscope.channel, "Wave"))
wave = Wave.return_value wave = Wave.return_value
def get_around(sample: int, return_nsamp: int, stride: int): def get_around(sample: int, return_nsamp: int, stride: int):
return np.zeros(return_nsamp) return np.zeros(return_nsamp)
wave.get_around.side_effect = get_around wave.get_around.side_effect = get_around
wave.with_flatten.return_value = wave wave.with_flatten.return_value = wave
wave.nsamp = 10000 wave.nsamp = 10000
wave.smp_s = 48000 wave.smp_s = 48000
ccfg = ChannelConfig( ccfg = ChannelConfig(
"tests/sine440.wav", "tests/sine440.wav",
trigger_width=c_trigger_width, trigger_width=c_trigger_width,
render_width=c_render_width, render_width=c_render_width,
amplification=c_amplification, amplification=c_amplification,
label="label" if override_label else "", label="label" if override_label else "",
)
def get_cfg():
return template_config(
trigger_ms=trigger_ms,
render_ms=render_ms,
trigger_subsampling=tsub,
render_subsampling=rsub,
amplification=amplification,
channels=[ccfg],
default_label=default_label,
trigger=NullTriggerConfig(),
benchmark_mode=BenchmarkMode.OUTPUT,
) )
# endregion def get_cfg():
return template_config(
trigger_ms=trigger_ms,
render_ms=render_ms,
trigger_subsampling=tsub,
render_subsampling=rsub,
amplification=amplification,
channels=[ccfg],
default_label=default_label,
trigger=NullTriggerConfig(),
benchmark_mode=BenchmarkMode.OUTPUT,
)
cfg = get_cfg() # endregion
channel = Channel(ccfg, cfg)
# Ensure cfg.width_ms etc. are correct cfg = get_cfg()
assert cfg.trigger_ms == trigger_ms channel = Channel(ccfg, cfg)
assert cfg.render_ms == render_ms
# Ensure channel.window_samp, trigger_subsampling, render_subsampling are correct. # Ensure cfg.width_ms etc. are correct
def ideal_samp(width_ms, sub): assert cfg.trigger_ms == trigger_ms
width_s = width_ms / 1000 assert cfg.render_ms == render_ms
return pytest.approx(
round(width_s * channel.trigger_wave.smp_s / sub), rel=1e-6
)
ideal_tsamp = ideal_samp(cfg.trigger_ms, tsub) # Ensure channel.window_samp, trigger_subsampling, render_subsampling are correct.
ideal_rsamp = ideal_samp(cfg.render_ms, rsub) def ideal_samp(width_ms, sub):
assert channel._render_samp == ideal_rsamp width_s = width_ms / 1000
return pytest.approx(
round(width_s * channel.trigger_wave.smp_s / sub), rel=1e-6
)
assert channel._trigger_stride == tsub * c_trigger_width ideal_tsamp = ideal_samp(cfg.trigger_ms, tsub)
assert channel.render_stride == rsub * c_render_width ideal_rsamp = ideal_samp(cfg.render_ms, rsub)
assert channel._render_samp == ideal_rsamp
# Ensure amplification override works assert channel._trigger_stride == tsub * c_trigger_width
args, kwargs = Wave.call_args assert channel.render_stride == rsub * c_render_width
assert kwargs["amplification"] == coalesce(c_amplification, amplification)
## Ensure trigger uses channel.window_samp and _trigger_stride. # Ensure amplification override works
trigger = channel.trigger args, kwargs = Wave.call_args
assert trigger._tsamp == ideal_tsamp assert kwargs["amplification"] == coalesce(c_amplification, amplification)
assert trigger._stride == channel._trigger_stride
## Ensure corrscope calls render using channel._render_samp and _render_stride. ## Ensure trigger uses channel.window_samp and _trigger_stride.
corr = CorrScope(cfg, Arguments(cfg_dir=".", outputs=[])) trigger = channel.trigger
renderer = mocker.patch.object(CorrScope, "_load_renderer").return_value assert trigger._tsamp == ideal_tsamp
corr.play() assert trigger._stride == channel._trigger_stride
## Ensure corrscope calls render using channel._render_samp and _render_stride.
corr = CorrScope(cfg, Arguments(cfg_dir=".", outputs=[]))
renderer = stack.enter_context(
patch.object(CorrScope, "_load_renderer")
).return_value
corr.play()
# Only Channel.get_render_around() (not NullTrigger) calls wave.get_around(). # Only Channel.get_render_around() (not NullTrigger) calls wave.get_around().
(_sample, _return_nsamp, _subsampling), kwargs = wave.get_around.call_args (_sample, _return_nsamp, _subsampling), kwargs = wave.get_around.call_args

Wyświetl plik

@ -1,5 +1,5 @@
import pytest import pytest
from pytest_cases import pytest_fixture_plus from pytest_cases import fixture
from corrscope.gui.model_bind import rgetattr, rsetattr, rhasattr, flatten_attr from corrscope.gui.model_bind import rgetattr, rsetattr, rhasattr, flatten_attr
@ -22,7 +22,7 @@ class Residence(object):
self.sqft = sqft self.sqft = sqft
@pytest_fixture_plus @fixture
@pytest.mark.parametrize("s", ["__", "."]) @pytest.mark.parametrize("s", ["__", "."])
def separator(s: str) -> str: def separator(s: str) -> str:
return s return s

Wyświetl plik

@ -1,4 +1,6 @@
from contextlib import ExitStack
from typing import Optional, TYPE_CHECKING, List from typing import Optional, TYPE_CHECKING, List
from unittest.mock import patch
import attr import attr
import hypothesis.strategies as hs import hypothesis.strategies as hs
@ -396,15 +398,14 @@ def test_res_divisor_rounding_fixed(target_int: int, res_divisor: float):
@given(target_int=hs.integers(1, 10000), res_divisor=hs.floats(1, 100)) @given(target_int=hs.integers(1, 10000), res_divisor=hs.floats(1, 100))
def test_res_divisor_rounding_hypothesis(target_int: int, res_divisor: float, mocker): def test_res_divisor_rounding_hypothesis(target_int: int, res_divisor: float):
verify_res_divisor_rounding(target_int, res_divisor, speed_hack=True, mocker=mocker) verify_res_divisor_rounding(target_int, res_divisor, speed_hack=True)
def verify_res_divisor_rounding( def verify_res_divisor_rounding(
target_int: int, target_int: int,
res_divisor: float, res_divisor: float,
speed_hack: bool, speed_hack: bool,
mocker: "pytest_mock.MockFixture" = None,
): ):
"""Ensure that pathological-case float rounding errors """Ensure that pathological-case float rounding errors
don't cause inconsistent dimensions and assertion errors.""" don't cause inconsistent dimensions and assertion errors."""
@ -414,20 +415,23 @@ def verify_res_divisor_rounding(
cfg = RendererConfig(undivided_dim, undivided_dim, res_divisor=res_divisor) cfg = RendererConfig(undivided_dim, undivided_dim, res_divisor=res_divisor)
cfg.before_preview() cfg.before_preview()
if speed_hack: with ExitStack() as stack:
mocker.patch.object(AbstractMatplotlibRenderer, "_save_background") if speed_hack:
datas = [] stack.enter_context(
else: patch.object(AbstractMatplotlibRenderer, "_save_background")
datas = [RENDER_Y_ZEROS] )
datas = []
else:
datas = [RENDER_Y_ZEROS]
try: try:
renderer = Renderer(cfg, LayoutConfig(), datas, None, None) renderer = Renderer(cfg, LayoutConfig(), datas, None, None)
if not speed_hack: if not speed_hack:
renderer.update_main_lines(datas) renderer.update_main_lines(datas)
renderer.get_frame() renderer.get_frame()
except Exception: except Exception:
perr(cfg.divided_width) perr(cfg.divided_width)
raise raise
# X-axis stride tests # X-axis stride tests

Wyświetl plik

@ -7,7 +7,7 @@ from matplotlib.axes import Axes
from matplotlib.figure import Figure from matplotlib.figure import Figure
# Pycharm assumes anything called "fixture" is pytest.fixture. # Pycharm assumes anything called "fixture" is pytest.fixture.
from pytest_cases import pytest_fixture_plus as fixture from pytest_cases import fixture
from corrscope import triggers from corrscope import triggers
from corrscope.triggers import ( from corrscope.triggers import (