diff options
Diffstat (limited to 'tst/test_help.py')
-rw-r--r-- | tst/test_help.py | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/tst/test_help.py b/tst/test_help.py index 3e5ce87..2a6c06a 100644 --- a/tst/test_help.py +++ b/tst/test_help.py @@ -22,7 +22,7 @@ from io import StringIO from hypothesis import example, given from pytest import fixture, mark, raises -from scadere import NetLoc +from scadere import EXAMPLE_PREFIX, EXAMPLE_DESCRIPTION_PREFIX, NetLoc from scadere.check import main as check from scadere.listen import main as listen @@ -31,7 +31,7 @@ from scadere.listen import main as listen def help_string(request): string = StringIO() with suppress(SystemExit), redirect_stdout(string): - request.param(['--help']) + request.param(arguments=['--help']) return string.getvalue() @@ -57,6 +57,26 @@ def test_long_option(help_string, short, long, metavar): assert f'{short} {metavar}, {long}={metavar}' in help_string +@mark.parametrize('help_string', [check, listen], indirect=True) +def test_examples(help_string): + index = help_string.find('\n\nExamples:\n') + assert index >= 0 + lines = help_string[index:].removeprefix('\n\nExamples:\n').splitlines() + + assert EXAMPLE_DESCRIPTION_PREFIX.startswith(EXAMPLE_PREFIX) + assert not lines[0].startswith(EXAMPLE_DESCRIPTION_PREFIX) + assert lines[-1].startswith(EXAMPLE_DESCRIPTION_PREFIX) + + must_be_desc = False + for line in lines: + if must_be_desc: + assert line.startswith(EXAMPLE_DESCRIPTION_PREFIX) + must_be_desc = False + else: + assert line.startswith(EXAMPLE_PREFIX) + must_be_desc = not line.startswith(EXAMPLE_DESCRIPTION_PREFIX) + + @example('a.example:b', None) # string is unlikely to match .*:\D+ @example('a.example:98', None) # string is unlikely to match .*:\d+ @given(...) |