From: Paul Brossier Date: Mon, 18 Apr 2016 21:46:18 +0000 (+0200) Subject: tests/: continue python3 preparation X-Git-Tag: 0.4.4~300^2~309 X-Git-Url: https://git.aubio.org/?a=commitdiff_plain;h=376d5e97103f3715d0ef89df155c14ffe6cbec09;p=aubio.git tests/: continue python3 preparation --- diff --git a/python/tests/test_filterbank.py b/python/tests/test_filterbank.py index 02ae0f3e..f419d533 100755 --- a/python/tests/test_filterbank.py +++ b/python/tests/test_filterbank.py @@ -16,7 +16,7 @@ class aubio_filterbank_test_case(TestCase): 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 @@ class aubio_filterbank_test_case(TestCase): 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 @@ class aubio_filterbank_test_case(TestCase): 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 ) diff --git a/python/tests/test_note2midi.py b/python/tests/test_note2midi.py index c4503b0b..055580e7 100755 --- a/python/tests/test_note2midi.py +++ b/python/tests/test_note2midi.py @@ -69,7 +69,7 @@ class freq2note_simple_test(unittest.TestCase): def test_freq2note(self): " make sure freq2note(441) == A4 " - self.assertEquals("A4", freq2note(441)) + self.assertEqual("A4", freq2note(441)) if __name__ == '__main__': unittest.main() diff --git a/python/tests/test_phasevoc.py b/python/tests/test_phasevoc.py index 2e19f264..45a92be7 100755 --- a/python/tests/test_phasevoc.py +++ b/python/tests/test_phasevoc.py @@ -30,7 +30,7 @@ class aubio_pvoc_test_case(TestCase): 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) diff --git a/python/tests/test_zero_crossing_rate.py b/python/tests/test_zero_crossing_rate.py index 06cd6dc5..b7b9965d 100755 --- a/python/tests/test_zero_crossing_rate.py +++ b/python/tests/test_zero_crossing_rate.py @@ -22,24 +22,24 @@ class zero_crossing_rate_test_case(TestCase): 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__': diff --git a/python/tests/utils.py b/python/tests/utils.py index 1cec0530..6d98c14e 100644 --- a/python/tests/utils.py +++ b/python/tests/utils.py @@ -4,8 +4,10 @@ def array_from_text_file(filename, dtype = 'float'): 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