@@ -60,12 +60,20 @@ def temp_record():
60
60
output_path = archive_path ,
61
61
)
62
62
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 ()
69
77
70
78
71
79
def test_wfdb_archive_inline_round_trip ():
@@ -108,12 +116,17 @@ def test_wfdb_archive_inline_round_trip():
108
116
# Read back from archive
109
117
record = rdrecord (archive_path )
110
118
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 ()
117
130
118
131
119
132
def test_wfdb_archive_round_trip (temp_record ):
0 commit comments