source: python/tests/test_sink.py @ bafa767

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

python/tests/test_{source,sink}.py: add close() tests

  • Property mode set to 100755
File size: 1.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
6from utils import list_all_sounds
7
8list_of_sounds = list_all_sounds('sounds')
9path = None
10
11class aubio_sink_test_case(TestCase):
12
13    def setUp(self):
14        if not len(list_of_sounds): self.skipTest('add some sound files in \'python/tests/sounds\'')
15
[9e6695d]16    def test_many_sinks(self):
17        for i in range(100):
18            g = sink('/tmp/f.wav', 0)
19            write = 256
20            for n in range(200):
21                vec = fvec(write)
22                g(vec, write)
23            del g
24
[e1bfde5]25    def test_read(self):
26        for path in list_of_sounds:
27            for samplerate, hop_size in zip([0, 44100, 8000, 32000], [512, 1024, 64, 256]):
28                f = source(path, samplerate, hop_size)
29                if samplerate == 0: samplerate = f.samplerate
30                g = sink('/tmp/f.wav', samplerate)
31                total_frames = 0
32                while True:
33                    vec, read = f()
[db1eab7]34                    g(vec, read)
[e1bfde5]35                    total_frames += read
36                    if read < f.hop_size: break
37                print "read", "%.2fs" % (total_frames / float(f.samplerate) ),
38                print "(", total_frames, "frames", "in",
39                print total_frames / f.hop_size, "blocks", "at", "%dHz" % f.samplerate, ")",
40                print "from", f.uri,
41                print "to", g.uri
[9e6695d]42                #del f, g
[e1bfde5]43
[4949182]44    def test_close_file(self):
45        samplerate = 44100
46        g = sink('/tmp/f.wav', samplerate)
47        g.close()
48
49    def test_close_file_twice(self):
50        samplerate = 44100
51        g = sink('/tmp/f.wav', samplerate)
52        g.close()
53        g.close()
54
[e1bfde5]55if __name__ == '__main__':
[9e6695d]56    from unittest import main
57    main()
Note: See TracBrowser for help on using the repository browser.