diff options
author | Nguyễn Gia Phong <cnx@loang.net> | 2025-05-29 00:58:44 +0900 |
---|---|---|
committer | Nguyễn Gia Phong <cnx@loang.net> | 2025-05-29 00:58:44 +0900 |
commit | dbfc5f4ff56ec65ec04a558d8715f1df7844dffa (patch) | |
tree | e7b7dcdc8267d114e2634dd6ee10be73327b659a /tst/test_help.py | |
parent | 9b9e25d1d042e315b745aba73f30501e6ab07edb (diff) | |
download | scadere-dbfc5f4ff56ec65ec04a558d8715f1df7844dffa.tar.gz |
Add unlikely examples for branch coverage
Diffstat (limited to 'tst/test_help.py')
-rw-r--r-- | tst/test_help.py | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/tst/test_help.py b/tst/test_help.py index 429d7c4..0889961 100644 --- a/tst/test_help.py +++ b/tst/test_help.py @@ -19,7 +19,7 @@ from contextlib import redirect_stdout, suppress from io import StringIO -from hypothesis import given +from hypothesis import example, given from pytest import fixture, mark, raises from scadere import NetLoc @@ -57,13 +57,18 @@ def test_long_option(help_string, short, long, metavar): assert f'{short} {metavar}, {long}={metavar}' in help_string +@example('a.example:98', None) # string is unlikely to match .*:\d+ @given(...) -def test_netloc(hostname: str, port: int | None, default_port: int | None): +def test_netloc(string: str, default_port: int | None): netloc = NetLoc(default_port) - if port is not None: - assert netloc(f'{hostname}:{port}') == (hostname, port) - elif default_port is None: - with raises(ValueError): - netloc(f'{hostname}:{port}') + if ':' not in string: + assert netloc(string) == (string, default_port) else: - assert netloc(hostname) == (hostname, default_port) + hostname, port = string.rsplit(':', 1) + try: + port_number = int(port) + except ValueError: + with raises(ValueError): + netloc(string) + else: + assert netloc(string) == (hostname, port_number) |