3 from numpy.testing import TestCase, assert_equal, assert_almost_equal
4 from aubio import fvec, source, sink
5 from numpy import array
6 from utils import list_all_sounds, get_tmp_sink_path, del_tmp_sink_path
8 list_of_sounds = list_all_sounds('sounds')
11 many_files = 300 # 256 opened files is too much
13 class aubio_sink_test_case(TestCase):
15 def test_many_sinks(self):
16 from tempfile import mkdtemp
21 for i in range(many_files):
22 path = os.path.join(tmpdir, 'f-' + str(i) + '.wav')
32 def test_read_and_write(self):
34 if not len(list_of_sounds):
35 self.skipTest('add some sound files in \'python/tests/sounds\'')
37 for path in list_of_sounds:
38 for samplerate, hop_size in zip([0, 44100, 8000, 32000], [512, 1024, 64, 256]):
39 f = source(path, samplerate, hop_size)
40 if samplerate == 0: samplerate = f.samplerate
41 sink_path = get_tmp_sink_path()
42 g = sink(sink_path, samplerate)
48 if read < f.hop_size: break
49 del_tmp_sink_path(sink_path)
51 def test_read_and_write_multi(self):
53 if not len(list_of_sounds):
54 self.skipTest('add some sound files in \'python/tests/sounds\'')
56 for path in list_of_sounds:
57 for samplerate, hop_size in zip([0, 44100, 8000, 32000], [512, 1024, 64, 256]):
58 f = source(path, samplerate, hop_size)
59 if samplerate == 0: samplerate = f.samplerate
60 sink_path = get_tmp_sink_path()
61 g = sink(sink_path, samplerate, channels = f.channels)
64 vec, read = f.do_multi()
67 if read < f.hop_size: break
68 del_tmp_sink_path(sink_path)
70 def test_close_file(self):
72 sink_path = get_tmp_sink_path()
73 g = sink(sink_path, samplerate)
75 del_tmp_sink_path(sink_path)
77 def test_close_file_twice(self):
79 sink_path = get_tmp_sink_path()
80 g = sink(sink_path, samplerate)
83 del_tmp_sink_path(sink_path)
85 if __name__ == '__main__':
86 from unittest import main