about summary refs log tree commit diff
path: root/tst/test_help.py
diff options
context:
space:
mode:
Diffstat (limited to 'tst/test_help.py')
-rw-r--r--tst/test_help.py21
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)