Skip to content

Commit d8ee8ad

Browse files
authored
Merge pull request #41 from LeakIX/fix-leaked-file-handles
Fix leaked file handles in tests
2 parents 44e50e5 + 97b56f2 commit d8ee8ad

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ and this project adheres to
2525

2626
### Fixed
2727

28+
- Fix leaked file handles in tests using context managers ([b66a6f5], [#25])
2829
- Fix typo in test name: `test_l9events_form_ip4scout` ->
2930
`test_l9events_from_ip4scout` ([0d8736e], [#27])
3031

@@ -150,6 +151,7 @@ and this project adheres to
150151

151152
<!-- Commit links -->
152153

154+
[b66a6f5]: https://github.com/LeakIX/l9format-python/commit/b66a6f5
153155
[3547e22]: https://github.com/LeakIX/l9format-python/commit/3547e22
154156
[1ca6e4d]: https://github.com/LeakIX/l9format-python/commit/1ca6e4d
155157
[0d8736e]: https://github.com/LeakIX/l9format-python/commit/0d8736e
@@ -218,4 +220,5 @@ and this project adheres to
218220
[#22]: https://github.com/LeakIX/l9format-python/issues/22
219221
[#27]: https://github.com/LeakIX/l9format-python/issues/27
220222
[#33]: https://github.com/LeakIX/l9format-python/issues/33
223+
[#25]: https://github.com/LeakIX/l9format-python/issues/25
221224
[#35]: https://github.com/LeakIX/l9format-python/issues/35

tests/test_l9format.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import json
2-
import os
32
from pathlib import Path
43

54
from l9format import L9Event
65

7-
TESTS_DIR = Path(os.path.dirname(__file__))
6+
TESTS_DIR = Path(__file__).parent
87

98
IP4SCOUT_FILES = [
109
f
@@ -15,13 +14,15 @@
1514

1615
def test_l9event_json_from_reference_repository():
1716
path = TESTS_DIR / "l9event.json"
18-
c = json.load(open(str(path), "r"))
17+
with open(path) as f:
18+
c = json.load(f)
1919
L9Event.from_dict(c)
2020

2121

2222
def test_l9events_from_ip4scout():
2323
for path in IP4SCOUT_FILES:
24-
c = json.load(open(str(path), "r"))
24+
with open(path) as f:
25+
c = json.load(f)
2526
L9Event.from_dict(c)
2627

2728

@@ -33,7 +34,8 @@ def test_iso8601_nanosecond_parsing():
3334
correctly in Python 3.11+.
3435
"""
3536
path = TESTS_DIR / "l9event.json"
36-
c = json.load(open(str(path), "r"))
37+
with open(path) as f:
38+
c = json.load(f)
3739
# Use a timestamp with nanosecond precision (9 decimal places)
3840
c["time"] = "2023-10-05T23:30:36.823867784Z"
3941
event = L9Event.from_dict(c)

0 commit comments

Comments
 (0)