Skip to content

Commit 2597974

Browse files
committed
Fix handling in Windows.
1 parent 45e588d commit 2597974

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

tests/test_archive.py

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,20 @@ def temp_record():
6060
output_path=archive_path,
6161
)
6262

63-
yield {
64-
"record_name": os.path.join(tmpdir, record_basename),
65-
"archive_path": archive_path,
66-
"original_signal": sig,
67-
"fs": fs,
68-
}
63+
try:
64+
yield {
65+
"record_name": os.path.join(tmpdir, record_basename),
66+
"archive_path": archive_path,
67+
"original_signal": sig,
68+
"fs": fs,
69+
}
70+
finally:
71+
# Clean up any open archive handles
72+
from wfdb.io.archive import _archive_cache
73+
for archive in _archive_cache.values():
74+
if archive is not None:
75+
archive.close()
76+
_archive_cache.clear()
6977

7078

7179
def test_wfdb_archive_inline_round_trip():
@@ -108,12 +116,17 @@ def test_wfdb_archive_inline_round_trip():
108116
# Read back from archive
109117
record = rdrecord(archive_path)
110118

111-
assert record.fs == fs
112-
assert record.n_sig == 2
113-
assert record.p_signal.shape == sig.shape
114-
115-
# Add tolerance to account for loss of precision during archive round-trip
116-
np.testing.assert_allclose(record.p_signal, sig, rtol=1e-2, atol=3e-3)
119+
try:
120+
assert record.fs == fs
121+
assert record.n_sig == 2
122+
assert record.p_signal.shape == sig.shape
123+
124+
# Add tolerance to account for loss of precision during archive round-trip
125+
np.testing.assert_allclose(record.p_signal, sig, rtol=1e-2, atol=3e-3)
126+
finally:
127+
# Ensure we close the archive after reading
128+
if hasattr(record, 'wfdb_archive') and record.wfdb_archive is not None:
129+
record.wfdb_archive.close()
117130

118131

119132
def test_wfdb_archive_round_trip(temp_record):

0 commit comments

Comments
 (0)