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
77 from nose2.tools import params
88
99 list_of_sounds = list_all_sounds('sounds')
10+default_test_sound = list_of_sounds[0]
1011 samplerates = [0, 44100, 8000, 32000]
1112 hop_sizes = [512, 1024, 64]
1213
@@ -50,8 +51,8 @@ class aubio_source_read_test_case(aubio_source_test_case_base): · 37 unmodified lines
5051 total_frames += read
5152 if read < f.hop_size: break
5253 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))
5556 return total_frames
5657
5758 @params(*all_params)
@@ -75,24 +76,6 @@ class aubio_source_read_test_case(aubio_source_test_case_base): · 17 unmodified lines
7576 assert f.samplerate != 0
7677 self.read_from_source(f)
7778
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−
9679 @params(*list_of_sounds)
9780 def test_zero_hop_size(self, p):
9881 f = source(p, 0, 0)
@@ -123,6 +106,38 @@ class aubio_source_read_test_case(aubio_source_test_case_base): · 24 unmodified lines
123106 if read < f.hop_size: break
124107 self.assertEqual(duration, total_frames)
125108
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+
126141 class aubio_source_readmulti_test_case(aubio_source_read_test_case):
127142
128143 def read_from_source(self, f):
@@ -133,7 +148,7 @@ class aubio_source_readmulti_test_case(aubio_source_read_test_case): · 4 unmodified lines
133148 if read < f.hop_size: break
134149 result_str = "read {:.2f}s ({:d} frames in {:d} channels and {:d} blocks at {:d}Hz) from {:s}"
135150 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))
137152 return total_frames
138153
139154 if __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