source: python/tests/test_sink.py @ 25d0c42

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

python/tests: fix most prospect warnings

  • Property mode set to 100755
File size: 3.0 KB
RevLine 
[e1bfde5]1#! /usr/bin/env python
2
[0b6d23d]3from nose2 import main
[2fe24df]4from nose2.tools import params
[0b6d23d]5from numpy.testing import TestCase
[e1bfde5]6from aubio import fvec, source, sink
[ab35262]7from utils import list_all_sounds, get_tmp_sink_path, del_tmp_sink_path
[e1bfde5]8
9list_of_sounds = list_all_sounds('sounds')
[2fe24df]10samplerates = [0, 44100, 8000, 32000]
11hop_sizes = [512, 1024, 64]
12
[e1bfde5]13path = None
14
[ab35262]15many_files = 300 # 256 opened files is too much
16
[2fe24df]17all_params = []
18for soundfile in list_of_sounds:
19    for hop_size in hop_sizes:
20        for samplerate in samplerates:
21            all_params.append((hop_size, samplerate, soundfile))
22
[e1bfde5]23class aubio_sink_test_case(TestCase):
24
[2fe24df]25    def setUp(self):
26        if not len(list_of_sounds):
27            self.skipTest('add some sound files in \'python/tests/sounds\'')
28
[9e6695d]29    def test_many_sinks(self):
[ab35262]30        from tempfile import mkdtemp
31        import os.path
32        import shutil
33        tmpdir = mkdtemp()
34        sink_list = []
35        for i in range(many_files):
36            path = os.path.join(tmpdir, 'f-' + str(i) + '.wav')
37            g = sink(path, 0)
38            sink_list.append(g)
39            write = 32
[0b6d23d]40            for _ in range(200):
[9e6695d]41                vec = fvec(write)
42                g(vec, write)
[ab35262]43            g.close()
44        shutil.rmtree(tmpdir)
45
[2fe24df]46    @params(*all_params)
47    def test_read_and_write(self, hop_size, samplerate, path):
[e1bfde5]48
[2fe24df]49        try:
50            f = source(path, samplerate, hop_size)
51        except RuntimeError as e:
[5de7f98]52            self.skipTest('failed opening with hop_s = {:d}, samplerate = {:d} ({:s})'.format(hop_size, samplerate, str(e)))
[2fe24df]53        if samplerate == 0: samplerate = f.samplerate
54        sink_path = get_tmp_sink_path()
55        g = sink(sink_path, samplerate)
56        total_frames = 0
57        while True:
58            vec, read = f()
59            g(vec, read)
60            total_frames += read
61            if read < f.hop_size: break
62        del_tmp_sink_path(sink_path)
[060a3135]63
[2fe24df]64    @params(*all_params)
65    def test_read_and_write_multi(self, hop_size, samplerate, path):
66        try:
67            f = source(path, samplerate, hop_size)
68        except RuntimeError as e:
[5de7f98]69            self.skipTest('failed opening with hop_s = {:d}, samplerate = {:d} ({:s})'.format(hop_size, samplerate, str(e)))
[2fe24df]70        if samplerate == 0: samplerate = f.samplerate
71        sink_path = get_tmp_sink_path()
72        g = sink(sink_path, samplerate, channels = f.channels)
73        total_frames = 0
74        while True:
75            vec, read = f.do_multi()
76            g.do_multi(vec, read)
77            total_frames += read
78            if read < f.hop_size: break
79        del_tmp_sink_path(sink_path)
[060a3135]80
[4949182]81    def test_close_file(self):
82        samplerate = 44100
[ab35262]83        sink_path = get_tmp_sink_path()
84        g = sink(sink_path, samplerate)
[4949182]85        g.close()
[ab35262]86        del_tmp_sink_path(sink_path)
[4949182]87
88    def test_close_file_twice(self):
89        samplerate = 44100
[ab35262]90        sink_path = get_tmp_sink_path()
91        g = sink(sink_path, samplerate)
[4949182]92        g.close()
93        g.close()
[ab35262]94        del_tmp_sink_path(sink_path)
[4949182]95
[e1bfde5]96if __name__ == '__main__':
[9e6695d]97    main()
Note: See TracBrowser for help on using the repository browser.