kopia lustrzana https://github.com/corrscope/corrscope
Fix tests (CLI sink fixtures)
rodzic
7923812407
commit
7e93c60f9a
|
@ -80,19 +80,20 @@ def find(a: 'np.ndarray[T]', predicate: 'Callable[[np.ndarray[T]], np.ndarray[bo
|
|||
i0 = i1
|
||||
|
||||
|
||||
# Adapted from https://stackoverflow.com/a/9458386
|
||||
def curry(x, argc=None):
|
||||
if argc is None:
|
||||
argc = x.__code__.co_argcount
|
||||
|
||||
@wraps(x)
|
||||
def p(*a):
|
||||
if len(a) == argc:
|
||||
return x(*a)
|
||||
|
||||
def q(*b):
|
||||
return x(*(a + b))
|
||||
|
||||
return curry(q, argc - len(a))
|
||||
|
||||
return p
|
||||
# # Adapted from https://stackoverflow.com/a/9458386
|
||||
# def curry(x, argc=None):
|
||||
# if argc is None:
|
||||
# argc = x.__code__.co_argcount
|
||||
#
|
||||
# @wraps(x)
|
||||
# def p(*a):
|
||||
# if len(a) == argc:
|
||||
# return x(*a)
|
||||
#
|
||||
# def q(*b):
|
||||
# return x(*(a + b))
|
||||
#
|
||||
# return curry(q, argc - len(a))
|
||||
#
|
||||
# del p.__wrapped__
|
||||
# return p
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import shlex
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING
|
||||
from typing import TYPE_CHECKING, Callable
|
||||
|
||||
import click
|
||||
import pytest
|
||||
|
@ -9,7 +9,6 @@ from click.testing import CliRunner
|
|||
from ovgenpy import cli
|
||||
from ovgenpy.config import yaml
|
||||
from ovgenpy.ovgenpy import Config
|
||||
from ovgenpy.util import curry
|
||||
|
||||
if TYPE_CHECKING:
|
||||
import pytest_mock
|
||||
|
@ -22,35 +21,40 @@ def call_main(args):
|
|||
# ovgenpy configuration sinks
|
||||
|
||||
@pytest.fixture
|
||||
@curry
|
||||
def yaml_sink(mocker: 'pytest_mock.MockFixture', command):
|
||||
dump = mocker.patch.object(yaml, 'dump')
|
||||
def yaml_sink(mocker: 'pytest_mock.MockFixture') -> Callable:
|
||||
def _yaml_sink(command):
|
||||
dump = mocker.patch.object(yaml, 'dump')
|
||||
|
||||
args = shlex.split(command) + ['-w']
|
||||
call_main(args)
|
||||
argv = shlex.split(command) + ['-w']
|
||||
call_main(argv)
|
||||
|
||||
dump.assert_called_once()
|
||||
args, kwargs = dump.call_args
|
||||
dump.assert_called_once()
|
||||
(cfg, stream), kwargs = dump.call_args
|
||||
|
||||
cfg = args[0] # yaml.dump(cfg, out)
|
||||
assert isinstance(cfg, Config)
|
||||
return cfg
|
||||
assert isinstance(cfg, Config)
|
||||
return cfg, stream
|
||||
return _yaml_sink
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@curry
|
||||
def player_sink(mocker, command):
|
||||
Ovgen = mocker.patch.object(cli, 'Ovgen')
|
||||
def player_sink(mocker) -> Callable:
|
||||
def _player_sink(command):
|
||||
Ovgen = mocker.patch.object(cli, 'Ovgen')
|
||||
|
||||
args = shlex.split(command) + ['-p']
|
||||
call_main(args)
|
||||
argv = shlex.split(command) + ['-p']
|
||||
call_main(argv)
|
||||
|
||||
Ovgen.assert_called_once()
|
||||
args, kwargs = Ovgen.call_args
|
||||
Ovgen.assert_called_once()
|
||||
(cfg,), kwargs = Ovgen.call_args
|
||||
|
||||
cfg = args[0] # Ovgen(cfg)
|
||||
assert isinstance(cfg, Config)
|
||||
return cfg
|
||||
assert isinstance(cfg, Config)
|
||||
return cfg,
|
||||
return _player_sink
|
||||
|
||||
|
||||
def test_sink_fixture(yaml_sink, player_sink):
|
||||
""" Ensure we can use yaml_sink and player_sink as a fixture directly """
|
||||
pass
|
||||
|
||||
|
||||
@pytest.fixture(params=[yaml_sink, player_sink])
|
||||
|
@ -67,11 +71,12 @@ def test_no_files(any_sink):
|
|||
|
||||
|
||||
@pytest.mark.parametrize('wav_dir', '. tests'.split())
|
||||
def test_cwd(any_sink, wav_dir):
|
||||
def test_file_dirs(any_sink, wav_dir):
|
||||
""" Ensure loading files from `dir` places `dir/*.wav` in config. """
|
||||
wavs = Path(wav_dir).glob('*.wav')
|
||||
wavs = sorted(str(x) for x in wavs)
|
||||
|
||||
cfg = any_sink(wav_dir)
|
||||
cfg = any_sink(wav_dir)[0]
|
||||
assert isinstance(cfg, Config)
|
||||
|
||||
assert [chan.wav_path for chan in cfg.channels] == wavs
|
||||
|
|
Ładowanie…
Reference in New Issue