tests/: continue python3 preparation
authorPaul Brossier <piem@piem.org>
Mon, 18 Apr 2016 21:46:18 +0000 (23:46 +0200)
committerPaul Brossier <piem@piem.org>
Mon, 18 Apr 2016 21:46:18 +0000 (23:46 +0200)
python/tests/test_filterbank.py
python/tests/test_note2midi.py
python/tests/test_phasevoc.py
python/tests/test_zero_crossing_rate.py
python/tests/utils.py

index 02ae0f3..f419d53 100755 (executable)
@@ -16,7 +16,7 @@ class aubio_filterbank_test_case(TestCase):
 
   def test_set_coeffs(self):
     f = filterbank(40, 512)
-    r = random.random([40, 512 / 2 + 1]).astype('float32')
+    r = random.random([40, int(512 / 2) + 1]).astype('float32')
     f.set_coeffs(r)
     assert_equal (r, f.get_coeffs())
 
@@ -35,16 +35,16 @@ class aubio_filterbank_test_case(TestCase):
   def test_random_norm(self):
     f = filterbank(40, 512)
     c = cvec(512)
-    c.norm[:] = random.random((512 / 2 + 1,)).astype('float32')
+    c.norm[:] = random.random((int(512 / 2) + 1,)).astype('float32')
     assert_equal( f(c), 0)
 
   def test_random_coeffs(self):
     f = filterbank(40, 512)
     c = cvec(512)
-    r = random.random([40, 512 / 2 + 1]).astype('float32')
+    r = random.random([40, int(512 / 2) + 1]).astype('float32')
     r /= r.sum()
     f.set_coeffs(r)
-    c.norm[:] = random.random((512 / 2 + 1,)).astype('float32')
+    c.norm[:] = random.random((int(512 / 2) + 1,)).astype('float32')
     assert_equal ( f(c) < 1., True )
     assert_equal ( f(c) > 0., True )
 
@@ -52,7 +52,7 @@ class aubio_filterbank_test_case(TestCase):
     f = filterbank(40, 512)
     c = cvec(512)
     f.set_mel_coeffs_slaney(44100)
-    c.norm[:] = random.random((512 / 2 + 1,)).astype('float32')
+    c.norm[:] = random.random((int(512 / 2) + 1,)).astype('float32')
     assert_equal ( f(c) < 1., True )
     assert_equal ( f(c) > 0., True )
 
index c4503b0..055580e 100755 (executable)
@@ -69,7 +69,7 @@ class freq2note_simple_test(unittest.TestCase):
 
     def test_freq2note(self):
         " make sure freq2note(441) == A4 "
-        self.assertEquals("A4", freq2note(441))
+        self.assertEqual("A4", freq2note(441))
 
 if __name__ == '__main__':
     unittest.main()
index 2e19f26..45a92be 100755 (executable)
@@ -30,7 +30,7 @@ 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( 4 * win_s / hop_s ):
+        for time in range( int ( 4 * win_s / hop_s ) ):
             s = f(t)
             r = f.rdo(s)
             assert_equal ( array(t), 0)
index 06cd6dc..b7b9965 100755 (executable)
@@ -22,24 +22,24 @@ class zero_crossing_rate_test_case(TestCase):
 
     def test_impulse(self):
         """ check zero crossing rate on a buffer with an impulse """
-        self.vector[buf_size / 2] = 1.
+        self.vector[int(buf_size / 2)] = 1.
         self.assertEqual(0., zero_crossing_rate(self.vector))
 
     def test_negative_impulse(self):
         """ check zero crossing rate on a buffer with a negative impulse """
-        self.vector[buf_size / 2] = -1.
+        self.vector[int(buf_size / 2)] = -1.
         self.assertEqual(2./buf_size, zero_crossing_rate(self.vector))
 
     def test_single(self):
         """ check zero crossing rate on single crossing """
-        self.vector[buf_size / 2 - 1] = 1.
-        self.vector[buf_size / 2] = -1.
+        self.vector[int(buf_size / 2) - 1] = 1.
+        self.vector[int(buf_size / 2)] = -1.
         self.assertEqual(2./buf_size, zero_crossing_rate(self.vector))
 
     def test_single_with_gap(self):
         """ check zero crossing rate on single crossing with a gap"""
-        self.vector[buf_size / 2 - 2] = 1.
-        self.vector[buf_size / 2] = -1.
+        self.vector[int(buf_size / 2) - 2] = 1.
+        self.vector[int(buf_size / 2)] = -1.
         self.assertEqual(2./buf_size, zero_crossing_rate(self.vector))
 
 if __name__ == '__main__':
index 1cec053..6d98c14 100644 (file)
@@ -4,8 +4,10 @@ def array_from_text_file(filename, dtype = 'float'):
     import os.path
     from numpy import array
     filename = os.path.join(os.path.dirname(__file__), filename)
-    return array([line.split() for line in open(filename).readlines()],
-        dtype = dtype)
+    with open(filename) as f:
+        lines = f.readlines()
+    return array([line.split() for line in lines],
+            dtype = dtype)
 
 def list_all_sounds(rel_dir):
     import os.path, glob