source: python/tests/test_sink.py @ 0229e51

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since 0229e51 was 0229e51, checked in by Paul Brossier <piem@piem.org>, 8 years ago

python/tests/test_sink.py: remove useless many_sinks_not_closed and more cruft

  • Property mode set to 100755
File size: 2.8 KB
RevLine 
[e1bfde5]1#! /usr/bin/env python
2
3from numpy.testing import TestCase, assert_equal, assert_almost_equal
4from aubio import fvec, source, sink
5from numpy import array
[ab35262]6from utils import list_all_sounds, get_tmp_sink_path, del_tmp_sink_path
[e1bfde5]7
8list_of_sounds = list_all_sounds('sounds')
9path = None
10
[ab35262]11many_files = 300 # 256 opened files is too much
12
[e1bfde5]13class aubio_sink_test_case(TestCase):
14
[9e6695d]15    def test_many_sinks(self):
[ab35262]16        from tempfile import mkdtemp
17        import os.path
18        import shutil
19        tmpdir = mkdtemp()
20        sink_list = []
21        for i in range(many_files):
22            path = os.path.join(tmpdir, 'f-' + str(i) + '.wav')
23            g = sink(path, 0)
24            sink_list.append(g)
25            write = 32
[9e6695d]26            for n in range(200):
27                vec = fvec(write)
28                g(vec, write)
[ab35262]29            g.close()
30        shutil.rmtree(tmpdir)
31
[4a1378c]32    def test_read_and_write(self):
33
34        if not len(list_of_sounds):
35            self.skipTest('add some sound files in \'python/tests/sounds\'')
36
[e1bfde5]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
[ab35262]41                sink_path = get_tmp_sink_path()
42                g = sink(sink_path, samplerate)
[e1bfde5]43                total_frames = 0
44                while True:
45                    vec, read = f()
[db1eab7]46                    g(vec, read)
[e1bfde5]47                    total_frames += read
48                    if read < f.hop_size: break
[ab35262]49                del_tmp_sink_path(sink_path)
[e1bfde5]50
[060a3135]51    def test_read_and_write_multi(self):
52
53        if not len(list_of_sounds):
54            self.skipTest('add some sound files in \'python/tests/sounds\'')
55
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)
62                total_frames = 0
63                while True:
64                    vec, read = f.do_multi()
65                    g.do_multi(vec, read)
66                    total_frames += read
67                    if read < f.hop_size: break
68                del_tmp_sink_path(sink_path)
69
[4949182]70    def test_close_file(self):
71        samplerate = 44100
[ab35262]72        sink_path = get_tmp_sink_path()
73        g = sink(sink_path, samplerate)
[4949182]74        g.close()
[ab35262]75        del_tmp_sink_path(sink_path)
[4949182]76
77    def test_close_file_twice(self):
78        samplerate = 44100
[ab35262]79        sink_path = get_tmp_sink_path()
80        g = sink(sink_path, samplerate)
[4949182]81        g.close()
82        g.close()
[ab35262]83        del_tmp_sink_path(sink_path)
[4949182]84
[e1bfde5]85if __name__ == '__main__':
[9e6695d]86    from unittest import main
87    main()
Note: See TracBrowser for help on using the repository browser.