Changes in python/tests/test_sink.py [6448d31:b4445fb]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/tests/test_sink.py
r6448d31 rb4445fb 1 1 #! /usr/bin/env python 2 2 3 from nose2 import main4 from nose2.tools import params5 3 from numpy.testing import TestCase 6 4 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 utils import parse_file_samplerate 7 from _tools import parametrize, skipTest, assert_raises, assert_warns 11 8 12 9 list_of_sounds = list_all_sounds('sounds') … … 24 21 all_params.append((hop_size, samplerate, soundfile)) 25 22 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\'') 23 class Test_aubio_sink(object): 31 24 32 25 def test_wrong_filename(self): 33 with self.assertRaises(RuntimeError):26 with assert_raises(RuntimeError): 34 27 sink('') 35 28 36 29 def test_wrong_samplerate(self): 37 with self.assertRaises(RuntimeError):30 with assert_raises(RuntimeError): 38 31 sink(get_tmp_sink_path(), -1) 39 32 40 33 def test_wrong_samplerate_too_large(self): 41 with self.assertRaises(RuntimeError):34 with assert_raises(RuntimeError): 42 35 sink(get_tmp_sink_path(), 1536001, 2) 43 36 44 37 def test_wrong_channels(self): 45 with self.assertRaises(RuntimeError):38 with assert_raises(RuntimeError): 46 39 sink(get_tmp_sink_path(), 44100, -1) 47 40 48 41 def test_wrong_channels_too_large(self): 49 with self.assertRaises(RuntimeError):42 with assert_raises(RuntimeError): 50 43 sink(get_tmp_sink_path(), 44100, 202020) 51 44 … … 67 60 shutil.rmtree(tmpdir) 68 61 69 @param s(*all_params)62 @parametrize('hop_size, samplerate, path', all_params) 70 63 def test_read_and_write(self, hop_size, samplerate, path): 71 64 orig_samplerate = parse_file_samplerate(soundfile) 72 65 try: 73 f = source(path, samplerate, hop_size) 66 if orig_samplerate is not None and orig_samplerate < samplerate: 67 # upsampling should emit a warning 68 with assert_warns(UserWarning): 69 f = source(soundfile, samplerate, hop_size) 70 else: 71 f = source(soundfile, samplerate, hop_size) 74 72 except RuntimeError as e: 75 self.skipTest('failed opening with hop_s = {:d}, samplerate = {:d} ({:s})'.format(hop_size, samplerate, str(e))) 73 err_msg = '{:s} (hop_s = {:d}, samplerate = {:d})' 74 skipTest(err_msg.format(str(e), hop_size, samplerate)) 76 75 if samplerate == 0: samplerate = f.samplerate 77 76 sink_path = get_tmp_sink_path() … … 85 84 del_tmp_sink_path(sink_path) 86 85 87 @param s(*all_params)86 @parametrize('hop_size, samplerate, path', all_params) 88 87 def test_read_and_write_multi(self, hop_size, samplerate, path): 88 orig_samplerate = parse_file_samplerate(soundfile) 89 89 try: 90 f = source(path, samplerate, hop_size) 90 if orig_samplerate is not None and orig_samplerate < samplerate: 91 # upsampling should emit a warning 92 with assert_warns(UserWarning): 93 f = source(soundfile, samplerate, hop_size) 94 else: 95 f = source(soundfile, samplerate, hop_size) 91 96 except RuntimeError as e: 92 self.skipTest('failed opening with hop_s = {:d}, samplerate = {:d} ({:s})'.format(hop_size, samplerate, str(e))) 97 err_msg = '{:s} (hop_s = {:d}, samplerate = {:d})' 98 skipTest(err_msg.format(str(e), hop_size, samplerate)) 93 99 if samplerate == 0: samplerate = f.samplerate 94 100 sink_path = get_tmp_sink_path() … … 126 132 127 133 if __name__ == '__main__': 128 main() 134 from _tools import run_module_suite 135 run_module_suite()
Note: See TracChangeset
for help on using the changeset viewer.