shithub: aubio

Download patch

ref: 689106ecec1986332b7f2bbb30928e034b3b6de2
parent: 1c6fe64f5d251e305db3a7bb2f710a20cb00d8d2
author: Paul Brossier <piem@piem.org>
date: Mon Apr 18 19:24:47 EDT 2016

python/tests/: prepare for python3 (see #33)

--- a/python/tests/test_fvec.py
+++ b/python/tests/test_fvec.py
@@ -19,7 +19,7 @@
         a = fvec([0,1,2,3])
         assert a.dtype == 'float32'
         assert a.shape == (4,)
-        assert_equal (range(4), a)
+        assert_equal (list(range(4)), a)
 
     def test_vector_assign_element(self):
         a = fvec(default_size)
@@ -41,7 +41,7 @@
         a = fvec(1)
         a.T
         array(a).T
-        a = range(len(a))
+        a = list(range(len(a)))
 
     def test_wrong_values(self):
         self.assertRaises (ValueError, fvec, -10)
@@ -52,11 +52,11 @@
 
     def test_alpha_norm_of_fvec(self):
         a = fvec(2)
-        self.assertEquals (alpha_norm(a, 1), 0)
+        self.assertEqual (alpha_norm(a, 1), 0)
         a[0] = 1
-        self.assertEquals (alpha_norm(a, 1), 0.5)
+        self.assertEqual (alpha_norm(a, 1), 0.5)
         a[1] = 1
-        self.assertEquals (alpha_norm(a, 1), 1)
+        self.assertEqual (alpha_norm(a, 1), 1)
         a = array([0, 1], dtype='float32')
         from math import sqrt
         assert_almost_equal (alpha_norm(a, 2), sqrt(2)/2.)
@@ -73,7 +73,7 @@
         self.assertRaises (ValueError, alpha_norm, a, 1)
         # check 1d array
         a = array(range(10), dtype = 'float32')
-        self.assertEquals (alpha_norm(a, 1), 4.5)
+        self.assertEqual (alpha_norm(a, 1), 4.5)
 
     def test_alpha_norm_of_array_of_int(self):
         a = array(1, dtype = 'int')
@@ -91,11 +91,11 @@
         a = array([0,1,-1], dtype='float32')
         assert_almost_equal (zero_crossing_rate(a), 1./3. )
         a = array([0.]*100, dtype='float32')
-        self.assertEquals (zero_crossing_rate(a), 0 )
+        self.assertEqual (zero_crossing_rate(a), 0 )
         a = array([-1.]*100, dtype='float32')
-        self.assertEquals (zero_crossing_rate(a), 0 )
+        self.assertEqual (zero_crossing_rate(a), 0 )
         a = array([1.]*100, dtype='float32')
-        self.assertEquals (zero_crossing_rate(a), 0 )
+        self.assertEqual (zero_crossing_rate(a), 0 )
 
     def test_alpha_norm_of_array_of_float64(self):
         # check scalar fail
@@ -105,10 +105,10 @@
         a = array([[[1,2],[3,4]]], dtype = 'float64')
         self.assertRaises (ValueError, alpha_norm, a, 1)
         # check float64 1d array fail
-        a = array(range(10), dtype = 'float64')
+        a = array(list(range(10)), dtype = 'float64')
         self.assertRaises (ValueError, alpha_norm, a, 1)
         # check float64 2d array fail
-        a = array([range(10), range(10)], dtype = 'float64')
+        a = array([list(range(10)), list(range(10))], dtype = 'float64')
         self.assertRaises (ValueError, alpha_norm, a, 1)
 
     def test_fvec_min_removal_of_array(self):
--- a/python/tests/test_mathutils.py
+++ b/python/tests/test_mathutils.py
@@ -12,7 +12,7 @@
     def test_unwrap2pi(self):
         unwrap2pi(int(23))
         unwrap2pi(float(23.))
-        unwrap2pi(long(23.))
+        unwrap2pi(int(23.))
         unwrap2pi(arange(10))
         unwrap2pi(arange(10).astype("int"))
         unwrap2pi(arange(10).astype("float"))
@@ -27,8 +27,8 @@
         #print zip(a, b)
 
         try:
-            print unwrap2pi(["23.","24.",25.])
-        except Exception, e:
+            print (unwrap2pi(["23.","24.",25.]))
+        except Exception as e:
             pass
 
     def test_unwrap2pi_takes_fvec(self):
@@ -53,7 +53,7 @@
         assert ( b <= pi ).all()
 
     def test_freqtomidi(self):
-        a = array(range(-20, 50000, 100) + [ -1e32, 1e32 ])
+        a = array(list(range(-20, 50000, 100)) + [ -1e32, 1e32 ])
         b = freqtomidi(a)
         #print zip(a, b)
         assert_equal ( isnan(array(b)), False )
@@ -61,7 +61,7 @@
         assert_equal ( array(b) < 0, False )
 
     def test_miditofreq(self):
-        a = range(-30, 200) + [-100000, 10000]
+        a = list(range(-30, 200)) + [-100000, 10000]
         b = miditofreq(a)
         #print zip(a, b)
         assert_equal ( isnan(b), False )
@@ -69,7 +69,7 @@
         assert_equal ( b < 0, False )
 
     def test_miditobin(self):
-        a = range(-30, 200) + [-100000, 10000]
+        a = list(range(-30, 200)) + [-100000, 10000]
         b = [ bintomidi(x, 44100, 512) for x in a ]
         #print zip(a, b)
         assert_equal ( isnan(array(b)), False )
@@ -77,7 +77,7 @@
         assert_equal ( array(b) < 0, False )
 
     def test_bintomidi(self):
-        a = range(-100, 512)
+        a = list(range(-100, 512))
         b = [ bintomidi(x, 44100, 512) for x in a ]
         #print zip(a, b)
         assert_equal ( isnan(array(b)), False )
@@ -85,7 +85,7 @@
         assert_equal ( array(b) < 0, False )
 
     def test_freqtobin(self):
-        a = range(-20, 50000, 100) + [ -1e32, 1e32 ]
+        a = list(range(-20, 50000, 100)) + [ -1e32, 1e32 ]
         b = [ freqtobin(x, 44100, 512) for x in a ]
         #print zip(a, b)
         assert_equal ( isnan(array(b)), False )
@@ -93,7 +93,7 @@
         assert_equal ( array(b) < 0, False )
 
     def test_bintofreq(self):
-        a = range(-20, 148)
+        a = list(range(-20, 148))
         b = [ bintofreq(x, 44100, 512) for x in a ]
         #print zip(a, b)
         assert_equal ( isnan(array(b)), False )
--- a/python/tests/test_musicutils.py
+++ b/python/tests/test_musicutils.py
@@ -17,7 +17,7 @@
     def test_fail_name_not_string(self):
         try:
             window(10, 1024)
-        except ValueError, e:
+        except ValueError as e:
             pass
         else:
             self.fail('non-string window type does not raise a ValueError')
@@ -25,7 +25,7 @@
     def test_fail_size_not_int(self):
         try:
             window("default", "default")
-        except ValueError, e:
+        except ValueError as e:
             pass
         else:
             self.fail('non-integer window length does not raise a ValueError')
@@ -43,7 +43,7 @@
     def test_fail_not_fvec(self):
         try:
             level_lin("default")
-        except ValueError, e:
+        except ValueError as e:
             pass
         else:
             self.fail('non-number input phase does not raise a TypeError')
@@ -62,7 +62,7 @@
     def test_fail_not_fvec(self):
         try:
             db_spl("default")
-        except ValueError, e:
+        except ValueError as e:
             pass
         else:
             self.fail('non-number input phase does not raise a TypeError')
@@ -82,7 +82,7 @@
     def test_fail_not_fvec(self):
         try:
             silence_detection("default", -70)
-        except ValueError, e:
+        except ValueError as e:
             pass
         else:
             self.fail('non-number input phase does not raise a TypeError')
@@ -102,7 +102,7 @@
     def test_fail_not_fvec(self):
         try:
             level_detection("default", -70)
-        except ValueError, e:
+        except ValueError as e:
             pass
         else:
             self.fail('non-number input phase does not raise a TypeError')
--- a/python/tests/test_phasevoc.py
+++ b/python/tests/test_phasevoc.py
@@ -63,7 +63,7 @@
         sigin = fvec(hop_s)
         zeros = fvec(hop_s)
         f = pvoc(buf_s, hop_s)
-        for i in xrange(hop_s):
+        for i in range(hop_s):
             sigin[i] = random() * 2. - 1.
         t2 = f.rdo( f(sigin) )
         t2 = f.rdo( f(zeros) )
--- a/python/tests/test_pitch.py
+++ b/python/tests/test_pitch.py
@@ -24,7 +24,7 @@
         " running on silence gives 0 "
         p = pitch('default', 2048, 512, 32000)
         f = fvec (512)
-        for i in xrange(10): assert_equal (p(f), 0.)
+        for i in range(10): assert_equal (p(f), 0.)
 
     def test_run_on_ones(self):
         " running on ones gives 0 "
@@ -31,7 +31,7 @@
         p = pitch('default', 2048, 512, 32000)
         f = fvec (512)
         f[:] = 1
-        for i in xrange(10): assert_equal (p(f), 0.)
+        for i in range(10): assert_equal (p(f), 0.)
 
 class aubio_pitch_Sinusoid(TestCase):
 
--- a/python/tests/test_sink.py
+++ b/python/tests/test_sink.py
@@ -44,7 +44,7 @@
                 for n in range(200):
                     vec = fvec(write)
                     g(vec, write)
-        except StandardError:
+        except Exception:
             pass
         else:
             self.fail("does not fail on too many files open")
@@ -70,11 +70,11 @@
                     total_frames += read
                     if read < f.hop_size: break
                 if 0:
-                    print "read", "%.2fs" % (total_frames / float(f.samplerate) ),
-                    print "(", total_frames, "frames", "in",
-                    print total_frames / f.hop_size, "blocks", "at", "%dHz" % f.samplerate, ")",
-                    print "from", f.uri,
-                    print "to", g.uri
+                    print ("read", "%.2fs" % (total_frames / float(f.samplerate) ) ),
+                    print ("(", total_frames, "frames", "in" ),
+                    print (total_frames / f.hop_size, "blocks", "at", "%dHz" % f.samplerate, ")" ),
+                    print ("from", f.uri ),
+                    print ("to", g.uri)
                 del_tmp_sink_path(sink_path)
 
     def test_read_and_write_multi(self):
@@ -95,13 +95,13 @@
                     total_frames += read
                     if read < f.hop_size: break
                 if 0:
-                    print "read", "%.2fs" % (total_frames / float(f.samplerate) ),
-                    print "(", total_frames, "frames", "in",
-                    print f.channels, "channels", "in",
-                    print total_frames / f.hop_size, "blocks", "at", "%dHz" % f.samplerate, ")",
-                    print "from", f.uri,
-                    print "to", g.uri,
-                    print "in", g.channels, "channels"
+                    print ("read", "%.2fs" % (total_frames / float(f.samplerate) ) ),
+                    print ("(", total_frames, "frames", "in" ),
+                    print (f.channels, "channels", "in" ),
+                    print (total_frames / f.hop_size, "blocks", "at", "%dHz" % f.samplerate, ")" ),
+                    print ("from", f.uri ),
+                    print ("to", g.uri ),
+                    print ("in", g.channels, "channels")
                 del_tmp_sink_path(sink_path)
 
     def test_close_file(self):
--- a/python/tests/test_source.py
+++ b/python/tests/test_source.py
@@ -38,10 +38,10 @@
             vec, read = f()
             total_frames += read
             if read < f.hop_size: break
-        print "read", "%.2fs" % (total_frames / float(f.samplerate) ),
-        print "(", total_frames, "frames", "in",
-        print total_frames / f.hop_size, "blocks", "at", "%dHz" % f.samplerate, ")",
-        print "from", f.uri
+        print ("read", "%.2fs" % (total_frames / float(f.samplerate) ) ),
+        print ("(", total_frames, "frames", "in" ),
+        print (total_frames / f.hop_size, "blocks", "at", "%dHz" % f.samplerate, ")" ),
+        print ("from", f.uri)
         return total_frames
 
     def test_samplerate_hopsize(self):
@@ -67,7 +67,7 @@
         for p in list_of_sounds:
             try:
                 f = source(p, -1)
-            except ValueError, e:
+            except ValueError as e:
                 pass
             else:
                 self.fail('negative samplerate does not raise ValueError')
@@ -76,7 +76,7 @@
         for p in list_of_sounds:
             try:
                 f = source(p, 0, -1)
-            except ValueError, e:
+            except ValueError as e:
                 pass
             else:
                 self.fail('negative hop_size does not raise ValueError')
@@ -108,11 +108,11 @@
             vec, read = f.do_multi()
             total_frames += read
             if read < f.hop_size: break
-        print "read", "%.2fs" % (total_frames / float(f.samplerate) ),
-        print "(", total_frames, "frames", "in",
-        print f.channels, "channels and",
-        print total_frames / f.hop_size, "blocks", "at", "%dHz" % f.samplerate, ")",
-        print "from", f.uri
+        print ("read", "%.2fs" % (total_frames / float(f.samplerate) ) ),
+        print ("(", total_frames, "frames", "in" ),
+        print (f.channels, "channels and" ),
+        print (total_frames / f.hop_size, "blocks", "at", "%dHz" % f.samplerate, ")" ),
+        print ("from", f.uri)
         return total_frames
 
 if __name__ == '__main__':