[tests] check reading source after close raises RuntimeError
[aubio.git] / python / tests / test_source.py
index cca8132..9d2e61f 100755 (executable)
@@ -23,7 +23,7 @@ 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(object):
 
     @parametrize('filename', list_of_sounds)
     def test_close_file(self, filename):
@@ -40,7 +40,20 @@ class Test_aubio_source_test_case:
         f.close()
         f.close()
 
-class Test_aubio_source_read:
+    @parametrize('filename', [default_test_sound])
+    def test_read_after_close(self, filename):
+        samplerate = 0 # use native samplerate
+        hop_size = 256
+        f = source(filename, 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
@@ -118,7 +131,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 +184,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 +200,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()