History

[tests] update sink tests

Paul Brossier committed 8 years ago

Commit ecd370b1 parent d4fae341 file · +16 −22Browse files

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

Unified · Split

python/tests/test_sink.py+16−22
@@ -1,13 +1,9 @@
11 #! /usr/bin/env python
22
3−from nose2 import main
4−from nose2.tools import params
53 from numpy.testing import TestCase
64 from aubio import fvec, source, sink
7−from .utils import list_all_sounds, get_tmp_sink_path, del_tmp_sink_path
8−
9−import warnings
10−warnings.filterwarnings('ignore', category=UserWarning, append=True)
5+from utils import list_all_sounds, get_tmp_sink_path, del_tmp_sink_path
6+from _tools import parametrize, skipTest, assert_raises
117
128 list_of_sounds = list_all_sounds('sounds')
139 samplerates = [0, 44100, 8000, 32000]
@@ -23,30 +19,26 @@ for soundfile in list_of_sounds: · 9 unmodified lines
2319 for samplerate in samplerates:
2420 all_params.append((hop_size, samplerate, soundfile))
2521
26−class aubio_sink_test_case(TestCase):
27−
28− def setUp(self):
29− if not len(list_of_sounds):
30− self.skipTest('add some sound files in \'python/tests/sounds\'')
22+class Test_aubio_sink:
3123
3224 def test_wrong_filename(self):
33− with self.assertRaises(RuntimeError):
25+ with assert_raises(RuntimeError):
3426 sink('')
3527
3628 def test_wrong_samplerate(self):
37− with self.assertRaises(RuntimeError):
29+ with assert_raises(RuntimeError):
3830 sink(get_tmp_sink_path(), -1)
3931
4032 def test_wrong_samplerate_too_large(self):
41− with self.assertRaises(RuntimeError):
33+ with assert_raises(RuntimeError):
4234 sink(get_tmp_sink_path(), 1536001, 2)
4335
4436 def test_wrong_channels(self):
45− with self.assertRaises(RuntimeError):
37+ with assert_raises(RuntimeError):
4638 sink(get_tmp_sink_path(), 44100, -1)
4739
4840 def test_wrong_channels_too_large(self):
49− with self.assertRaises(RuntimeError):
41+ with assert_raises(RuntimeError):
5042 sink(get_tmp_sink_path(), 44100, 202020)
5143
5244 def test_many_sinks(self):
@@ -66,13 +58,13 @@ class aubio_sink_test_case(TestCase): · 13 unmodified lines
6658 g.close()
6759 shutil.rmtree(tmpdir)
6860
69− @params(*all_params)
61+ @parametrize('hop_size, samplerate, path', all_params)
7062 def test_read_and_write(self, hop_size, samplerate, path):
71−
7263 try:
7364 f = source(path, samplerate, hop_size)
7465 except RuntimeError as e:
75− self.skipTest('failed opening with hop_s = {:d}, samplerate = {:d} ({:s})'.format(hop_size, samplerate, str(e)))
66+ err_msg = '{:s} (hop_s = {:d}, samplerate = {:d})'
67+ skipTest(err_msg.format(str(e), hop_size, samplerate))
7668 if samplerate == 0: samplerate = f.samplerate
7769 sink_path = get_tmp_sink_path()
7870 g = sink(sink_path, samplerate)
@@ -84,12 +76,13 @@ class aubio_sink_test_case(TestCase): · 5 unmodified lines
8476 if read < f.hop_size: break
8577 del_tmp_sink_path(sink_path)
8678
87− @params(*all_params)
79+ @parametrize('hop_size, samplerate, path', all_params)
8880 def test_read_and_write_multi(self, hop_size, samplerate, path):
8981 try:
9082 f = source(path, samplerate, hop_size)
9183 except RuntimeError as e:
92− self.skipTest('failed opening with hop_s = {:d}, samplerate = {:d} ({:s})'.format(hop_size, samplerate, str(e)))
84+ err_msg = '{:s} (hop_s = {:d}, samplerate = {:d})'
85+ skipTest(err_msg.format(str(e), hop_size, samplerate))
9386 if samplerate == 0: samplerate = f.samplerate
9487 sink_path = get_tmp_sink_path()
9588 g = sink(sink_path, samplerate, channels = f.channels)
@@ -125,4 +118,5 @@ class aubio_sink_test_case(TestCase): · 29 unmodified lines
125118 g(vec, 128)
126119
127120 if __name__ == '__main__':
128− main()
121+ import pytest, sys
122+ pytest.main(sys.argv)

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