ref: 376d5e97103f3715d0ef89df155c14ffe6cbec09
parent: 6db76007fdbbb97428dcf4255b2284bc5a0652f7
author: Paul Brossier <piem@piem.org>
date: Mon Apr 18 19:46:18 EDT 2016
tests/: continue python3 preparation
--- a/python/tests/test_filterbank.py
+++ b/python/tests/test_filterbank.py
@@ -16,7 +16,7 @@
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 @@
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 @@
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 )
--- a/python/tests/test_note2midi.py
+++ b/python/tests/test_note2midi.py
@@ -69,7 +69,7 @@
def test_freq2note(self):
" make sure freq2note(441) == A4 "
- self.assertEquals("A4", freq2note(441))
+ self.assertEqual("A4", freq2note(441))
if __name__ == '__main__':
unittest.main()
--- a/python/tests/test_phasevoc.py
+++ b/python/tests/test_phasevoc.py
@@ -30,7 +30,7 @@
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)
--- a/python/tests/test_zero_crossing_rate.py
+++ b/python/tests/test_zero_crossing_rate.py
@@ -22,24 +22,24 @@
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__':
--- a/python/tests/utils.py
+++ b/python/tests/utils.py
@@ -4,8 +4,10 @@
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