Changeset 41b985f for python/tests
- Timestamp:
- Mar 12, 2017, 11:26:24 AM (8 years ago)
- Branches:
- sampler
- Children:
- bde49c4a
- Parents:
- 71f2e5f (diff), 67b6618 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- python/tests
- Files:
-
- 2 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
python/tests/eval_pitch
r71f2e5f r41b985f 25 25 import os.path 26 26 import numpy 27 from utils import array_from_text_file, array_from_yaml_file27 from .utils import array_from_text_file, array_from_yaml_file 28 28 from aubio import source, pitch, freqtomidi 29 29 -
python/tests/test_aubio.py
r71f2e5f r41b985f 10 10 import aubio 11 11 12 def test_version(self): 13 """ test aubio.version """ 14 import aubio 15 self.assertEqual('0', aubio.version[0]) 16 12 17 if __name__ == '__main__': 13 18 main() -
python/tests/test_fft.py
r71f2e5f r41b985f 34 34 fftgrain = f (timegrain) 35 35 assert_equal ( fftgrain.norm, 0 ) 36 assert_equal ( fftgrain.phas, 0 ) 36 try: 37 assert_equal ( fftgrain.phas, 0 ) 38 except AssertionError: 39 assert_equal (fftgrain.phas[fftgrain.phas > 0], +pi) 40 assert_equal (fftgrain.phas[fftgrain.phas < 0], -pi) 41 assert_equal (np.abs(fftgrain.phas[np.abs(fftgrain.phas) != pi]), 0) 42 self.skipTest('fft(fvec(%d)).phas != +0, ' % win_s \ 43 + 'This is expected when using fftw3 on powerpc.') 37 44 38 45 def test_impulse(self): -
python/tests/test_filter.py
r71f2e5f r41b985f 4 4 from numpy.testing import TestCase, assert_equal, assert_almost_equal 5 5 from aubio import fvec, digital_filter 6 from utils import array_from_text_file6 from .utils import array_from_text_file 7 7 8 8 class aubio_filter_test_case(TestCase): -
python/tests/test_filterbank.py
r71f2e5f r41b985f 6 6 import numpy as np 7 7 from aubio import cvec, filterbank, float_type 8 from utils import array_from_text_file8 from .utils import array_from_text_file 9 9 10 10 class aubio_filterbank_test_case(TestCase): -
python/tests/test_midi2note.py
r71f2e5f r41b985f 3 3 4 4 from aubio import midi2note 5 from nose2.tools import params 5 6 import unittest 6 7 … … 17 18 class midi2note_good_values(unittest.TestCase): 18 19 19 def test_midi2note_known_values(self): 20 @params(*list_of_known_midis) 21 def test_midi2note_known_values(self, midi, note): 20 22 " known values are correctly converted " 21 for midi, note in list_of_known_midis: 22 self.assertEqual ( midi2note(midi), note ) 23 self.assertEqual ( midi2note(midi), note ) 23 24 24 25 class midi2note_wrong_values(unittest.TestCase): … … 41 42 42 43 if __name__ == '__main__': 43 unittest.main() 44 import nose2 45 nose2.main() -
python/tests/test_note2midi.py
r71f2e5f r41b985f 5 5 6 6 from aubio import note2midi, freq2note 7 from nose2.tools import params 7 8 import unittest 8 9 … … 14 15 ( 'B3', 59 ), 15 16 ( 'B#3', 60 ), 17 ( 'C♯4', 61 ), 16 18 ( 'A4', 69 ), 17 19 ( 'A#4', 70 ), 20 ( 'A♯4', 70 ), 21 ( 'A\u266f4', 70 ), 18 22 ( 'Bb4', 70 ), 19 23 ( 'B♭4', 70 ), 24 ( 'B\u266d4', 70 ), 20 25 ( 'G8', 115 ), 21 26 ( 'G♯8', 116 ), 22 27 ( 'G9', 127 ), 23 ( 'G\udd2a2', 45 ),24 ( 'B\ufffd2', 45 ),25 28 ( 'A♮2', 45 ), 29 ) 30 31 list_of_known_notes_with_unicode_issues = ( 32 ('C𝄪4', 62 ), 33 ('E𝄫4', 62 ), 34 ) 35 36 list_of_unknown_notes = ( 37 ( 'G\udd2a2' ), 38 ( 'B\ufffd2' ), 39 ( 'B\u266e\u266e2' ), 40 ( 'B\u266f\u266d3' ), 41 ( 'B33' ), 42 ( 'C.3' ), 43 ( 'A' ), 44 ( '2' ), 26 45 ) 27 46 28 47 class note2midi_good_values(unittest.TestCase): 29 48 30 def test_note2midi_known_values(self): 49 @params(*list_of_known_notes) 50 def test_note2midi_known_values(self, note, midi): 31 51 " known values are correctly converted " 32 for note, midi in list_of_known_notes: 52 self.assertEqual ( note2midi(note), midi ) 53 54 @params(*list_of_known_notes_with_unicode_issues) 55 def test_note2midi_known_values_with_unicode_issues(self, note, midi): 56 " known values are correctly converted, unless decoding is expected to fail" 57 try: 33 58 self.assertEqual ( note2midi(note), midi ) 59 except UnicodeEncodeError as e: 60 import sys 61 strfmt = "len(u'\\U0001D12A') != 1, excpected decoding failure | {:s} | {:s} {:s}" 62 strres = strfmt.format(e, sys.platform, sys.version) 63 # happens with: darwin 2.7.10, windows 2.7.12 64 if len('\U0001D12A') != 1 and sys.version[0] == '2': 65 self.skipTest(strres + " | upgrade to Python 3 to fix") 66 else: 67 raise 34 68 35 69 class note2midi_wrong_values(unittest.TestCase): … … 67 101 self.assertRaises(TypeError, note2midi, 123) 68 102 103 def test_note2midi_wrong_data_too_long(self): 104 " fails when passed a note with a note name longer than expected" 105 self.assertRaises(ValueError, note2midi, 'CB+-3') 106 107 @params(*list_of_unknown_notes) 108 def test_note2midi_unknown_values(self, note): 109 " unknown values throw out an error " 110 self.assertRaises(ValueError, note2midi, note) 69 111 70 112 class freq2note_simple_test(unittest.TestCase): … … 75 117 76 118 if __name__ == '__main__': 77 unittest.main() 119 import nose2 120 nose2.main() -
python/tests/test_phasevoc.py
r71f2e5f r41b985f 47 47 assert_equal ( t, 0.) 48 48 assert_equal ( s.norm, 0.) 49 assert_equal ( s.phas, 0.) 49 try: 50 assert_equal ( s.phas, 0 ) 51 except AssertionError: 52 assert_equal (s.phas[s.phas > 0], +np.pi) 53 assert_equal (s.phas[s.phas < 0], -np.pi) 54 assert_equal (np.abs(s.phas[np.abs(s.phas) != np.pi]), 0) 55 self.skipTest('pvoc(fvec(%d)).phas != +0, ' % win_s \ 56 + 'This is expected when using fftw3 on powerpc.') 50 57 assert_equal ( r, 0.) 51 58 -
python/tests/test_sink.py
r71f2e5f r41b985f 5 5 from numpy.testing import TestCase 6 6 from aubio import fvec, source, sink 7 from utils import list_all_sounds, get_tmp_sink_path, del_tmp_sink_path 7 from .utils import list_all_sounds, get_tmp_sink_path, del_tmp_sink_path 8 9 import warnings 10 warnings.filterwarnings('ignore', category=UserWarning, append=True) 8 11 9 12 list_of_sounds = list_all_sounds('sounds') … … 26 29 if not len(list_of_sounds): 27 30 self.skipTest('add some sound files in \'python/tests/sounds\'') 31 32 def test_wrong_filename(self): 33 with self.assertRaises(RuntimeError): 34 sink('') 35 36 def test_wrong_samplerate(self): 37 with self.assertRaises(RuntimeError): 38 sink(get_tmp_sink_path(), -1) 39 40 def test_wrong_samplerate_too_large(self): 41 with self.assertRaises(RuntimeError): 42 sink(get_tmp_sink_path(), 1536001, 2) 43 44 def test_wrong_channels(self): 45 with self.assertRaises(RuntimeError): 46 sink(get_tmp_sink_path(), 44100, -1) 47 48 def test_wrong_channels_too_large(self): 49 with self.assertRaises(RuntimeError): 50 sink(get_tmp_sink_path(), 44100, 202020) 28 51 29 52 def test_many_sinks(self): … … 94 117 del_tmp_sink_path(sink_path) 95 118 119 def test_read_with(self): 120 sink_path =get_tmp_sink_path() 121 vec = fvec(128) 122 with sink(sink_path, samplerate) as g: 123 for i in range(10): 124 g(vec, 128) 125 96 126 if __name__ == '__main__': 97 127 main() -
python/tests/test_slicing.py
r71f2e5f r41b985f 4 4 from numpy.testing import TestCase, assert_equal 5 5 from aubio import slice_source_at_stamps 6 from utils import count_files_in_directory, get_default_test_sound7 from utils import count_samples_in_directory, count_samples_in_file6 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 -
python/tests/test_source.py
r71f2e5f r41b985f 5 5 from numpy.testing import TestCase, assert_equal 6 6 from aubio import source 7 from utils import list_all_sounds7 from .utils import list_all_sounds 8 8 import numpy as np 9 9 … … 57 57 if read < f.hop_size: 58 58 assert_equal(samples[read:], 0) 59 if 'brownnoise' in f.uri:60 self.assertEquals(np.count_nonzero(samples[:read]), read)61 59 break 62 60 #result_str = "read {:.2f}s ({:d} frames in {:d} blocks at {:d}Hz) from {:s}" … … 72 70 self.skipTest('failed opening with hop_s = {:d}, samplerate = {:d} ({:s})'.format(hop_size, samplerate, str(e))) 73 71 assert f.samplerate != 0 74 self.read_from_source(f) 72 read_frames = self.read_from_source(f) 73 if 'f_' in soundfile and samplerate == 0: 74 import re 75 f = re.compile('.*_\([0:9]*f\)_.*') 76 match_f = re.findall('([0-9]*)f_', soundfile) 77 if len(match_f) == 1: 78 expected_frames = int(match_f[0]) 79 self.assertEqual(expected_frames, read_frames) 75 80 76 81 @params(*list_of_sounds) … … 159 164 if read < f.hop_size: 160 165 assert_equal(samples[:,read:], 0) 161 if 'brownnoise' in f.uri:162 self.assertEquals(np.count_nonzero(samples[:,:read]), read)163 166 break 164 167 #result_str = "read {:.2f}s ({:d} frames in {:d} channels and {:d} blocks at {:d}Hz) from {:s}" … … 167 170 return total_frames 168 171 172 class aubio_source_with(aubio_source_test_case_base): 173 174 #@params(*list_of_sounds) 175 @params(*list_of_sounds) 176 def test_read_from_mono(self, filename): 177 total_frames = 0 178 hop_size = 2048 179 with source(filename, 0, hop_size) as input_source: 180 assert_equal(input_source.hop_size, hop_size) 181 #assert_equal(input_source.samplerate, samplerate) 182 total_frames = 0 183 for frames in input_source: 184 total_frames += frames.shape[-1] 185 # check we read as many samples as we expected 186 assert_equal(total_frames, input_source.duration) 187 169 188 if __name__ == '__main__': 170 189 main()
Note: See TracChangeset
for help on using the changeset viewer.