diff --git a/CHANGELOG.md b/CHANGELOG.md index 6103fb1..e00aaa3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ and this project adheres to ### Fixed +- Fix leaked file handles in tests using context managers ([b66a6f5], [#25]) - Fix typo in test name: `test_l9events_form_ip4scout` -> `test_l9events_from_ip4scout` ([0d8736e], [#27]) @@ -150,6 +151,7 @@ and this project adheres to +[b66a6f5]: https://github.com/LeakIX/l9format-python/commit/b66a6f5 [3547e22]: https://github.com/LeakIX/l9format-python/commit/3547e22 [1ca6e4d]: https://github.com/LeakIX/l9format-python/commit/1ca6e4d [0d8736e]: https://github.com/LeakIX/l9format-python/commit/0d8736e @@ -218,4 +220,5 @@ and this project adheres to [#22]: https://github.com/LeakIX/l9format-python/issues/22 [#27]: https://github.com/LeakIX/l9format-python/issues/27 [#33]: https://github.com/LeakIX/l9format-python/issues/33 +[#25]: https://github.com/LeakIX/l9format-python/issues/25 [#35]: https://github.com/LeakIX/l9format-python/issues/35 diff --git a/tests/test_l9format.py b/tests/test_l9format.py index 01edfd6..51e58ed 100644 --- a/tests/test_l9format.py +++ b/tests/test_l9format.py @@ -1,10 +1,9 @@ import json -import os from pathlib import Path from l9format import L9Event -TESTS_DIR = Path(os.path.dirname(__file__)) +TESTS_DIR = Path(__file__).parent IP4SCOUT_FILES = [ f @@ -15,13 +14,15 @@ def test_l9event_json_from_reference_repository(): path = TESTS_DIR / "l9event.json" - c = json.load(open(str(path), "r")) + with open(path) as f: + c = json.load(f) L9Event.from_dict(c) def test_l9events_from_ip4scout(): for path in IP4SCOUT_FILES: - c = json.load(open(str(path), "r")) + with open(path) as f: + c = json.load(f) L9Event.from_dict(c) @@ -33,7 +34,8 @@ def test_iso8601_nanosecond_parsing(): correctly in Python 3.11+. """ path = TESTS_DIR / "l9event.json" - c = json.load(open(str(path), "r")) + with open(path) as f: + c = json.load(f) # Use a timestamp with nanosecond precision (9 decimal places) c["time"] = "2023-10-05T23:30:36.823867784Z" event = L9Event.from_dict(c)