Skip to content

Commit 6a6967f

Browse files
authored
Merge pull request #48 from LeakIX/parametrize-ip4scout-tests
Use pytest.mark.parametrize for ip4scout tests
2 parents 7b90670 + 398fbe1 commit 6a6967f

2 files changed

Lines changed: 20 additions & 16 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ and this project adheres to
2727
([1dcfbef], [#21])
2828
- Tests now import from `l9format` package directly instead of
2929
`l9format.l9format` ([e8aef2e], [#21])
30+
- Use `pytest.mark.parametrize` for ip4scout tests so each file is a distinct
31+
test case ([ac4744e], [#32])
3032

3133
### Fixed
3234

@@ -160,6 +162,7 @@ and this project adheres to
160162

161163
<!-- Commit links -->
162164

165+
[ac4744e]: https://github.com/LeakIX/l9format-python/commit/ac4744e
163166
[d554f1e]: https://github.com/LeakIX/l9format-python/commit/d554f1e
164167
[7f49ff5]: https://github.com/LeakIX/l9format-python/commit/7f49ff5
165168
[cd74b55]: https://github.com/LeakIX/l9format-python/commit/cd74b55
@@ -241,4 +244,5 @@ and this project adheres to
241244
[#35]: https://github.com/LeakIX/l9format-python/issues/35
242245
[#24]: https://github.com/LeakIX/l9format-python/issues/24
243246
[#31]: https://github.com/LeakIX/l9format-python/issues/31
247+
[#32]: https://github.com/LeakIX/l9format-python/issues/32
244248
[#43]: https://github.com/LeakIX/l9format-python/issues/43

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)