Skip to content

Commit ac4744e

Browse files
committed
refactor: use pytest.mark.parametrize for ip4scout tests
Each ip4scout file is now a distinct test case, making zero files visible in output instead of silently passing. Also sort the file list for deterministic ordering and simplify Path method calls. Closes #32
1 parent 7b90670 commit ac4744e

1 file changed

Lines changed: 16 additions & 16 deletions

File tree

tests/test_l9format.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import json
22
from pathlib import Path
33

4+
import pytest
5+
46
from l9format import L9Event
57

68
TESTS_DIR = Path(__file__).parent
79

8-
IP4SCOUT_FILES = [
9-
f
10-
for f in Path.iterdir(TESTS_DIR)
11-
if Path.is_file(f) and "ip4scout" in f.name
12-
]
10+
IP4SCOUT_FILES = sorted(
11+
f for f in TESTS_DIR.iterdir() if f.is_file() and "ip4scout" in f.name
12+
)
1313

1414

1515
def test_l9event_json_from_reference_repository() -> None:
@@ -55,17 +55,17 @@ def test_l9event_json_from_reference_repository() -> None:
5555
]
5656

5757

58-
def test_l9events_from_ip4scout() -> None:
59-
for path in IP4SCOUT_FILES:
60-
with open(path) as f:
61-
c = json.load(f)
62-
event = L9Event.from_dict(c)
63-
assert event.event_source == "ip4scout"
64-
assert event.event_type == "synack"
65-
assert isinstance(event.ip, str)
66-
assert len(event.ip) > 0
67-
assert isinstance(event.port, str)
68-
assert len(event.port) > 0
58+
@pytest.mark.parametrize("path", IP4SCOUT_FILES, ids=lambda p: p.name)
59+
def test_l9events_from_ip4scout(path: Path) -> None:
60+
with open(path) as f:
61+
c = json.load(f)
62+
event = L9Event.from_dict(c)
63+
assert event.event_source == "ip4scout"
64+
assert event.event_type == "synack"
65+
assert isinstance(event.ip, str)
66+
assert len(event.ip) > 0
67+
assert isinstance(event.port, str)
68+
assert len(event.port) > 0
6969

7070

7171
def test_iso8601_nanosecond_parsing() -> None:

0 commit comments

Comments
 (0)