Show More
@@ -159,16 +159,12 b' class Audio(DisplayObject):' | |||||
159 |
|
159 | |||
160 | @staticmethod |
|
160 | @staticmethod | |
161 | def _validate_and_normalize_without_numpy(data): |
|
161 | def _validate_and_normalize_without_numpy(data): | |
162 | # check that it is a "1D" list |
|
|||
163 | idata = iter(data) # fails if not an iterable |
|
|||
164 | try: |
|
162 | try: | |
165 | iter(idata.next()) |
|
163 | maxabsvalue = float(max([abs(x) for x in data])) | |
|
164 | except TypeError: | |||
166 | raise TypeError('Only lists of mono audio are ' |
|
165 | raise TypeError('Only lists of mono audio are ' | |
167 | 'supported if numpy is not installed') |
|
166 | 'supported if numpy is not installed') | |
168 | except TypeError: |
|
167 | ||
169 | # this means it's not a nested list, which is what we want |
|
|||
170 | pass |
|
|||
171 | maxabsvalue = float(max([abs(x) for x in data])) |
|
|||
172 | scaled = [int(x/maxabsvalue*32767) for x in data] |
|
168 | scaled = [int(x/maxabsvalue*32767) for x in data] | |
173 | nchan = 1 |
|
169 | nchan = 1 | |
174 | return scaled, nchan |
|
170 | return scaled, nchan |
@@ -19,6 +19,7 b' try:' | |||||
19 | import pathlib |
|
19 | import pathlib | |
20 | except ImportError: |
|
20 | except ImportError: | |
21 | pass |
|
21 | pass | |
|
22 | from unittest import mock | |||
22 |
|
23 | |||
23 | # Third-party imports |
|
24 | # Third-party imports | |
24 | import nose.tools as nt |
|
25 | import nose.tools as nt | |
@@ -186,6 +187,17 b' def test_audio_from_file():' | |||||
186 | def test_audio_from_numpy_array(): |
|
187 | def test_audio_from_numpy_array(): | |
187 | display.Audio(get_test_tone(), rate=44100) |
|
188 | display.Audio(get_test_tone(), rate=44100) | |
188 |
|
189 | |||
|
190 | def test_audio_from_list_without_numpy(): | |||
|
191 | # Simulate numpy not installed. | |||
|
192 | with mock.patch('numpy.array', side_effect=ImportError): | |||
|
193 | display.Audio(list(get_test_tone()), rate=44100) | |||
|
194 | ||||
|
195 | def test_audio_from_list_without_numpy_raises_for_nested_list(): | |||
|
196 | # Simulate numpy not installed. | |||
|
197 | with mock.patch('numpy.array', side_effect=ImportError): | |||
|
198 | stereo_signal = [list(get_test_tone())] * 2 | |||
|
199 | nt.assert_raises(TypeError, lambda: display.Audio(stereo_signal, rate=44100)) | |||
|
200 | ||||
189 | def test_audio_from_numpy_array_without_rate_raises(): |
|
201 | def test_audio_from_numpy_array_without_rate_raises(): | |
190 | nt.assert_raises(ValueError, display.Audio, get_test_tone()) |
|
202 | nt.assert_raises(ValueError, display.Audio, get_test_tone()) | |
191 |
|
203 |
General Comments 0
You need to be logged in to leave comments.
Login now