[wip] Add unit tests for CLI parser

pull/357/head
nyanpasu64 2018-08-19 21:42:43 -07:00
rodzic 47a8450669
commit 2a19afce5f
2 zmienionych plików z 46 dodań i 0 usunięć
ovgenpy

Wyświetl plik

@ -146,6 +146,8 @@ def main(
if show_gui:
raise OvgenError('GUI not implemented')
else:
if not files:
raise click.ClickException('Must specify files or folders to play')
if write:
if audio:
write_path = Path(audio).with_suffix(YAML_NAME)

44
tests/test_cli.py 100644
Wyświetl plik

@ -0,0 +1,44 @@
import os
import shlex
from contextlib import contextmanager
from typing import TYPE_CHECKING, List, Tuple, ContextManager, Callable
import click
import pytest
from click.testing import CliRunner
from ovgenpy import cli
from ovgenpy.config import yaml
from ovgenpy.ovgenpy import Config
if TYPE_CHECKING:
import pytest_mock
def call_main(args):
return CliRunner().invoke(cli.main, args, catch_exceptions=False, standalone_mode=False)
# ovgenpy configuration sinks
def write_yaml(command):
args = shlex.split(command) + ['-w']
return call_main(args)
def play(command):
args = shlex.split(command) + ['-p']
return call_main(args)
# ovgenpy configuration sources
@pytest.mark.parametrize('runner', [write_yaml, play])
def test_no_files(runner):
with pytest.raises(click.ClickException):
runner('')
@pytest.mark.parametrize('runner', [write_yaml, play])
def test_cwd(runner):
runner('.')