From dbfc5f4ff56ec65ec04a558d8715f1df7844dffa Mon Sep 17 00:00:00 2001 From: Nguyễn Gia Phong Date: Thu, 29 May 2025 00:58:44 +0900 Subject: Add unlikely examples for branch coverage --- tst/test_help.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'tst/test_help.py') 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) -- cgit 1.4.1