History

python/tests/test_source.py: simplify, quieten

Paul Brossier committed 10 years ago

Commit 36e89561 parent ed938a21 file · +36 −21Browse files

Showing the changes to python/tests/test_source.py (1 of 1 file). Show all

Unified · Split

python/tests/test_source.py+36−21
@@ -7,6 +7,7 @@ from utils import list_all_sounds · 6 unmodified lines
7from nose2.tools import params7from nose2.tools import params
8 8
9list_of_sounds = list_all_sounds('sounds')9list_of_sounds = list_all_sounds('sounds')
10default_test_sound = list_of_sounds[0]
10samplerates = [0, 44100, 8000, 32000]11samplerates = [0, 44100, 8000, 32000]
11hop_sizes = [512, 1024, 64]12hop_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 total_frames += read51 total_frames += read
51 if read < f.hop_size: break52 if read < f.hop_size: break
52 result_str = "read {:.2f}s ({:d} frames in {:d} blocks at {:d}Hz) from {:s}"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.uri54 result_params = total_frames / float(f.samplerate), total_frames, total_frames//f.hop_size, f.samplerate, f.uri
54 print (result_str.format(*result_params))55 #print (result_str.format(*result_params))
55 return total_frames56 return total_frames
56 57
57 @params(*all_params)58 @params(*all_params)
@@ -75,24 +76,6 @@ class aubio_source_read_test_case(aubio_source_test_case_base): · 17 unmodified lines
75 assert f.samplerate != 076 assert f.samplerate != 0
76 self.read_from_source(f)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 @params(*list_of_sounds)79 @params(*list_of_sounds)
97 def test_zero_hop_size(self, p):80 def test_zero_hop_size(self, p):
98 f = source(p, 0, 0)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 if read < f.hop_size: break106 if read < f.hop_size: break
124 self.assertEqual(duration, total_frames)107 self.assertEqual(duration, total_frames)
125 108
109
110class 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
126class aubio_source_readmulti_test_case(aubio_source_read_test_case):141class aubio_source_readmulti_test_case(aubio_source_read_test_case):
127 142
128 def read_from_source(self, f):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 if read < f.hop_size: break148 if read < f.hop_size: break
134 result_str = "read {:.2f}s ({:d} frames in {:d} channels and {:d} blocks at {:d}Hz) from {:s}"149 result_str = "read {:.2f}s ({:d} frames in {:d} channels and {:d} blocks at {:d}Hz) from {:s}"
135 result_params = total_frames / float(f.samplerate), total_frames, f.channels, int(total_frames/f.hop_size), f.samplerate, f.uri150 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 return total_frames152 return total_frames
138 153
139if __name__ == '__main__':154if __name__ == '__main__':

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