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