From: Paul Brossier Date: Mon, 18 Apr 2016 21:24:47 +0000 (+0200) Subject: python/tests/: prepare for python3 (see #33) X-Git-Tag: 0.4.4~300^2~311 X-Git-Url: https://git.aubio.org/?a=commitdiff_plain;h=689106ecec1986332b7f2bbb30928e034b3b6de2;p=aubio.git python/tests/: prepare for python3 (see #33) --- diff --git a/python/tests/test_fvec.py b/python/tests/test_fvec.py index 7521b298..9340ef92 100755 --- a/python/tests/test_fvec.py +++ b/python/tests/test_fvec.py @@ -19,7 +19,7 @@ class aubio_fvec_test_case(TestCase): 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 @@ class aubio_fvec_test_case(TestCase): 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 @@ class aubio_fvec_test_case(TestCase): 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 @@ class aubio_fvec_test_case(TestCase): 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 @@ class aubio_fvec_test_case(TestCase): 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 @@ class aubio_fvec_test_case(TestCase): 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): diff --git a/python/tests/test_mathutils.py b/python/tests/test_mathutils.py index e61dc8e4..e42c3a54 100755 --- a/python/tests/test_mathutils.py +++ b/python/tests/test_mathutils.py @@ -12,7 +12,7 @@ class aubio_mathutils(TestCase): 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 @@ class aubio_mathutils(TestCase): #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 @@ class aubio_mathutils(TestCase): 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 @@ class aubio_mathutils(TestCase): 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 @@ class aubio_mathutils(TestCase): 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 @@ class aubio_mathutils(TestCase): 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 @@ class aubio_mathutils(TestCase): 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 @@ class aubio_mathutils(TestCase): 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 ) diff --git a/python/tests/test_musicutils.py b/python/tests/test_musicutils.py index 35132895..20e6168c 100755 --- a/python/tests/test_musicutils.py +++ b/python/tests/test_musicutils.py @@ -17,7 +17,7 @@ class aubio_window(TestCase): 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 @@ class aubio_window(TestCase): 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 @@ class aubio_level_lin(TestCase): 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 @@ class aubio_db_spl(TestCase): 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 @@ class aubio_silence_detection(TestCase): 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 @@ class aubio_level_detection(TestCase): 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') diff --git a/python/tests/test_phasevoc.py b/python/tests/test_phasevoc.py index 1ffd26c2..2e19f264 100755 --- a/python/tests/test_phasevoc.py +++ b/python/tests/test_phasevoc.py @@ -63,7 +63,7 @@ class aubio_pvoc_test_case(TestCase): 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) ) diff --git a/python/tests/test_pitch.py b/python/tests/test_pitch.py index c0c15cd0..89ced4af 100755 --- a/python/tests/test_pitch.py +++ b/python/tests/test_pitch.py @@ -24,14 +24,14 @@ class aubio_pitch_Good_Values(TestCase): " 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 " 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): diff --git a/python/tests/test_sink.py b/python/tests/test_sink.py index 54749d8e..b6e7061e 100755 --- a/python/tests/test_sink.py +++ b/python/tests/test_sink.py @@ -44,7 +44,7 @@ class aubio_sink_test_case(TestCase): 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 @@ class aubio_sink_test_case(TestCase): 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 @@ class aubio_sink_test_case(TestCase): 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): diff --git a/python/tests/test_source.py b/python/tests/test_source.py index f571a147..1ade98d0 100755 --- a/python/tests/test_source.py +++ b/python/tests/test_source.py @@ -38,10 +38,10 @@ class aubio_source_read_test_case(aubio_source_test_case_base): 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 @@ class aubio_source_read_test_case(aubio_source_test_case_base): 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 @@ class aubio_source_read_test_case(aubio_source_test_case_base): 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 @@ class aubio_source_readmulti_test_case(aubio_source_read_test_case): 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__':