[tests] simplify test_source.py, skip if no test sounds
[aubio.git] / python / tests / test_source.py
index 01fb41b..97290eb 100755 (executable)
@@ -23,24 +23,38 @@ no_sounds_msg = "no test sounds, add some in 'python/tests/sounds/'!"
 
 _debug = False
 
-class Test_aubio_source_test_case:
+class Test_aubio_source_test_case(TestCase):
 
-    @parametrize('filename', list_of_sounds)
-    def test_close_file(self, filename):
+    def setUp(self):
+        if not default_test_sound:
+            skipTest(no_sounds_msg)
+
+    def test_close_file(self):
         samplerate = 0 # use native samplerate
         hop_size = 256
-        f = source(filename, samplerate, hop_size)
+        f = source(default_test_sound, samplerate, hop_size)
         f.close()
 
-    @parametrize('filename', list_of_sounds)
-    def test_close_file_twice(self, filename):
+    def test_close_file_twice(self):
         samplerate = 0 # use native samplerate
         hop_size = 256
-        f = source(filename, samplerate, hop_size)
+        f = source(default_test_sound, samplerate, hop_size)
         f.close()
         f.close()
 
-class Test_aubio_source_read:
+    def test_read_after_close(self):
+        samplerate = 0 # use native samplerate
+        hop_size = 256
+        f = source(default_test_sound, samplerate, hop_size)
+        read, frames = f()
+        f.close()
+        with assert_raises(RuntimeError):
+            read, frames = f()
+        with assert_raises(RuntimeError):
+            read, frames = f.do_multi()
+
+
+class Test_aubio_source_read(object):
 
     def read_from_source(self, f):
         total_frames = 0
@@ -69,7 +83,7 @@ class Test_aubio_source_read:
         read_frames = self.read_from_source(f)
         if 'f_' in soundfile and samplerate == 0:
             import re
-            f = re.compile('.*_\([0:9]*f\)_.*')
+            f = re.compile(r'.*_\([0:9]*f\)_.*')
             match_f = re.findall('([0-9]*)f_', soundfile)
             if len(match_f) == 1:
                 expected_frames = int(match_f[0])
@@ -118,7 +132,7 @@ class Test_aubio_source_read:
         assert_equal (duration, total_frames)
 
 
-class Test_aubio_source_wrong_params:
+class Test_aubio_source_wrong_params(object):
 
     def test_wrong_file(self):
         with assert_raises(RuntimeError):
@@ -171,7 +185,7 @@ class Test_aubio_source_readmulti(Test_aubio_source_read):
             print (result_str.format(*result_params))
         return total_frames
 
-class Test_aubio_source_with:
+class Test_aubio_source_with(object):
 
     @parametrize('filename', list_of_sounds)
     def test_read_from_mono(self, filename):
@@ -187,5 +201,5 @@ class Test_aubio_source_with:
             assert_equal(total_frames, input_source.duration)
 
 if __name__ == '__main__':
-    import sys, pytest
-    pytest.main(sys.argv)
+    from _tools import run_module_suite
+    run_module_suite()