|
1 | 1 | import json |
2 | 2 | from pathlib import Path |
3 | 3 |
|
| 4 | +import pytest |
| 5 | + |
4 | 6 | from l9format import L9Event |
5 | 7 |
|
6 | 8 | TESTS_DIR = Path(__file__).parent |
7 | 9 |
|
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 | +) |
13 | 13 |
|
14 | 14 |
|
15 | 15 | def test_l9event_json_from_reference_repository() -> None: |
@@ -55,17 +55,17 @@ def test_l9event_json_from_reference_repository() -> None: |
55 | 55 | ] |
56 | 56 |
|
57 | 57 |
|
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 |
69 | 69 |
|
70 | 70 |
|
71 | 71 | def test_iso8601_nanosecond_parsing() -> None: |
|
0 commit comments