Changeset 0b6d23d for python/tests
- Timestamp:
- May 16, 2016, 5:08:18 AM (9 years ago)
- Branches:
- feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
- Children:
- a6f9ebf
- Parents:
- 58a5fb9
- Location:
- python/tests
- Files:
-
- 21 edited
Legend:
- Unmodified
- Added
- Removed
-
python/tests/test_aubio.py
r58a5fb9 r0b6d23d 1 1 #! /usr/bin/env python 2 2 3 from numpy.testing import TestCase, run_module_suite 3 from unittest import main 4 from numpy.testing import TestCase 4 5 5 6 class aubiomodule_test_case(TestCase): 6 7 7 def test_import(self):8 """ try importing aubio """9 import aubio8 def test_import(self): 9 """ try importing aubio """ 10 import aubio 10 11 11 12 if __name__ == '__main__': 12 from unittest import main 13 main() 13 main() 14 14 -
python/tests/test_cvec.py
r58a5fb9 r0b6d23d 1 1 #! /usr/bin/env python 2 2 3 from numpy.testing import TestCase 4 from numpy.testing import assert_equal, assert_almost_equal 3 from unittest import main 4 import numpy as np 5 from numpy.testing import TestCase, assert_equal 5 6 from aubio import cvec, fvec, float_type 6 import numpy as np7 7 8 8 wrong_type = 'float32' if float_type == 'float64' else 'float64' … … 14 14 assert_equal(a.norm.shape[0], 10 / 2 + 1) 15 15 assert_equal(a.phas.shape[0], 10 / 2 + 1) 16 a.norm[0]16 _ = a.norm[0] 17 17 assert_equal(a.norm, 0.) 18 18 assert_equal(a.phas, 0.) … … 143 143 144 144 if __name__ == '__main__': 145 from nose2 import main146 145 main() -
python/tests/test_fft.py
r58a5fb9 r0b6d23d 1 1 #! /usr/bin/env python 2 2 3 from unittest import main 3 4 from numpy.testing import TestCase 4 5 from numpy.testing import assert_equal, assert_almost_equal 6 import numpy as np 5 7 from aubio import fvec, fft, cvec 6 from math import pi 8 from math import pi, floor 9 from random import random 7 10 8 11 class aubio_fft_test_case(TestCase): … … 35 38 def test_impulse(self): 36 39 """ check the transform of one impulse at a random place """ 37 from random import random38 from math import floor39 40 win_s = 256 40 41 i = int(floor(random()*win_s)) … … 50 51 51 52 def test_impulse_negative(self): 52 """ check the transform of one impulse at a random place """ 53 from random import random 54 from math import floor 53 """ check the transform of a negative impulse at a random place """ 55 54 win_s = 256 56 i = 057 impulse = - 10.55 i = int(floor(random()*win_s)) 56 impulse = -.1 58 57 f = fft(win_s) 59 58 timegrain = fvec(win_s) 59 timegrain[0] = 0 60 60 timegrain[i] = impulse 61 61 fftgrain = f ( timegrain ) 62 62 #self.plot_this ( fftgrain.phas ) 63 assert_almost_equal ( fftgrain.norm, abs(impulse), decimal = 6)63 assert_almost_equal ( fftgrain.norm, abs(impulse), decimal = 5 ) 64 64 if impulse < 0: 65 65 # phase can be pi or -pi, as it is not unwrapped 66 assert_almost_equal ( abs(fftgrain.phas[1:-1]) , pi, decimal = 6 )66 #assert_almost_equal ( abs(fftgrain.phas[1:-1]) , pi, decimal = 6 ) 67 67 assert_almost_equal ( fftgrain.phas[0], pi, decimal = 6) 68 assert_almost_equal ( fftgrain.phas[-1], pi, decimal = 6)68 assert_almost_equal ( np.fmod(fftgrain.phas[-1], pi), 0, decimal = 6) 69 69 else: 70 assert_equal ( fftgrain.phas[1:-1] == 0, True)71 assert_equal ( fftgrain.phas[0] == 0, True)72 assert_ equal ( fftgrain.phas[-1] == 0, True)70 #assert_equal ( fftgrain.phas[1:-1] == 0, True) 71 assert_equal ( fftgrain.phas[0], 0) 72 assert_almost_equal ( np.fmod(fftgrain.phas[-1], pi), 0, decimal = 6) 73 73 # now check the resynthesis 74 74 synthgrain = f.rdo ( fftgrain ) … … 96 96 """ check running fft.rdo before fft.do works """ 97 97 win_s = 1024 98 impulse = pi99 98 f = fft(win_s) 100 99 fftgrain = cvec(win_s) … … 178 177 with self.assertRaises(RuntimeError): 179 178 fft(win_s) 180 except AssertionError as e:179 except AssertionError: 181 180 self.skipTest('creating aubio.fft with size %d did not fail' % win_s) 182 181 … … 187 186 188 187 if __name__ == '__main__': 189 from nose2 import main190 188 main() -
python/tests/test_filter.py
r58a5fb9 r0b6d23d 1 1 #! /usr/bin/env python 2 2 3 from unittest import main 3 4 from numpy.testing import TestCase, assert_equal, assert_almost_equal 4 5 from aubio import fvec, digital_filter 5 from numpy import array6 6 from utils import array_from_text_file 7 7 … … 85 85 86 86 if __name__ == '__main__': 87 from unittest import main88 87 main() -
python/tests/test_filterbank.py
r58a5fb9 r0b6d23d 1 1 #! /usr/bin/env python 2 2 3 from unittest import main 3 4 from numpy.testing import TestCase 4 5 from numpy.testing import assert_equal, assert_almost_equal … … 81 82 82 83 if __name__ == '__main__': 83 from nose2 import main84 84 main() 85 -
python/tests/test_filterbank_mel.py
r58a5fb9 r0b6d23d 1 1 #! /usr/bin/env python 2 2 3 from numpy.testing import TestCase, run_module_suite 3 from unittest import main 4 from numpy.testing import TestCase 4 5 from numpy.testing import assert_equal, assert_almost_equal 5 6 from numpy import array, shape … … 8 9 class aubio_filterbank_mel_test_case(TestCase): 9 10 10 def test_slaney(self):11 f = filterbank(40, 512)12 f.set_mel_coeffs_slaney(16000)13 a = f.get_coeffs()14 assert_equal(shape (a), (40, 512/2 + 1) )11 def test_slaney(self): 12 f = filterbank(40, 512) 13 f.set_mel_coeffs_slaney(16000) 14 a = f.get_coeffs() 15 assert_equal(shape (a), (40, 512/2 + 1) ) 15 16 16 def test_other_slaney(self):17 f = filterbank(40, 512*2)18 f.set_mel_coeffs_slaney(44100)19 a= f.get_coeffs()20 #print "sum is", sum(sum(a))21 for win_s in [256, 512, 1024, 2048, 4096]:22 f = filterbank(40, win_s)23 f.set_mel_coeffs_slaney(320000)24 a= f.get_coeffs()25 #print "sum is", sum(sum(a))17 def test_other_slaney(self): 18 f = filterbank(40, 512*2) 19 f.set_mel_coeffs_slaney(44100) 20 _ = f.get_coeffs() 21 #print "sum is", sum(sum(a)) 22 for win_s in [256, 512, 1024, 2048, 4096]: 23 f = filterbank(40, win_s) 24 f.set_mel_coeffs_slaney(32000) 25 _ = f.get_coeffs() 26 #print "sum is", sum(sum(a)) 26 27 27 def test_triangle_freqs_zeros(self):28 f = filterbank(9, 1024)29 freq_list = [40, 80, 200, 400, 800, 1600, 3200, 6400, 12800, 15000, 24000]30 freqs = array(freq_list, dtype = float_type)31 f.set_triangle_bands(freqs, 48000)32 f.get_coeffs().T33 assert_equal ( f(cvec(1024)), 0)28 def test_triangle_freqs_zeros(self): 29 f = filterbank(9, 1024) 30 freq_list = [40, 80, 200, 400, 800, 1600, 3200, 6400, 12800, 15000, 24000] 31 freqs = array(freq_list, dtype = float_type) 32 f.set_triangle_bands(freqs, 48000) 33 _ = f.get_coeffs().T 34 assert_equal ( f(cvec(1024)), 0) 34 35 35 def test_triangle_freqs_ones(self):36 f = filterbank(9, 1024)37 freq_list = [40, 80, 200, 400, 800, 1600, 3200, 6400, 12800, 15000, 24000]38 freqs = array(freq_list, dtype = float_type)39 f.set_triangle_bands(freqs, 48000)40 f.get_coeffs().T41 spec = cvec(1024)42 spec.norm[:] = 143 assert_almost_equal ( f(spec),44 [ 0.02070313, 0.02138672, 0.02127604, 0.02135417,45 0.02133301, 0.02133301, 0.02133311, 0.02133334,0.02133345])36 def test_triangle_freqs_ones(self): 37 f = filterbank(9, 1024) 38 freq_list = [40, 80, 200, 400, 800, 1600, 3200, 6400, 12800, 15000, 24000] 39 freqs = array(freq_list, dtype = float_type) 40 f.set_triangle_bands(freqs, 48000) 41 _ = f.get_coeffs().T 42 spec = cvec(1024) 43 spec.norm[:] = 1 44 assert_almost_equal ( f(spec), 45 [ 0.02070313, 0.02138672, 0.02127604, 0.02135417, 46 0.02133301, 0.02133301, 0.02133311, 0.02133334, 0.02133345]) 46 47 47 48 if __name__ == '__main__': 48 from unittest import main 49 main() 50 51 49 main() -
python/tests/test_fvec.py
r58a5fb9 r0b6d23d 1 1 #! /usr/bin/env python 2 2 3 from unittest import main 3 4 import numpy as np 4 5 from numpy.testing import TestCase, assert_equal, assert_almost_equal … … 50 51 self.assertRaises(ValueError, fvec, -10) 51 52 52 def test_ negative_length(self):53 def test_zero_length(self): 53 54 """ test creating fvec with zero length fails (pure python) """ 54 55 self.assertRaises(ValueError, fvec, 0) … … 129 130 def test_pass_to_numpy(self): 130 131 a = fvec(10) 131 a = 1.132 a[:] = 1. 132 133 b = a 133 134 del a … … 140 141 141 142 if __name__ == '__main__': 142 from unittest import main143 143 main() -
python/tests/test_mathutils.py
r58a5fb9 r0b6d23d 1 1 #! /usr/bin/env python 2 2 3 from unittest import main 3 4 from numpy.testing import TestCase, assert_equal 4 5 from numpy import array, arange, isnan, isinf … … 24 25 unwrap2pi(a) 25 26 a = pi/100. * arange(-600,600).astype("float") 26 b = unwrap2pi(a)27 unwrap2pi(a) 27 28 #print zip(a, b) 28 29 29 try: 30 print (unwrap2pi(["23.","24.",25.])) 31 except Exception as e: 32 pass 30 def test_unwrap2pi_fails_on_list(self): 31 with self.assertRaises(TypeError): 32 unwrap2pi(["23.","24.",25.]) 33 33 34 34 def test_unwrap2pi_takes_fvec(self): … … 102 102 103 103 if __name__ == '__main__': 104 from unittest import main105 104 main() -
python/tests/test_mfcc.py
r58a5fb9 r0b6d23d 1 1 #! /usr/bin/env python 2 2 3 from numpy.testing import TestCase, assert_equal, assert_almost_equal 4 from numpy import random, arange, log, zeros, count_nonzero 3 from nose2 import main 4 from nose2.tools import params 5 from numpy import random, count_nonzero 6 from numpy.testing import TestCase 5 7 from aubio import mfcc, cvec, float_type 6 from math import pi7 8 8 9 buf_size = 2048 … … 11 12 samplerate = 44100 12 13 13 from nose2.tools import params14 14 15 15 new_params = ['buf_size', 'n_filters', 'n_coeffs', 'samplerate'] … … 102 102 spec = cvec(buf_size) 103 103 spec.phas[0] = 0.2 104 for iin range(10):105 coeffs =o(spec)104 for _ in range(10): 105 o(spec) 106 106 #print coeffs 107 107 108 108 if __name__ == '__main__': 109 import nose2 110 nose2.main() 109 main() -
python/tests/test_midi2note.py
r58a5fb9 r0b6d23d 28 28 self.assertRaises(ValueError, midi2note, -2) 29 29 30 def test_midi2note_ negative_value(self):30 def test_midi2note_large(self): 31 31 " fails when passed a value greater than 127 " 32 32 self.assertRaises(ValueError, midi2note, 128) -
python/tests/test_musicutils.py
r58a5fb9 r0b6d23d 1 1 #! /usr/bin/env python 2 2 3 from unittest import main 4 import numpy as np 3 5 from numpy.testing import TestCase 4 6 from numpy.testing.utils import assert_equal, assert_almost_equal 5 from numpy import cos, arange6 from math import pi7 8 7 from aubio import window, level_lin, db_spl, silence_detection, level_detection 9 10 8 from aubio import fvec, float_type 11 9 … … 26 24 size = 1024 27 25 aubio_window = window("hanning", size) 28 numpy_window = .5 - .5 * cos(2. * pi *arange(size) / size)26 numpy_window = .5 - .5 * np.cos(2. * np.pi * np.arange(size) / size) 29 27 assert_almost_equal(aubio_window, numpy_window) 30 28 … … 34 32 35 33 def test_fail_not_fvec(self): 36 try:34 with self.assertRaises(ValueError): 37 35 level_lin("default") 38 except ValueError as e:39 pass40 else:41 self.fail('non-number input phase does not raise a TypeError')42 36 43 37 def test_zeros_is_zeros(self): … … 45 39 46 40 def test_minus_ones_is_one(self): 47 from numpy import ones 48 assert_equal(level_lin(-ones(1024, dtype = float_type)), 1.) 41 assert_equal(level_lin(-np.ones(1024, dtype = float_type)), 1.) 49 42 50 43 class aubio_db_spl(TestCase): … … 53 46 54 47 def test_fail_not_fvec(self): 55 try:48 with self.assertRaises(ValueError): 56 49 db_spl("default") 57 except ValueError as e:58 pass59 else:60 self.fail('non-number input phase does not raise a TypeError')61 50 62 51 def test_zeros_is_inf(self): 63 from math import isinf 64 assert isinf(db_spl(fvec(1024))) 52 assert np.isinf(db_spl(fvec(1024))) 65 53 66 54 def test_minus_ones_is_zero(self): 67 from numpy import ones 68 assert_equal(db_spl(-ones(1024, dtype = float_type)), 0.) 55 assert_equal(db_spl(-np.ones(1024, dtype = float_type)), 0.) 69 56 70 57 class aubio_silence_detection(TestCase): … … 73 60 74 61 def test_fail_not_fvec(self): 75 try:62 with self.assertRaises(ValueError): 76 63 silence_detection("default", -70) 77 except ValueError as e:78 pass79 else:80 self.fail('non-number input phase does not raise a TypeError')81 64 82 65 def test_zeros_is_one(self): 83 from math import isinf84 66 assert silence_detection(fvec(1024), -70) == 1 85 67 … … 93 75 94 76 def test_fail_not_fvec(self): 95 try:77 with self.assertRaises(ValueError): 96 78 level_detection("default", -70) 97 except ValueError as e:98 pass99 else:100 self.fail('non-number input phase does not raise a TypeError')101 79 102 80 def test_zeros_is_one(self): 103 from math import isinf104 81 assert level_detection(fvec(1024), -70) == 1 105 82 … … 109 86 110 87 if __name__ == '__main__': 111 from unittest import main112 88 main() -
python/tests/test_note2midi.py
r58a5fb9 r0b6d23d 59 59 self.assertRaises(ValueError, note2midi, 'W9') 60 60 61 def test_note2midi_ wrong_octave(self):62 " fails when passed a note with a wrongoctave"61 def test_note2midi_low_octave(self): 62 " fails when passed a note with a too low octave" 63 63 self.assertRaises(ValueError, note2midi, 'C-9') 64 64 -
python/tests/test_onset.py
r58a5fb9 r0b6d23d 1 1 #! /usr/bin/env python 2 2 3 from numpy.testing import TestCase, run_module_suite4 from numpy.testing import assert_equal, assert_almost_equal3 from unittest import main 4 from numpy.testing import TestCase, assert_equal, assert_almost_equal 5 5 from aubio import onset 6 6 … … 85 85 86 86 if __name__ == '__main__': 87 from unittest import main88 87 main() -
python/tests/test_phasevoc.py
r58a5fb9 r0b6d23d 3 3 from numpy.testing import TestCase, assert_equal, assert_array_less 4 4 from aubio import fvec, cvec, pvoc, float_type 5 from nose2 import main 5 6 from nose2.tools import params 6 7 import numpy as np … … 41 42 f = pvoc (win_s, hop_s) 42 43 t = fvec (hop_s) 43 for timein range( int ( 4 * win_s / hop_s ) ):44 for _ in range( int ( 4 * win_s / hop_s ) ): 44 45 s = f(t) 45 46 r = f.rdo(s) … … 103 104 zeros = fvec(hop_s) 104 105 r2 = f.rdo( f(sigin) ) 105 for iin range(1, ratio):106 for _ in range(1, ratio): 106 107 r2 = f.rdo( f(zeros) ) 107 108 # compute square errors … … 178 179 with self.assertRaises(RuntimeError): 179 180 pvoc(win_s, hop_s) 180 except AssertionError as e:181 except AssertionError: 181 182 # when compiled with fftw3, aubio supports non power of two fft sizes 182 183 self.skipTest('creating aubio.pvoc with size %d did not fail' % win_s) 183 184 184 185 if __name__ == '__main__': 185 from nose2 import main186 186 main() 187 187 -
python/tests/test_pitch.py
r58a5fb9 r0b6d23d 1 1 #! /usr/bin/env python 2 2 3 from unittest import TestCase 4 from numpy.testing import assert_equal, assert_almost_equal 5 from numpy import random, sin, arange, mean, median, isnan 6 from math import pi 3 from unittest import TestCase, main 4 from numpy.testing import assert_equal 5 from numpy import sin, arange, mean, median, isnan, pi 7 6 from aubio import fvec, pitch, freqtomidi, float_type 8 7 … … 25 24 p = pitch('default', 2048, 512, 32000) 26 25 f = fvec (512) 27 for iin range(10): assert_equal (p(f), 0.)26 for _ in range(10): assert_equal (p(f), 0.) 28 27 29 28 def test_run_on_ones(self): … … 32 31 f = fvec (512) 33 32 f[:] = 1 34 for iin range(10): assert_equal (p(f), 0.)33 for _ in range(10): assert_equal (p(f), 0.) 35 34 36 35 class aubio_pitch_Sinusoid(TestCase): … … 54 53 55 54 def run_pitch(self, p, input_vec, freq): 56 count = 057 55 pitches, errors = [], [] 58 56 input_blocks = input_vec.reshape((-1, p.hop_size)) … … 64 62 assert_equal ( isnan(pitches), False ) 65 63 # cut the first candidates 66 cut = ( p.buf_size - p.hop_size ) / p.hop_size64 #cut = ( p.buf_size - p.hop_size ) / p.hop_size 67 65 pitches = pitches[2:] 68 66 errors = errors[2:] … … 125 123 126 124 if __name__ == '__main__': 127 from unittest import main128 125 main() -
python/tests/test_sink.py
r58a5fb9 r0b6d23d 1 1 #! /usr/bin/env python 2 2 3 from n umpy.testing import TestCase, assert_equal, assert_almost_equal3 from nose2 import main 4 4 from nose2.tools import params 5 from numpy.testing import TestCase 5 6 from aubio import fvec, source, sink 6 from numpy import array7 7 from utils import list_all_sounds, get_tmp_sink_path, del_tmp_sink_path 8 8 … … 38 38 sink_list.append(g) 39 39 write = 32 40 for nin range(200):40 for _ in range(200): 41 41 vec = fvec(write) 42 42 g(vec, write) … … 95 95 96 96 if __name__ == '__main__': 97 from nose2 import main98 97 main() -
python/tests/test_slicing.py
r58a5fb9 r0b6d23d 1 1 #! /usr/bin/env python 2 2 3 from numpy.testing import TestCase, run_module_suite 4 from numpy.testing import assert_equal, assert_almost_equal 5 3 from unittest import main 4 from numpy.testing import TestCase, assert_equal 6 5 from aubio import slice_source_at_stamps 7 from utils import * 6 from utils import count_files_in_directory, get_default_test_sound 7 from utils import count_samples_in_directory, count_samples_in_file 8 8 9 9 import tempfile … … 147 147 148 148 if __name__ == '__main__': 149 from unittest import main150 149 main() -
python/tests/test_source.py
r58a5fb9 r0b6d23d 1 1 #! /usr/bin/env python 2 2 3 from numpy.testing import TestCase, assert_equal, assert_almost_equal 4 from aubio import fvec, source 5 from numpy import array 3 from nose2 import main 4 from nose2.tools import params 5 from numpy.testing import TestCase 6 from aubio import source 6 7 from utils import list_all_sounds 7 from nose2.tools import params8 8 9 9 list_of_sounds = list_all_sounds('sounds') … … 48 48 total_frames = 0 49 49 while True: 50 vec, read = f()50 _ , read = f() 51 51 total_frames += read 52 52 if read < f.hop_size: break 53 result_str = "read {:.2f}s ({:d} frames in {:d} blocks at {:d}Hz) from {:s}"54 result_params = total_frames / float(f.samplerate), total_frames, total_frames//f.hop_size, f.samplerate, f.uri53 #result_str = "read {:.2f}s ({:d} frames in {:d} blocks at {:d}Hz) from {:s}" 54 #result_params = total_frames / float(f.samplerate), total_frames, total_frames//f.hop_size, f.samplerate, f.uri 55 55 #print (result_str.format(*result_params)) 56 56 return total_frames … … 102 102 duration = f.duration 103 103 while True: 104 vec, read = f()104 _, read = f() 105 105 total_frames += read 106 106 if read < f.hop_size: break … … 112 112 def test_wrong_file(self): 113 113 with self.assertRaises(RuntimeError): 114 f =source('path_to/unexisting file.mp3')114 source('path_to/unexisting file.mp3') 115 115 116 116 class aubio_source_test_wrong_params_with_file(aubio_source_test_case_base): … … 118 118 def test_wrong_samplerate(self): 119 119 with self.assertRaises(ValueError): 120 f =source(self.default_test_sound, -1)120 source(self.default_test_sound, -1) 121 121 122 122 def test_wrong_hop_size(self): 123 123 with self.assertRaises(ValueError): 124 f =source(self.default_test_sound, 0, -1)124 source(self.default_test_sound, 0, -1) 125 125 126 126 def test_wrong_channels(self): 127 127 with self.assertRaises(ValueError): 128 f =source(self.default_test_sound, 0, 0, -1)128 source(self.default_test_sound, 0, 0, -1) 129 129 130 130 def test_wrong_seek(self): … … 138 138 with self.assertRaises(ValueError): 139 139 f.seek(f.duration + f.samplerate * 10) 140 except AssertionError as e:140 except AssertionError: 141 141 self.skipTest('seeking after end of stream failed raising ValueError') 142 142 … … 146 146 total_frames = 0 147 147 while True: 148 vec, read = f.do_multi()148 _, read = f.do_multi() 149 149 total_frames += read 150 150 if read < f.hop_size: break 151 result_str = "read {:.2f}s ({:d} frames in {:d} channels and {:d} blocks at {:d}Hz) from {:s}"152 result_params = total_frames / float(f.samplerate), total_frames, f.channels, int(total_frames/f.hop_size), f.samplerate, f.uri151 #result_str = "read {:.2f}s ({:d} frames in {:d} channels and {:d} blocks at {:d}Hz) from {:s}" 152 #result_params = total_frames / float(f.samplerate), total_frames, f.channels, int(total_frames/f.hop_size), f.samplerate, f.uri 153 153 #print (result_str.format(*result_params)) 154 154 return total_frames 155 155 156 156 if __name__ == '__main__': 157 from nose2 import main158 157 main() -
python/tests/test_specdesc.py
r58a5fb9 r0b6d23d 1 1 #! /usr/bin/env python 2 2 3 from unittest import main 3 4 from numpy.testing import TestCase, assert_equal, assert_almost_equal 4 5 from numpy import random, arange, log, zeros 5 6 from aubio import specdesc, cvec, float_type 6 from math import pi7 7 8 8 methods = ["default", … … 30 30 31 31 for method in methods: 32 o = specdesc(method, buf_size) 33 assert_equal ([o.buf_size, o.method], [buf_size, method]) 34 35 spec = cvec(buf_size) 36 spec.norm[0] = 1 37 spec.norm[1] = 1./2. 38 #print "%20s" % method, str(o(spec)) 39 o(spec) 40 spec.norm = random.random_sample((len(spec.norm),)).astype(float_type) 41 spec.phas = random.random_sample((len(spec.phas),)).astype(float_type) 42 #print "%20s" % method, str(o(spec)) 43 assert (o(spec) != 0.) 44 45 def test_hfc(self): 46 o = specdesc("hfc", buf_size) 47 spec = cvec(buf_size) 48 # hfc of zeros is zero 49 assert_equal (o(spec), 0.) 50 # hfc of ones is sum of all bin numbers 51 spec.norm[:] = 1 52 expected = sum(range(buf_size/2 + 2)) 53 assert_equal (o(spec), expected) 54 # changing phase doesn't change anything 55 spec.phas[:] = 1 56 assert_equal (o(spec), sum(range(buf_size/2 + 2))) 32 o = specdesc(method, buf_size) 33 assert_equal ([o.buf_size, o.method], [buf_size, method]) 34 35 spec = cvec(buf_size) 36 spec.norm[0] = 1 37 spec.norm[1] = 1./2. 38 #print "%20s" % method, str(o(spec)) 39 o(spec) 40 spec.norm = random.random_sample((len(spec.norm),)).astype(float_type) 41 spec.phas = random.random_sample((len(spec.phas),)).astype(float_type) 42 #print "%20s" % method, str(o(spec)) 43 assert (o(spec) != 0.) 57 44 58 45 def test_phase(self): … … 223 210 assert_equal( 0., o(c)) 224 211 a = arange(c.length * 2, 0, -2, dtype=float_type) 225 k = arange(c.length, dtype=float_type)226 212 c.norm = a 227 213 cumsum = .95*sum(a*a) 228 214 i = 0; rollsum = 0 229 215 while rollsum < cumsum: 230 rollsum += a[i]*a[i]231 i+=1216 rollsum += a[i]*a[i] 217 i+=1 232 218 rolloff = i 233 219 assert_equal (rolloff, o(c)) … … 237 223 def test_negative(self): 238 224 with self.assertRaises(ValueError): 239 o =specdesc("default", -10)225 specdesc("default", -10) 240 226 241 227 def test_unknown(self): 242 228 # FIXME should fail? 243 229 with self.assertRaises(ValueError): 244 o =specdesc("unknown", 512)230 specdesc("unknown", 512) 245 231 self.skipTest('todo: new_specdesc should fail on wrong method') 246 232 247 233 if __name__ == '__main__': 248 from unittest import main249 234 main() -
python/tests/test_zero_crossing_rate.py
r58a5fb9 r0b6d23d 1 1 #! /usr/bin/env python 2 2 3 from unittest import main 3 4 from numpy.testing import TestCase 4 5 5 from aubio import fvec, zero_crossing_rate 6 6 … … 44 44 45 45 if __name__ == '__main__': 46 from unittest import main47 46 main() -
python/tests/utils.py
r58a5fb9 r0b6d23d 1 1 #! /usr/bin/env python 2 2 3 import os 4 import glob 5 import numpy as np 6 from tempfile import mkstemp 7 3 8 def array_from_text_file(filename, dtype = 'float'): 4 import os.path5 from numpy import array6 9 filename = os.path.join(os.path.dirname(__file__), filename) 7 10 with open(filename) as f: 8 11 lines = f.readlines() 9 return array([line.split() for line in lines],12 return np.array([line.split() for line in lines], 10 13 dtype = dtype) 11 14 12 15 def list_all_sounds(rel_dir): 13 import os.path, glob14 16 datadir = os.path.join(os.path.dirname(__file__), rel_dir) 15 17 return glob.glob(os.path.join(datadir,'*.*')) … … 23 25 24 26 def get_tmp_sink_path(): 25 from tempfile import mkstemp26 import os27 27 fd, path = mkstemp() 28 28 os.close(fd) … … 30 30 31 31 def del_tmp_sink_path(path): 32 import os33 32 os.unlink(path) 34 33 … … 46 45 total_frames = 0 47 46 while True: 48 samples, read = s()47 _, read = s() 49 48 total_frames += read 50 49 if read < hopsize: break … … 52 51 53 52 def count_samples_in_directory(samples_dir): 54 import os55 53 total_frames = 0 56 54 for f in os.walk(samples_dir): … … 63 61 64 62 def count_files_in_directory(samples_dir): 65 import os66 63 total_files = 0 67 64 for f in os.walk(samples_dir):
Note: See TracChangeset
for help on using the changeset viewer.