Showing the changes to python (1 of 1 file). Show all
Unified · Split
| @@ -1,13 +1,9 @@ | |||
| 1 | #! /usr/bin/env python | 1 | #! /usr/bin/env python |
| 2 | 2 | ||
| 3 | from nose2 import main | ||
| 4 | from nose2.tools import params | ||
| 5 | from numpy.testing import TestCase | 3 | from numpy.testing import TestCase |
| 6 | from aubio import fvec, source, sink | 4 | from aubio import fvec, source, sink |
| 7 | from .utils import list_all_sounds, get_tmp_sink_path, del_tmp_sink_path | 5 | from utils import list_all_sounds, get_tmp_sink_path, del_tmp_sink_path |
| 8 | 6 | from _tools import parametrize, skipTest, assert_raises | |
| 9 | import warnings | ||
| 10 | warnings.filterwarnings('ignore', category=UserWarning, append=True) | ||
| 11 | 7 | ||
| 12 | list_of_sounds = list_all_sounds('sounds') | 8 | list_of_sounds = list_all_sounds('sounds') |
| 13 | samplerates = [0, 44100, 8000, 32000] | 9 | samplerates = [0, 44100, 8000, 32000] |
| @@ -23,30 +19,26 @@ for soundfile in list_of_sounds: · 9 unmodified lines | |||
| 23 | for samplerate in samplerates: | 19 | for samplerate in samplerates: |
| 24 | all_params.append((hop_size, samplerate, soundfile)) | 20 | all_params.append((hop_size, samplerate, soundfile)) |
| 25 | 21 | ||
| 26 | class aubio_sink_test_case(TestCase): | 22 | class Test_aubio_sink: |
| 27 | |||
| 28 | def setUp(self): | ||
| 29 | if not len(list_of_sounds): | ||
| 30 | self.skipTest('add some sound files in \'python/tests/sounds\'') | ||
| 31 | 23 | ||
| 32 | def test_wrong_filename(self): | 24 | def test_wrong_filename(self): |
| 33 | with self.assertRaises(RuntimeError): | 25 | with assert_raises(RuntimeError): |
| 34 | sink('') | 26 | sink('') |
| 35 | 27 | ||
| 36 | def test_wrong_samplerate(self): | 28 | def test_wrong_samplerate(self): |
| 37 | with self.assertRaises(RuntimeError): | 29 | with assert_raises(RuntimeError): |
| 38 | sink(get_tmp_sink_path(), -1) | 30 | sink(get_tmp_sink_path(), -1) |
| 39 | 31 | ||
| 40 | def test_wrong_samplerate_too_large(self): | 32 | def test_wrong_samplerate_too_large(self): |
| 41 | with self.assertRaises(RuntimeError): | 33 | with assert_raises(RuntimeError): |
| 42 | sink(get_tmp_sink_path(), 1536001, 2) | 34 | sink(get_tmp_sink_path(), 1536001, 2) |
| 43 | 35 | ||
| 44 | def test_wrong_channels(self): | 36 | def test_wrong_channels(self): |
| 45 | with self.assertRaises(RuntimeError): | 37 | with assert_raises(RuntimeError): |
| 46 | sink(get_tmp_sink_path(), 44100, -1) | 38 | sink(get_tmp_sink_path(), 44100, -1) |
| 47 | 39 | ||
| 48 | def test_wrong_channels_too_large(self): | 40 | def test_wrong_channels_too_large(self): |
| 49 | with self.assertRaises(RuntimeError): | 41 | with assert_raises(RuntimeError): |
| 50 | sink(get_tmp_sink_path(), 44100, 202020) | 42 | sink(get_tmp_sink_path(), 44100, 202020) |
| 51 | 43 | ||
| 52 | def test_many_sinks(self): | 44 | def test_many_sinks(self): |
| @@ -66,13 +58,13 @@ class aubio_sink_test_case(TestCase): · 13 unmodified lines | |||
| 66 | g.close() | 58 | g.close() |
| 67 | shutil.rmtree(tmpdir) | 59 | shutil.rmtree(tmpdir) |
| 68 | 60 | ||
| 69 | @params(*all_params) | 61 | @parametrize('hop_size, samplerate, path', all_params) |
| 70 | def test_read_and_write(self, hop_size, samplerate, path): | 62 | def test_read_and_write(self, hop_size, samplerate, path): |
| 71 | |||
| 72 | try: | 63 | try: |
| 73 | f = source(path, samplerate, hop_size) | 64 | f = source(path, samplerate, hop_size) |
| 74 | except RuntimeError as e: | 65 | 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)) | ||
| 76 | if samplerate == 0: samplerate = f.samplerate | 68 | if samplerate == 0: samplerate = f.samplerate |
| 77 | sink_path = get_tmp_sink_path() | 69 | sink_path = get_tmp_sink_path() |
| 78 | g = sink(sink_path, samplerate) | 70 | g = sink(sink_path, samplerate) |
| @@ -84,12 +76,13 @@ class aubio_sink_test_case(TestCase): · 5 unmodified lines | |||
| 84 | if read < f.hop_size: break | 76 | if read < f.hop_size: break |
| 85 | del_tmp_sink_path(sink_path) | 77 | del_tmp_sink_path(sink_path) |
| 86 | 78 | ||
| 87 | @params(*all_params) | 79 | @parametrize('hop_size, samplerate, path', all_params) |
| 88 | def test_read_and_write_multi(self, hop_size, samplerate, path): | 80 | def test_read_and_write_multi(self, hop_size, samplerate, path): |
| 89 | try: | 81 | try: |
| 90 | f = source(path, samplerate, hop_size) | 82 | f = source(path, samplerate, hop_size) |
| 91 | except RuntimeError as e: | 83 | 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)) | ||
| 93 | if samplerate == 0: samplerate = f.samplerate | 86 | if samplerate == 0: samplerate = f.samplerate |
| 94 | sink_path = get_tmp_sink_path() | 87 | sink_path = get_tmp_sink_path() |
| 95 | g = sink(sink_path, samplerate, channels = f.channels) | 88 | g = sink(sink_path, samplerate, channels = f.channels) |
| @@ -125,4 +118,5 @@ class aubio_sink_test_case(TestCase): · 29 unmodified lines | |||
| 125 | g(vec, 128) | 118 | g(vec, 128) |
| 126 | 119 | ||
| 127 | if __name__ == '__main__': | 120 | if __name__ == '__main__': |
| 128 | main() | 121 | import pytest, sys |
| 122 | pytest.main(sys.argv) | ||