History

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

Paul Brossier committed 10 years ago

Commit 689106e1 parent 1c6fe647 files · +53 −53Browse files

Showing the changes to python/tests (7 of 7 files). Show all

Unified · Split

7 files
  1. python/tests/test_fvec.py +11 −11
  2. python/tests/test_mathutils.py +9 −9
  3. python/tests/test_musicutils.py +6 −6
  4. python/tests/test_phasevoc.py +1 −1
  5. python/tests/test_pitch.py +2 −2
  6. python/tests/test_sink.py +13 −13
  7. python/tests/test_source.py +11 −11
python/tests/test_fvec.py+11−11
@@ -19,7 +19,7 @@ class aubio_fvec_test_case(TestCase): · 18 unmodified lines
1919 a = fvec([0,1,2,3])
2020 assert a.dtype == 'float32'
2121 assert a.shape == (4,)
22− assert_equal (range(4), a)
22+ assert_equal (list(range(4)), a)
2323
2424 def test_vector_assign_element(self):
2525 a = fvec(default_size)
@@ -41,7 +41,7 @@ class aubio_fvec_test_case(TestCase): · 15 unmodified lines
4141 a = fvec(1)
4242 a.T
4343 array(a).T
44− a = range(len(a))
44+ a = list(range(len(a)))
4545
4646 def test_wrong_values(self):
4747 self.assertRaises (ValueError, fvec, -10)
@@ -52,11 +52,11 @@ class aubio_fvec_test_case(TestCase): · 4 unmodified lines
5252
5353 def test_alpha_norm_of_fvec(self):
5454 a = fvec(2)
55− self.assertEquals (alpha_norm(a, 1), 0)
55+ self.assertEqual (alpha_norm(a, 1), 0)
5656 a[0] = 1
57− self.assertEquals (alpha_norm(a, 1), 0.5)
57+ self.assertEqual (alpha_norm(a, 1), 0.5)
5858 a[1] = 1
59− self.assertEquals (alpha_norm(a, 1), 1)
59+ self.assertEqual (alpha_norm(a, 1), 1)
6060 a = array([0, 1], dtype='float32')
6161 from math import sqrt
6262 assert_almost_equal (alpha_norm(a, 2), sqrt(2)/2.)
@@ -73,7 +73,7 @@ class aubio_fvec_test_case(TestCase): · 10 unmodified lines
7373 self.assertRaises (ValueError, alpha_norm, a, 1)
7474 # check 1d array
7575 a = array(range(10), dtype = 'float32')
76− self.assertEquals (alpha_norm(a, 1), 4.5)
76+ self.assertEqual (alpha_norm(a, 1), 4.5)
7777
7878 def test_alpha_norm_of_array_of_int(self):
7979 a = array(1, dtype = 'int')
@@ -91,11 +91,11 @@ class aubio_fvec_test_case(TestCase): · 11 unmodified lines
9191 a = array([0,1,-1], dtype='float32')
9292 assert_almost_equal (zero_crossing_rate(a), 1./3. )
9393 a = array([0.]*100, dtype='float32')
94− self.assertEquals (zero_crossing_rate(a), 0 )
94+ self.assertEqual (zero_crossing_rate(a), 0 )
9595 a = array([-1.]*100, dtype='float32')
96− self.assertEquals (zero_crossing_rate(a), 0 )
96+ self.assertEqual (zero_crossing_rate(a), 0 )
9797 a = array([1.]*100, dtype='float32')
98− self.assertEquals (zero_crossing_rate(a), 0 )
98+ self.assertEqual (zero_crossing_rate(a), 0 )
9999
100100 def test_alpha_norm_of_array_of_float64(self):
101101 # check scalar fail
@@ -105,10 +105,10 @@ class aubio_fvec_test_case(TestCase): · 3 unmodified lines
105105 a = array([[[1,2],[3,4]]], dtype = 'float64')
106106 self.assertRaises (ValueError, alpha_norm, a, 1)
107107 # check float64 1d array fail
108− a = array(range(10), dtype = 'float64')
108+ a = array(list(range(10)), dtype = 'float64')
109109 self.assertRaises (ValueError, alpha_norm, a, 1)
110110 # check float64 2d array fail
111− a = array([range(10), range(10)], dtype = 'float64')
111+ a = array([list(range(10)), list(range(10))], dtype = 'float64')
112112 self.assertRaises (ValueError, alpha_norm, a, 1)
113113
114114 def test_fvec_min_removal_of_array(self):
python/tests/test_mathutils.py+9−9
@@ -12,7 +12,7 @@ class aubio_mathutils(TestCase): · 11 unmodified lines
1212 def test_unwrap2pi(self):
1313 unwrap2pi(int(23))
1414 unwrap2pi(float(23.))
15− unwrap2pi(long(23.))
15+ unwrap2pi(int(23.))
1616 unwrap2pi(arange(10))
1717 unwrap2pi(arange(10).astype("int"))
1818 unwrap2pi(arange(10).astype("float"))
@@ -27,8 +27,8 @@ class aubio_mathutils(TestCase): · 8 unmodified lines
2727 #print zip(a, b)
2828
2929 try:
30− print unwrap2pi(["23.","24.",25.])
31− except Exception, e:
30+ print (unwrap2pi(["23.","24.",25.]))
31+ except Exception as e:
3232 pass
3333
3434 def test_unwrap2pi_takes_fvec(self):
@@ -53,7 +53,7 @@ class aubio_mathutils(TestCase): · 18 unmodified lines
5353 assert ( b <= pi ).all()
5454
5555 def test_freqtomidi(self):
56− a = array(range(-20, 50000, 100) + [ -1e32, 1e32 ])
56+ a = array(list(range(-20, 50000, 100)) + [ -1e32, 1e32 ])
5757 b = freqtomidi(a)
5858 #print zip(a, b)
5959 assert_equal ( isnan(array(b)), False )
@@ -61,7 +61,7 @@ class aubio_mathutils(TestCase): · 1 unmodified line
6161 assert_equal ( array(b) < 0, False )
6262
6363 def test_miditofreq(self):
64− a = range(-30, 200) + [-100000, 10000]
64+ a = list(range(-30, 200)) + [-100000, 10000]
6565 b = miditofreq(a)
6666 #print zip(a, b)
6767 assert_equal ( isnan(b), False )
@@ -69,7 +69,7 @@ class aubio_mathutils(TestCase): · 1 unmodified line
6969 assert_equal ( b < 0, False )
7070
7171 def test_miditobin(self):
72− a = range(-30, 200) + [-100000, 10000]
72+ a = list(range(-30, 200)) + [-100000, 10000]
7373 b = [ bintomidi(x, 44100, 512) for x in a ]
7474 #print zip(a, b)
7575 assert_equal ( isnan(array(b)), False )
@@ -77,7 +77,7 @@ class aubio_mathutils(TestCase): · 1 unmodified line
7777 assert_equal ( array(b) < 0, False )
7878
7979 def test_bintomidi(self):
80− a = range(-100, 512)
80+ a = list(range(-100, 512))
8181 b = [ bintomidi(x, 44100, 512) for x in a ]
8282 #print zip(a, b)
8383 assert_equal ( isnan(array(b)), False )
@@ -85,7 +85,7 @@ class aubio_mathutils(TestCase): · 1 unmodified line
8585 assert_equal ( array(b) < 0, False )
8686
8787 def test_freqtobin(self):
88− a = range(-20, 50000, 100) + [ -1e32, 1e32 ]
88+ a = list(range(-20, 50000, 100)) + [ -1e32, 1e32 ]
8989 b = [ freqtobin(x, 44100, 512) for x in a ]
9090 #print zip(a, b)
9191 assert_equal ( isnan(array(b)), False )
@@ -93,7 +93,7 @@ class aubio_mathutils(TestCase): · 1 unmodified line
9393 assert_equal ( array(b) < 0, False )
9494
9595 def test_bintofreq(self):
96− a = range(-20, 148)
96+ a = list(range(-20, 148))
9797 b = [ bintofreq(x, 44100, 512) for x in a ]
9898 #print zip(a, b)
9999 assert_equal ( isnan(array(b)), False )
python/tests/test_musicutils.py+6−6
@@ -17,7 +17,7 @@ class aubio_window(TestCase): · 16 unmodified lines
1717 def test_fail_name_not_string(self):
1818 try:
1919 window(10, 1024)
20− except ValueError, e:
20+ except ValueError as e:
2121 pass
2222 else:
2323 self.fail('non-string window type does not raise a ValueError')
@@ -25,7 +25,7 @@ class aubio_window(TestCase): · 1 unmodified line
2525 def test_fail_size_not_int(self):
2626 try:
2727 window("default", "default")
28− except ValueError, e:
28+ except ValueError as e:
2929 pass
3030 else:
3131 self.fail('non-integer window length does not raise a ValueError')
@@ -43,7 +43,7 @@ class aubio_level_lin(TestCase): · 11 unmodified lines
4343 def test_fail_not_fvec(self):
4444 try:
4545 level_lin("default")
46− except ValueError, e:
46+ except ValueError as e:
4747 pass
4848 else:
4949 self.fail('non-number input phase does not raise a TypeError')
@@ -62,7 +62,7 @@ class aubio_db_spl(TestCase): · 12 unmodified lines
6262 def test_fail_not_fvec(self):
6363 try:
6464 db_spl("default")
65− except ValueError, e:
65+ except ValueError as e:
6666 pass
6767 else:
6868 self.fail('non-number input phase does not raise a TypeError')
@@ -82,7 +82,7 @@ class aubio_silence_detection(TestCase): · 13 unmodified lines
8282 def test_fail_not_fvec(self):
8383 try:
8484 silence_detection("default", -70)
85− except ValueError, e:
85+ except ValueError as e:
8686 pass
8787 else:
8888 self.fail('non-number input phase does not raise a TypeError')
@@ -102,7 +102,7 @@ class aubio_level_detection(TestCase): · 13 unmodified lines
102102 def test_fail_not_fvec(self):
103103 try:
104104 level_detection("default", -70)
105− except ValueError, e:
105+ except ValueError as e:
106106 pass
107107 else:
108108 self.fail('non-number input phase does not raise a TypeError')
python/tests/test_phasevoc.py+1−1
@@ -63,7 +63,7 @@ class aubio_pvoc_test_case(TestCase): · 62 unmodified lines
6363 sigin = fvec(hop_s)
6464 zeros = fvec(hop_s)
6565 f = pvoc(buf_s, hop_s)
66− for i in xrange(hop_s):
66+ for i in range(hop_s):
6767 sigin[i] = random() * 2. - 1.
6868 t2 = f.rdo( f(sigin) )
6969 t2 = f.rdo( f(zeros) )
python/tests/test_pitch.py+2−2
@@ -24,14 +24,14 @@ class aubio_pitch_Good_Values(TestCase): · 23 unmodified lines
2424 " running on silence gives 0 "
2525 p = pitch('default', 2048, 512, 32000)
2626 f = fvec (512)
27− for i in xrange(10): assert_equal (p(f), 0.)
27+ for i in range(10): assert_equal (p(f), 0.)
2828
2929 def test_run_on_ones(self):
3030 " running on ones gives 0 "
3131 p = pitch('default', 2048, 512, 32000)
3232 f = fvec (512)
3333 f[:] = 1
34− for i in xrange(10): assert_equal (p(f), 0.)
34+ for i in range(10): assert_equal (p(f), 0.)
3535
3636 class aubio_pitch_Sinusoid(TestCase):
3737
python/tests/test_sink.py+13−13
@@ -44,7 +44,7 @@ class aubio_sink_test_case(TestCase): · 43 unmodified lines
4444 for n in range(200):
4545 vec = fvec(write)
4646 g(vec, write)
47− except StandardError:
47+ except Exception:
4848 pass
4949 else:
5050 self.fail("does not fail on too many files open")
@@ -70,11 +70,11 @@ class aubio_sink_test_case(TestCase): · 19 unmodified lines
7070 total_frames += read
7171 if read < f.hop_size: break
7272 if 0:
73− print "read", "%.2fs" % (total_frames / float(f.samplerate) ),
74− print "(", total_frames, "frames", "in",
75− print total_frames / f.hop_size, "blocks", "at", "%dHz" % f.samplerate, ")",
76− print "from", f.uri,
77− print "to", g.uri
73+ print ("read", "%.2fs" % (total_frames / float(f.samplerate) ) ),
74+ print ("(", total_frames, "frames", "in" ),
75+ print (total_frames / f.hop_size, "blocks", "at", "%dHz" % f.samplerate, ")" ),
76+ print ("from", f.uri ),
77+ print ("to", g.uri)
7878 del_tmp_sink_path(sink_path)
7979
8080 def test_read_and_write_multi(self):
@@ -95,13 +95,13 @@ class aubio_sink_test_case(TestCase): · 14 unmodified lines
9595 total_frames += read
9696 if read < f.hop_size: break
9797 if 0:
98− print "read", "%.2fs" % (total_frames / float(f.samplerate) ),
99− print "(", total_frames, "frames", "in",
100− print f.channels, "channels", "in",
101− print total_frames / f.hop_size, "blocks", "at", "%dHz" % f.samplerate, ")",
102− print "from", f.uri,
103− print "to", g.uri,
104− print "in", g.channels, "channels"
98+ print ("read", "%.2fs" % (total_frames / float(f.samplerate) ) ),
99+ print ("(", total_frames, "frames", "in" ),
100+ print (f.channels, "channels", "in" ),
101+ print (total_frames / f.hop_size, "blocks", "at", "%dHz" % f.samplerate, ")" ),
102+ print ("from", f.uri ),
103+ print ("to", g.uri ),
104+ print ("in", g.channels, "channels")
105105 del_tmp_sink_path(sink_path)
106106
107107 def test_close_file(self):
python/tests/test_source.py+11−11
@@ -38,10 +38,10 @@ class aubio_source_read_test_case(aubio_source_test_case_base): · 37 unmodified lines
3838 vec, read = f()
3939 total_frames += read
4040 if read < f.hop_size: break
41− print "read", "%.2fs" % (total_frames / float(f.samplerate) ),
42− print "(", total_frames, "frames", "in",
43− print total_frames / f.hop_size, "blocks", "at", "%dHz" % f.samplerate, ")",
44− print "from", f.uri
41+ print ("read", "%.2fs" % (total_frames / float(f.samplerate) ) ),
42+ print ("(", total_frames, "frames", "in" ),
43+ print (total_frames / f.hop_size, "blocks", "at", "%dHz" % f.samplerate, ")" ),
44+ print ("from", f.uri)
4545 return total_frames
4646
4747 def test_samplerate_hopsize(self):
@@ -67,7 +67,7 @@ class aubio_source_read_test_case(aubio_source_test_case_base): · 19 unmodified lines
6767 for p in list_of_sounds:
6868 try:
6969 f = source(p, -1)
70− except ValueError, e:
70+ except ValueError as e:
7171 pass
7272 else:
7373 self.fail('negative samplerate does not raise ValueError')
@@ -76,7 +76,7 @@ class aubio_source_read_test_case(aubio_source_test_case_base): · 2 unmodified lines
7676 for p in list_of_sounds:
7777 try:
7878 f = source(p, 0, -1)
79− except ValueError, e:
79+ except ValueError as e:
8080 pass
8181 else:
8282 self.fail('negative hop_size does not raise ValueError')
@@ -108,11 +108,11 @@ class aubio_source_readmulti_test_case(aubio_source_read_test_case): · 25 unmodified lines
108108 vec, read = f.do_multi()
109109 total_frames += read
110110 if read < f.hop_size: break
111− print "read", "%.2fs" % (total_frames / float(f.samplerate) ),
112− print "(", total_frames, "frames", "in",
113− print f.channels, "channels and",
114− print total_frames / f.hop_size, "blocks", "at", "%dHz" % f.samplerate, ")",
115− print "from", f.uri
111+ print ("read", "%.2fs" % (total_frames / float(f.samplerate) ) ),
112+ print ("(", total_frames, "frames", "in" ),
113+ print (f.channels, "channels and" ),
114+ print (total_frames / f.hop_size, "blocks", "at", "%dHz" % f.samplerate, ")" ),
115+ print ("from", f.uri)
116116 return total_frames
117117
118118 if __name__ == '__main__':

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t