mirror of
https://github.com/qurator-spk/eynollah.git
synced 2025-11-10 06:34:11 +01:00
refactor cli tests
This commit is contained in:
parent
ef999c8f0a
commit
b6f82c72b9
15 changed files with 453 additions and 592 deletions
36
tests/cli_tests/conftest.py
Normal file
36
tests/cli_tests/conftest.py
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
from typing import List
|
||||
from click import Command
|
||||
import pytest
|
||||
import logging
|
||||
|
||||
from click.testing import CliRunner, Result
|
||||
|
||||
@pytest.fixture
|
||||
def run_eynollah_ok_and_check_logs(
|
||||
pytestconfig,
|
||||
caplog,
|
||||
model_dir,
|
||||
eynollah_log_filter,
|
||||
):
|
||||
"""
|
||||
Generates a Click Runner for `cli`, injects model_path and logging level
|
||||
to `args`, runs the command and checks whether the logs generated contain
|
||||
every fragment in `expected_logs`
|
||||
"""
|
||||
|
||||
def _run_click_ok_logs(cli: Command, args: List[str], expected_logs: List[str]) -> Result:
|
||||
args = ['-m', model_dir] + args
|
||||
if pytestconfig.getoption('verbose') > 0:
|
||||
args.extend(['-l', 'DEBUG'])
|
||||
caplog.set_level(logging.INFO)
|
||||
runner = CliRunner()
|
||||
with caplog.filtering(eynollah_log_filter):
|
||||
result = runner.invoke(cli, args, catch_exceptions=False)
|
||||
assert result.exit_code == 0, result.stdout
|
||||
if expected_logs:
|
||||
logmsgs = [logrec.message for logrec in caplog.records]
|
||||
assert any(logmsg.startswith(needle) for needle in expected_logs for logmsg in logmsgs), f'{expected_logs} not in {logmsgs}'
|
||||
return result
|
||||
|
||||
return _run_click_ok_logs
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue