Skip to content

Commit 0dab235

Browse files
author
Benjamin Moody
committed
test_annotation: convert to a standard unittest.TestCase.
Make the test_annotation class a subclass of unittest.TestCase, allowing it to use standard unit testing utility methods, as well as setup and teardown functions. (nosetests will run "test" class methods automatically even if they are not subclasses of TestCase, but unittest won't.) Rename the class to TestAnnotation for consistency. Make the module executable (invoke unittest.main()) so it can be invoked simply using 'python3 -m tests.test_annotation'. Ensure that temporary files created by the annotation tests will be correctly cleaned up by TestAnnotation.tearDownClass() rather than by the unrelated TestRecord.tearDownClass(). (Presumably this only happened to work previously because "test_record" comes alphabetically after "test_annotation".)
1 parent 481978e commit 0dab235

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

tests/test_annotation.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
import os
12
import re
3+
import unittest
24

35
import numpy as np
46

57
import wfdb
68

7-
class test_annotation():
9+
10+
class TestAnnotation(unittest.TestCase):
811
"""
912
Testing read and write of WFDB annotations, including Physionet
1013
streaming.
@@ -183,3 +186,18 @@ def test_3(self):
183186
assert (comp == [True] * 6)
184187
assert annotation.__eq__(pn_annotation)
185188
assert annotation.__eq__(write_annotation)
189+
190+
@classmethod
191+
def tearDownClass(cls):
192+
writefiles = [
193+
'100.atr',
194+
'1003.atr',
195+
'12726.anI',
196+
]
197+
for file in writefiles:
198+
if os.path.isfile(file):
199+
os.remove(file)
200+
201+
202+
if __name__ == '__main__':
203+
unittest.main()

tests/test_record.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -521,9 +521,9 @@ def test_header_with_non_utf8(self):
521521
@classmethod
522522
def tearDownClass(cls):
523523
"Clean up written files"
524-
writefiles = ['03700181.dat','03700181.hea','100.atr','100.dat',
525-
'100.hea','1003.atr','100_3chan.dat','100_3chan.hea',
526-
'12726.anI','a103l.hea','a103l.mat','s0010_re.dat',
524+
writefiles = ['03700181.dat','03700181.hea','100.dat',
525+
'100.hea','100_3chan.dat','100_3chan.hea',
526+
'a103l.hea','a103l.mat','s0010_re.dat',
527527
's0010_re.hea','s0010_re.xyz','test01_00s.dat',
528528
'test01_00s.hea','test01_00s_skewframe.hea',
529529
'n8_evoked_raw_95_F1_R9.dat', 'n8_evoked_raw_95_F1_R9.hea']

0 commit comments

Comments
 (0)