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
19 a = fvec([0,1,2,3])19 a = fvec([0,1,2,3])
20 assert a.dtype == 'float32'20 assert a.dtype == 'float32'
21 assert a.shape == (4,)21 assert a.shape == (4,)
22 assert_equal (range(4), a)22 assert_equal (list(range(4)), a)
23 23
24 def test_vector_assign_element(self):24 def test_vector_assign_element(self):
25 a = fvec(default_size)25 a = fvec(default_size)
@@ -41,7 +41,7 @@ class aubio_fvec_test_case(TestCase): · 15 unmodified lines
41 a = fvec(1)41 a = fvec(1)
42 a.T42 a.T
43 array(a).T43 array(a).T
44 a = range(len(a))44 a = list(range(len(a)))
45 45
46 def test_wrong_values(self):46 def test_wrong_values(self):
47 self.assertRaises (ValueError, fvec, -10)47 self.assertRaises (ValueError, fvec, -10)
@@ -52,11 +52,11 @@ class aubio_fvec_test_case(TestCase): · 4 unmodified lines
52 52
53 def test_alpha_norm_of_fvec(self):53 def test_alpha_norm_of_fvec(self):
54 a = fvec(2)54 a = fvec(2)
55 self.assertEquals (alpha_norm(a, 1), 0)55 self.assertEqual (alpha_norm(a, 1), 0)
56 a[0] = 156 a[0] = 1
57 self.assertEquals (alpha_norm(a, 1), 0.5)57 self.assertEqual (alpha_norm(a, 1), 0.5)
58 a[1] = 158 a[1] = 1
59 self.assertEquals (alpha_norm(a, 1), 1)59 self.assertEqual (alpha_norm(a, 1), 1)
60 a = array([0, 1], dtype='float32')60 a = array([0, 1], dtype='float32')
61 from math import sqrt61 from math import sqrt
62 assert_almost_equal (alpha_norm(a, 2), sqrt(2)/2.)62 assert_almost_equal (alpha_norm(a, 2), sqrt(2)/2.)
@@ -73,7 +73,7 @@ class aubio_fvec_test_case(TestCase): · 10 unmodified lines
73 self.assertRaises (ValueError, alpha_norm, a, 1)73 self.assertRaises (ValueError, alpha_norm, a, 1)
74 # check 1d array74 # check 1d array
75 a = array(range(10), dtype = 'float32')75 a = array(range(10), dtype = 'float32')
76 self.assertEquals (alpha_norm(a, 1), 4.5)76 self.assertEqual (alpha_norm(a, 1), 4.5)
77 77
78 def test_alpha_norm_of_array_of_int(self):78 def test_alpha_norm_of_array_of_int(self):
79 a = array(1, dtype = 'int')79 a = array(1, dtype = 'int')
@@ -91,11 +91,11 @@ class aubio_fvec_test_case(TestCase): · 11 unmodified lines
91 a = array([0,1,-1], dtype='float32')91 a = array([0,1,-1], dtype='float32')
92 assert_almost_equal (zero_crossing_rate(a), 1./3. )92 assert_almost_equal (zero_crossing_rate(a), 1./3. )
93 a = array([0.]*100, dtype='float32')93 a = array([0.]*100, dtype='float32')
94 self.assertEquals (zero_crossing_rate(a), 0 )94 self.assertEqual (zero_crossing_rate(a), 0 )
95 a = array([-1.]*100, dtype='float32')95 a = array([-1.]*100, dtype='float32')
96 self.assertEquals (zero_crossing_rate(a), 0 )96 self.assertEqual (zero_crossing_rate(a), 0 )
97 a = array([1.]*100, dtype='float32')97 a = array([1.]*100, dtype='float32')
98 self.assertEquals (zero_crossing_rate(a), 0 )98 self.assertEqual (zero_crossing_rate(a), 0 )
99 99
100 def test_alpha_norm_of_array_of_float64(self):100 def test_alpha_norm_of_array_of_float64(self):
101 # check scalar fail101 # check scalar fail
@@ -105,10 +105,10 @@ class aubio_fvec_test_case(TestCase): · 3 unmodified lines
105 a = array([[[1,2],[3,4]]], dtype = 'float64')105 a = array([[[1,2],[3,4]]], dtype = 'float64')
106 self.assertRaises (ValueError, alpha_norm, a, 1)106 self.assertRaises (ValueError, alpha_norm, a, 1)
107 # check float64 1d array fail107 # check float64 1d array fail
108 a = array(range(10), dtype = 'float64')108 a = array(list(range(10)), dtype = 'float64')
109 self.assertRaises (ValueError, alpha_norm, a, 1)109 self.assertRaises (ValueError, alpha_norm, a, 1)
110 # check float64 2d array fail110 # 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')
112 self.assertRaises (ValueError, alpha_norm, a, 1)112 self.assertRaises (ValueError, alpha_norm, a, 1)
113 113
114 def test_fvec_min_removal_of_array(self):114 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
12 def test_unwrap2pi(self):12 def test_unwrap2pi(self):
13 unwrap2pi(int(23))13 unwrap2pi(int(23))
14 unwrap2pi(float(23.))14 unwrap2pi(float(23.))
15 unwrap2pi(long(23.))15 unwrap2pi(int(23.))
16 unwrap2pi(arange(10))16 unwrap2pi(arange(10))
17 unwrap2pi(arange(10).astype("int"))17 unwrap2pi(arange(10).astype("int"))
18 unwrap2pi(arange(10).astype("float"))18 unwrap2pi(arange(10).astype("float"))
@@ -27,8 +27,8 @@ class aubio_mathutils(TestCase): · 8 unmodified lines
27 #print zip(a, b)27 #print zip(a, b)
28 28
29 try:29 try:
30 print unwrap2pi(["23.","24.",25.])30 print (unwrap2pi(["23.","24.",25.]))
31 except Exception, e:31 except Exception as e:
32 pass32 pass
33 33
34 def test_unwrap2pi_takes_fvec(self):34 def test_unwrap2pi_takes_fvec(self):
@@ -53,7 +53,7 @@ class aubio_mathutils(TestCase): · 18 unmodified lines
53 assert ( b <= pi ).all()53 assert ( b <= pi ).all()
54 54
55 def test_freqtomidi(self):55 def test_freqtomidi(self):
56 a = array(range(-20, 50000, 100) + [ -1e32, 1e32 ])56 a = array(list(range(-20, 50000, 100)) + [ -1e32, 1e32 ])
57 b = freqtomidi(a)57 b = freqtomidi(a)
58 #print zip(a, b)58 #print zip(a, b)
59 assert_equal ( isnan(array(b)), False )59 assert_equal ( isnan(array(b)), False )
@@ -61,7 +61,7 @@ class aubio_mathutils(TestCase): · 1 unmodified line
61 assert_equal ( array(b) < 0, False )61 assert_equal ( array(b) < 0, False )
62 62
63 def test_miditofreq(self):63 def test_miditofreq(self):
64 a = range(-30, 200) + [-100000, 10000]64 a = list(range(-30, 200)) + [-100000, 10000]
65 b = miditofreq(a)65 b = miditofreq(a)
66 #print zip(a, b)66 #print zip(a, b)
67 assert_equal ( isnan(b), False )67 assert_equal ( isnan(b), False )
@@ -69,7 +69,7 @@ class aubio_mathutils(TestCase): · 1 unmodified line
69 assert_equal ( b < 0, False )69 assert_equal ( b < 0, False )
70 70
71 def test_miditobin(self):71 def test_miditobin(self):
72 a = range(-30, 200) + [-100000, 10000]72 a = list(range(-30, 200)) + [-100000, 10000]
73 b = [ bintomidi(x, 44100, 512) for x in a ]73 b = [ bintomidi(x, 44100, 512) for x in a ]
74 #print zip(a, b)74 #print zip(a, b)
75 assert_equal ( isnan(array(b)), False )75 assert_equal ( isnan(array(b)), False )
@@ -77,7 +77,7 @@ class aubio_mathutils(TestCase): · 1 unmodified line
77 assert_equal ( array(b) < 0, False )77 assert_equal ( array(b) < 0, False )
78 78
79 def test_bintomidi(self):79 def test_bintomidi(self):
80 a = range(-100, 512)80 a = list(range(-100, 512))
81 b = [ bintomidi(x, 44100, 512) for x in a ]81 b = [ bintomidi(x, 44100, 512) for x in a ]
82 #print zip(a, b)82 #print zip(a, b)
83 assert_equal ( isnan(array(b)), False )83 assert_equal ( isnan(array(b)), False )
@@ -85,7 +85,7 @@ class aubio_mathutils(TestCase): · 1 unmodified line
85 assert_equal ( array(b) < 0, False )85 assert_equal ( array(b) < 0, False )
86 86
87 def test_freqtobin(self):87 def test_freqtobin(self):
88 a = range(-20, 50000, 100) + [ -1e32, 1e32 ]88 a = list(range(-20, 50000, 100)) + [ -1e32, 1e32 ]
89 b = [ freqtobin(x, 44100, 512) for x in a ]89 b = [ freqtobin(x, 44100, 512) for x in a ]
90 #print zip(a, b)90 #print zip(a, b)
91 assert_equal ( isnan(array(b)), False )91 assert_equal ( isnan(array(b)), False )
@@ -93,7 +93,7 @@ class aubio_mathutils(TestCase): · 1 unmodified line
93 assert_equal ( array(b) < 0, False )93 assert_equal ( array(b) < 0, False )
94 94
95 def test_bintofreq(self):95 def test_bintofreq(self):
96 a = range(-20, 148)96 a = list(range(-20, 148))
97 b = [ bintofreq(x, 44100, 512) for x in a ]97 b = [ bintofreq(x, 44100, 512) for x in a ]
98 #print zip(a, b)98 #print zip(a, b)
99 assert_equal ( isnan(array(b)), False )99 assert_equal ( isnan(array(b)), False )
python/tests/test_musicutils.py+6−6
@@ -17,7 +17,7 @@ class aubio_window(TestCase): · 16 unmodified lines
17 def test_fail_name_not_string(self):17 def test_fail_name_not_string(self):
18 try:18 try:
19 window(10, 1024)19 window(10, 1024)
20 except ValueError, e:20 except ValueError as e:
21 pass21 pass
22 else:22 else:
23 self.fail('non-string window type does not raise a ValueError')23 self.fail('non-string window type does not raise a ValueError')
@@ -25,7 +25,7 @@ class aubio_window(TestCase): · 1 unmodified line
25 def test_fail_size_not_int(self):25 def test_fail_size_not_int(self):
26 try:26 try:
27 window("default", "default")27 window("default", "default")
28 except ValueError, e:28 except ValueError as e:
29 pass29 pass
30 else:30 else:
31 self.fail('non-integer window length does not raise a ValueError')31 self.fail('non-integer window length does not raise a ValueError')
@@ -43,7 +43,7 @@ class aubio_level_lin(TestCase): · 11 unmodified lines
43 def test_fail_not_fvec(self):43 def test_fail_not_fvec(self):
44 try:44 try:
45 level_lin("default")45 level_lin("default")
46 except ValueError, e:46 except ValueError as e:
47 pass47 pass
48 else:48 else:
49 self.fail('non-number input phase does not raise a TypeError')49 self.fail('non-number input phase does not raise a TypeError')
@@ -62,7 +62,7 @@ class aubio_db_spl(TestCase): · 12 unmodified lines
62 def test_fail_not_fvec(self):62 def test_fail_not_fvec(self):
63 try:63 try:
64 db_spl("default")64 db_spl("default")
65 except ValueError, e:65 except ValueError as e:
66 pass66 pass
67 else:67 else:
68 self.fail('non-number input phase does not raise a TypeError')68 self.fail('non-number input phase does not raise a TypeError')
@@ -82,7 +82,7 @@ class aubio_silence_detection(TestCase): · 13 unmodified lines
82 def test_fail_not_fvec(self):82 def test_fail_not_fvec(self):
83 try:83 try:
84 silence_detection("default", -70)84 silence_detection("default", -70)
85 except ValueError, e:85 except ValueError as e:
86 pass86 pass
87 else:87 else:
88 self.fail('non-number input phase does not raise a TypeError')88 self.fail('non-number input phase does not raise a TypeError')
@@ -102,7 +102,7 @@ class aubio_level_detection(TestCase): · 13 unmodified lines
102 def test_fail_not_fvec(self):102 def test_fail_not_fvec(self):
103 try:103 try:
104 level_detection("default", -70)104 level_detection("default", -70)
105 except ValueError, e:105 except ValueError as e:
106 pass106 pass
107 else:107 else:
108 self.fail('non-number input phase does not raise a TypeError')108 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
63 sigin = fvec(hop_s)63 sigin = fvec(hop_s)
64 zeros = fvec(hop_s)64 zeros = fvec(hop_s)
65 f = pvoc(buf_s, hop_s)65 f = pvoc(buf_s, hop_s)
66 for i in xrange(hop_s):66 for i in range(hop_s):
67 sigin[i] = random() * 2. - 1.67 sigin[i] = random() * 2. - 1.
68 t2 = f.rdo( f(sigin) )68 t2 = f.rdo( f(sigin) )
69 t2 = f.rdo( f(zeros) )69 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
24 " running on silence gives 0 "24 " running on silence gives 0 "
25 p = pitch('default', 2048, 512, 32000)25 p = pitch('default', 2048, 512, 32000)
26 f = fvec (512)26 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.)
28 28
29 def test_run_on_ones(self):29 def test_run_on_ones(self):
30 " running on ones gives 0 "30 " running on ones gives 0 "
31 p = pitch('default', 2048, 512, 32000)31 p = pitch('default', 2048, 512, 32000)
32 f = fvec (512)32 f = fvec (512)
33 f[:] = 133 f[:] = 1
34 for i in xrange(10): assert_equal (p(f), 0.)34 for i in range(10): assert_equal (p(f), 0.)
35 35
36class aubio_pitch_Sinusoid(TestCase):36class aubio_pitch_Sinusoid(TestCase):
37 37
python/tests/test_sink.py+13−13
@@ -44,7 +44,7 @@ class aubio_sink_test_case(TestCase): · 43 unmodified lines
44 for n in range(200):44 for n in range(200):
45 vec = fvec(write)45 vec = fvec(write)
46 g(vec, write)46 g(vec, write)
47 except StandardError:47 except Exception:
48 pass48 pass
49 else:49 else:
50 self.fail("does not fail on too many files open")50 self.fail("does not fail on too many files open")
@@ -70,11 +70,11 @@ class aubio_sink_test_case(TestCase): · 19 unmodified lines
70 total_frames += read70 total_frames += read
71 if read < f.hop_size: break71 if read < f.hop_size: break
72 if 0:72 if 0:
73 print "read", "%.2fs" % (total_frames / float(f.samplerate) ),73 print ("read", "%.2fs" % (total_frames / float(f.samplerate) ) ),
74 print "(", total_frames, "frames", "in",74 print ("(", total_frames, "frames", "in" ),
75 print total_frames / f.hop_size, "blocks", "at", "%dHz" % f.samplerate, ")",75 print (total_frames / f.hop_size, "blocks", "at", "%dHz" % f.samplerate, ")" ),
76 print "from", f.uri,76 print ("from", f.uri ),
77 print "to", g.uri77 print ("to", g.uri)
78 del_tmp_sink_path(sink_path)78 del_tmp_sink_path(sink_path)
79 79
80 def test_read_and_write_multi(self):80 def test_read_and_write_multi(self):
@@ -95,13 +95,13 @@ class aubio_sink_test_case(TestCase): · 14 unmodified lines
95 total_frames += read95 total_frames += read
96 if read < f.hop_size: break96 if read < f.hop_size: break
97 if 0:97 if 0:
98 print "read", "%.2fs" % (total_frames / float(f.samplerate) ),98 print ("read", "%.2fs" % (total_frames / float(f.samplerate) ) ),
99 print "(", total_frames, "frames", "in",99 print ("(", total_frames, "frames", "in" ),
100 print f.channels, "channels", "in",100 print (f.channels, "channels", "in" ),
101 print total_frames / f.hop_size, "blocks", "at", "%dHz" % f.samplerate, ")",101 print (total_frames / f.hop_size, "blocks", "at", "%dHz" % f.samplerate, ")" ),
102 print "from", f.uri,102 print ("from", f.uri ),
103 print "to", g.uri,103 print ("to", g.uri ),
104 print "in", g.channels, "channels"104 print ("in", g.channels, "channels")
105 del_tmp_sink_path(sink_path)105 del_tmp_sink_path(sink_path)
106 106
107 def test_close_file(self):107 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
38 vec, read = f()38 vec, read = f()
39 total_frames += read39 total_frames += read
40 if read < f.hop_size: break40 if read < f.hop_size: break
41 print "read", "%.2fs" % (total_frames / float(f.samplerate) ),41 print ("read", "%.2fs" % (total_frames / float(f.samplerate) ) ),
42 print "(", total_frames, "frames", "in",42 print ("(", total_frames, "frames", "in" ),
43 print total_frames / f.hop_size, "blocks", "at", "%dHz" % f.samplerate, ")",43 print (total_frames / f.hop_size, "blocks", "at", "%dHz" % f.samplerate, ")" ),
44 print "from", f.uri44 print ("from", f.uri)
45 return total_frames45 return total_frames
46 46
47 def test_samplerate_hopsize(self):47 def test_samplerate_hopsize(self):
@@ -67,7 +67,7 @@ class aubio_source_read_test_case(aubio_source_test_case_base): · 19 unmodified lines
67 for p in list_of_sounds:67 for p in list_of_sounds:
68 try:68 try:
69 f = source(p, -1)69 f = source(p, -1)
70 except ValueError, e:70 except ValueError as e:
71 pass71 pass
72 else:72 else:
73 self.fail('negative samplerate does not raise ValueError')73 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
76 for p in list_of_sounds:76 for p in list_of_sounds:
77 try:77 try:
78 f = source(p, 0, -1)78 f = source(p, 0, -1)
79 except ValueError, e:79 except ValueError as e:
80 pass80 pass
81 else:81 else:
82 self.fail('negative hop_size does not raise ValueError')82 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
108 vec, read = f.do_multi()108 vec, read = f.do_multi()
109 total_frames += read109 total_frames += read
110 if read < f.hop_size: break110 if read < f.hop_size: break
111 print "read", "%.2fs" % (total_frames / float(f.samplerate) ),111 print ("read", "%.2fs" % (total_frames / float(f.samplerate) ) ),
112 print "(", total_frames, "frames", "in",112 print ("(", total_frames, "frames", "in" ),
113 print f.channels, "channels and",113 print (f.channels, "channels and" ),
114 print total_frames / f.hop_size, "blocks", "at", "%dHz" % f.samplerate, ")",114 print (total_frames / f.hop_size, "blocks", "at", "%dHz" % f.samplerate, ")" ),
115 print "from", f.uri115 print ("from", f.uri)
116 return total_frames116 return total_frames
117 117
118if __name__ == '__main__':118if __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