History

python/tests/test_sink.py: switch to nose2

Paul Brossier committed 10 years ago

Commit 2fe24df1 parent 797435f1 file · +47 −36Browse files

Showing the changes to python (1 of 1 file). Show all

Unified · Split

python/tests/test_sink.py+47−36
@@ -1,17 +1,31 @@
1#! /usr/bin/env python1#! /usr/bin/env python
2 2
3from numpy.testing import TestCase, assert_equal, assert_almost_equal3from numpy.testing import TestCase, assert_equal, assert_almost_equal
4from nose2.tools import params
4from aubio import fvec, source, sink5from aubio import fvec, source, sink
5from numpy import array6from numpy import array
6from utils import list_all_sounds, get_tmp_sink_path, del_tmp_sink_path7from utils import list_all_sounds, get_tmp_sink_path, del_tmp_sink_path
7 8
8list_of_sounds = list_all_sounds('sounds')9list_of_sounds = list_all_sounds('sounds')
10samplerates = [0, 44100, 8000, 32000]
11hop_sizes = [512, 1024, 64]
12
9path = None13path = None
10 14
11many_files = 300 # 256 opened files is too much15many_files = 300 # 256 opened files is too much
12 16
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
13class aubio_sink_test_case(TestCase):23class aubio_sink_test_case(TestCase):
14 24
25 def setUp(self):
26 if not len(list_of_sounds):
27 self.skipTest('add some sound files in \'python/tests/sounds\'')
28
15 def test_many_sinks(self):29 def test_many_sinks(self):
16 from tempfile import mkdtemp30 from tempfile import mkdtemp
17 import os.path31 import os.path
@@ -29,43 +43,40 @@ class aubio_sink_test_case(TestCase): · 11 unmodified lines
29 g.close()43 g.close()
30 shutil.rmtree(tmpdir)44 shutil.rmtree(tmpdir)
31 45
32 def test_read_and_write(self):46 @params(*all_params)
33 47 def test_read_and_write(self, hop_size, samplerate, path):
34 if not len(list_of_sounds):
35 self.skipTest('add some sound files in \'python/tests/sounds\'')
36
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)
43 total_frames = 0
44 while True:
45 vec, read = f()
46 g(vec, read)
47 total_frames += read
48 if read < f.hop_size: break
49 del_tmp_sink_path(sink_path)
50 48
51 def test_read_and_write_multi(self):49 try:
52 50 f = source(path, samplerate, hop_size)
53 if not len(list_of_sounds):51 except RuntimeError as e:
54 self.skipTest('add some sound files in \'python/tests/sounds\'')52 self.skipTest('failed opening with hop_s = {:d}, samplerate = {:d} ({:s})'.format(hop_size, samplerate, e))
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)
55 63
56 for path in list_of_sounds:64 @params(*all_params)
57 for samplerate, hop_size in zip([0, 44100, 8000, 32000], [512, 1024, 64, 256]):65 def test_read_and_write_multi(self, hop_size, samplerate, path):
58 f = source(path, samplerate, hop_size)66 try:
59 if samplerate == 0: samplerate = f.samplerate67 f = source(path, samplerate, hop_size)
60 sink_path = get_tmp_sink_path()68 except RuntimeError as e:
61 g = sink(sink_path, samplerate, channels = f.channels)69 self.skipTest('failed opening with hop_s = {:d}, samplerate = {:d} ({:s})'.format(hop_size, samplerate, e))
62 total_frames = 070 if samplerate == 0: samplerate = f.samplerate
63 while True:71 sink_path = get_tmp_sink_path()
64 vec, read = f.do_multi()72 g = sink(sink_path, samplerate, channels = f.channels)
65 g.do_multi(vec, read)73 total_frames = 0
66 total_frames += read74 while True:
67 if read < f.hop_size: break75 vec, read = f.do_multi()
68 del_tmp_sink_path(sink_path)76 g.do_multi(vec, read)
77 total_frames += read
78 if read < f.hop_size: break
79 del_tmp_sink_path(sink_path)
69 80
70 def test_close_file(self):81 def test_close_file(self):
71 samplerate = 4410082 samplerate = 44100
@@ -83,5 +94,5 @@ class aubio_sink_test_case(TestCase): · 11 unmodified lines
83 del_tmp_sink_path(sink_path)94 del_tmp_sink_path(sink_path)
84 95
85if __name__ == '__main__':96if __name__ == '__main__':
86 from unittest import main97 from nose2 import main
87 main()98 main()

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t