[py] fix pvoc tests on powerpc
[aubio.git] / python / tests / test_phasevoc.py
index 311e089..b228269 100755 (executable)
@@ -1,8 +1,8 @@
 #! /usr/bin/env python
 
 from numpy.testing import TestCase, assert_equal, assert_array_less
+from _tools import parametrize, skipTest
 from aubio import fvec, cvec, pvoc, float_type
-from nose2.tools import params
 import numpy as np
 
 if float_type == 'float32':
@@ -17,7 +17,7 @@ def create_sine(hop_s, freq, samplerate):
 def create_noise(hop_s):
     return np.random.rand(hop_s).astype(float_type) * 2. - 1.
 
-class aubio_pvoc_test_case(TestCase):
+class Test_aubio_pvoc_test_case(object):
     """ pvoc object test case """
 
     def test_members_automatic_sizes_default(self):
@@ -40,15 +40,32 @@ class aubio_pvoc_test_case(TestCase):
         win_s, hop_s = 1024, 256
         f = pvoc (win_s, hop_s)
         t = fvec (hop_s)
-        for time in range( int ( 4 * win_s / hop_s ) ):
+        for _ in range( int ( 4 * win_s / hop_s ) ):
             s = f(t)
             r = f.rdo(s)
             assert_equal ( t, 0.)
             assert_equal ( s.norm, 0.)
-            assert_equal ( s.phas, 0.)
+            try:
+                assert_equal ( s.phas, 0 )
+            except AssertionError:
+                assert_equal (s.phas[s.phas > 0], +np.pi)
+                assert_equal (s.phas[s.phas < 0], -np.pi)
+                assert_equal (np.abs(s.phas[np.abs(s.phas) != np.pi]), 0)
+                skipTest('pvoc(fvec(%d)).phas != +0, ' % win_s \
+                        + 'This is expected when using fftw3 on powerpc.')
             assert_equal ( r, 0.)
 
-    @params(
+    def test_no_overlap(self):
+        win_s, hop_s = 1024, 1024
+        f = pvoc (win_s, hop_s)
+        t = fvec (hop_s)
+        for _ in range(4):
+            s = f(t)
+            r = f.rdo(s)
+            assert_equal ( t, 0.)
+
+    resynth_noise_args = "hop_s, ratio"
+    resynth_noise_values = [
             ( 256, 8),
             ( 256, 4),
             ( 256, 2),
@@ -70,13 +87,16 @@ class aubio_pvoc_test_case(TestCase):
             (8192, 8),
             (8192, 4),
             (8192, 2),
-            )
+            ]
+
+    @parametrize(resynth_noise_args, resynth_noise_values)
     def test_resynth_steps_noise(self, hop_s, ratio):
         """ check the resynthesis of a random signal is correct """
         sigin = create_noise(hop_s)
         self.reconstruction(sigin, hop_s, ratio)
 
-    @params(
+    resynth_sine_args = "samplerate, hop_s, ratio, freq"
+    resynth_sine_values = [
             (44100,  256, 8,   441),
             (44100,  256, 4,  1203),
             (44100,  256, 2,  3045),
@@ -91,7 +111,9 @@ class aubio_pvoc_test_case(TestCase):
             (22050,  256, 8,   445),
             (96000, 1024, 8, 47000),
             (96000, 1024, 8,    20),
-            )
+            ]
+
+    @parametrize(resynth_sine_args, resynth_sine_values)
     def test_resynth_steps_sine(self, samplerate, hop_s, ratio, freq):
         """ check the resynthesis of a sine is correct """
         sigin = create_sine(hop_s, freq, samplerate)
@@ -102,7 +124,7 @@ class aubio_pvoc_test_case(TestCase):
         f = pvoc(buf_s, hop_s)
         zeros = fvec(hop_s)
         r2 = f.rdo( f(sigin) )
-        for i in range(1, ratio):
+        for _ in range(1, ratio):
             r2 = f.rdo( f(zeros) )
         # compute square errors
         sq_error = (r2 - sigin)**2
@@ -177,11 +199,10 @@ class aubio_pvoc_wrong_params(TestCase):
         try:
             with self.assertRaises(RuntimeError):
                 pvoc(win_s, hop_s)
-        except AssertionError as e:
+        except AssertionError:
             # when compiled with fftw3, aubio supports non power of two fft sizes
             self.skipTest('creating aubio.pvoc with size %d did not fail' % win_s)
 
 if __name__ == '__main__':
-    from nose2 import main
+    from unittest import main
     main()
-