From 556a40ba3184f2aed2afda42be3c4da4a96cab76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20L=C3=B6ffler?= Date: Mon, 27 May 2024 14:51:56 +0300 Subject: [PATCH] Textbook file closing for test files --- tests/integration/benchmark.py | 3 ++- tests/integration/test_integration.py | 9 +++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/integration/benchmark.py b/tests/integration/benchmark.py index 1fb6e79..86b33a5 100644 --- a/tests/integration/benchmark.py +++ b/tests/integration/benchmark.py @@ -11,7 +11,8 @@ def test_performance(benchmark): path = RESOURCES_DIR / "data/27312315.bz2" - data = bz2.open(path).read() + with bz2.open(path) as f: + data = f.read() result = benchmark.pedantic(stream_decode_lines, args=(data,)) assert len(result) == 50854 for msg in result: diff --git a/tests/integration/test_integration.py b/tests/integration/test_integration.py index 20f7da1..ce0b012 100644 --- a/tests/integration/test_integration.py +++ b/tests/integration/test_integration.py @@ -85,10 +85,11 @@ def test_responses(path): def test_archive(path): mc = MarketSubscriptionCache() i = 0 - for i, line in enumerate(bz2.open(path), start=1): - msg = stream_decode(line) - assert isinstance(msg, MCM) - mc.update(msg) + with bz2.open(path) as f: + for i, line in enumerate(f, start=1): + msg = stream_decode(line) + assert isinstance(msg, MCM) + mc.update(msg) required_count = LINE_COUNT.get(path.name) if required_count: