Showing the changes to python (1 of 1 file). Show all
Unified · Split
| @@ -7,6 +7,7 @@ from utils import list_all_sounds · 6 unmodified lines | ||
| 7 | 7 | from nose2.tools import params |
| 8 | 8 | |
| 9 | 9 | list_of_sounds = list_all_sounds('sounds') |
| 10 | +default_test_sound = list_of_sounds[0] | |
| 10 | 11 | samplerates = [0, 44100, 8000, 32000] |
| 11 | 12 | hop_sizes = [512, 1024, 64] |
| 12 | 13 | |
| @@ -50,8 +51,8 @@ class aubio_source_read_test_case(aubio_source_test_case_base): · 37 unmodified lines | ||
| 50 | 51 | total_frames += read |
| 51 | 52 | if read < f.hop_size: break |
| 52 | 53 | result_str = "read {:.2f}s ({:d} frames in {:d} blocks at {:d}Hz) from {:s}" |
| 53 | − result_params = total_frames / float(f.samplerate), total_frames, int(total_frames/f.hop_size), f.samplerate, f.uri | |
| 54 | − print (result_str.format(*result_params)) | |
| 54 | + result_params = total_frames / float(f.samplerate), total_frames, total_frames//f.hop_size, f.samplerate, f.uri | |
| 55 | + #print (result_str.format(*result_params)) | |
| 55 | 56 | return total_frames |
| 56 | 57 | |
| 57 | 58 | @params(*all_params) |
| @@ -75,24 +76,6 @@ class aubio_source_read_test_case(aubio_source_test_case_base): · 17 unmodified lines | ||
| 75 | 76 | assert f.samplerate != 0 |
| 76 | 77 | self.read_from_source(f) |
| 77 | 78 | |
| 78 | − @params(*list_of_sounds) | |
| 79 | − def test_wrong_samplerate(self, p): | |
| 80 | − try: | |
| 81 | − f = source(p, -1) | |
| 82 | − except ValueError as e: | |
| 83 | − pass | |
| 84 | − else: | |
| 85 | − self.fail('negative samplerate does not raise ValueError') | |
| 86 | − | |
| 87 | − @params(*list_of_sounds) | |
| 88 | − def test_wrong_hop_size(self, p): | |
| 89 | − try: | |
| 90 | − f = source(p, 0, -1) | |
| 91 | − except ValueError as e: | |
| 92 | − pass | |
| 93 | − else: | |
| 94 | − self.fail('negative hop_size does not raise ValueError') | |
| 95 | − | |
| 96 | 79 | @params(*list_of_sounds) |
| 97 | 80 | def test_zero_hop_size(self, p): |
| 98 | 81 | f = source(p, 0, 0) |
| @@ -123,6 +106,38 @@ class aubio_source_read_test_case(aubio_source_test_case_base): · 24 unmodified lines | ||
| 123 | 106 | if read < f.hop_size: break |
| 124 | 107 | self.assertEqual(duration, total_frames) |
| 125 | 108 | |
| 109 | + | |
| 110 | +class aubio_source_test_wrong_params(TestCase): | |
| 111 | + | |
| 112 | + def test_wrong_file(self): | |
| 113 | + with self.assertRaises(RuntimeError): | |
| 114 | + f = source('path_to/unexisting file.mp3') | |
| 115 | + | |
| 116 | + def test_wrong_samplerate(self): | |
| 117 | + with self.assertRaises(ValueError): | |
| 118 | + f = source(default_test_sound, -1) | |
| 119 | + | |
| 120 | + def test_wrong_hop_size(self): | |
| 121 | + with self.assertRaises(ValueError): | |
| 122 | + f = source(default_test_sound, 0, -1) | |
| 123 | + | |
| 124 | + def test_wrong_channels(self): | |
| 125 | + with self.assertRaises(ValueError): | |
| 126 | + f = source(default_test_sound, 0, 0, -1) | |
| 127 | + | |
| 128 | + def test_wrong_seek(self): | |
| 129 | + f = source(default_test_sound) | |
| 130 | + with self.assertRaises(ValueError): | |
| 131 | + f.seek(-1) | |
| 132 | + | |
| 133 | + def test_wrong_seek_too_large(self): | |
| 134 | + f = source(default_test_sound) | |
| 135 | + try: | |
| 136 | + with self.assertRaises(ValueError): | |
| 137 | + f.seek(f.duration + f.samplerate * 10) | |
| 138 | + except AssertionError as e: | |
| 139 | + self.skipTest('seeking after end of stream failed raising ValueError') | |
| 140 | + | |
| 126 | 141 | class aubio_source_readmulti_test_case(aubio_source_read_test_case): |
| 127 | 142 | |
| 128 | 143 | def read_from_source(self, f): |
| @@ -133,7 +148,7 @@ class aubio_source_readmulti_test_case(aubio_source_read_test_case): · 4 unmodified lines | ||
| 133 | 148 | if read < f.hop_size: break |
| 134 | 149 | result_str = "read {:.2f}s ({:d} frames in {:d} channels and {:d} blocks at {:d}Hz) from {:s}" |
| 135 | 150 | result_params = total_frames / float(f.samplerate), total_frames, f.channels, int(total_frames/f.hop_size), f.samplerate, f.uri |
| 136 | − print (result_str.format(*result_params)) | |
| 151 | + #print (result_str.format(*result_params)) | |
| 137 | 152 | return total_frames |
| 138 | 153 | |
| 139 | 154 | if __name__ == '__main__': |