2626
2727# Third-party imports
2828import nose .tools as nt
29- import numpy
29+
30+ try :
31+ import numpy
32+ except ImportError :
33+ pass
3034
3135# Our own imports
3236from IPython .lib import display
3337
38+ from IPython .testing .decorators import skipif_not_numpy
39+
3440#-----------------------------------------------------------------------------
3541# Classes and functions
3642#-----------------------------------------------------------------------------
@@ -188,26 +194,32 @@ def test_audio_from_file():
188194 display .Audio (filename = path )
189195
190196class TestAudioDataWithNumpy (TestCase ):
197+
198+ @skipif_not_numpy
191199 def test_audio_from_numpy_array (self ):
192200 test_tone = get_test_tone ()
193201 audio = display .Audio (test_tone , rate = 44100 )
194202 nt .assert_equal (len (read_wav (audio .data )), len (test_tone ))
195203
204+ @skipif_not_numpy
196205 def test_audio_from_list (self ):
197206 test_tone = get_test_tone ()
198207 audio = display .Audio (list (test_tone ), rate = 44100 )
199208 nt .assert_equal (len (read_wav (audio .data )), len (test_tone ))
200209
210+ @skipif_not_numpy
201211 def test_audio_from_numpy_array_without_rate_raises (self ):
202212 nt .assert_raises (ValueError , display .Audio , get_test_tone ())
203213
214+ @skipif_not_numpy
204215 def test_audio_data_normalization (self ):
205216 expected_max_value = numpy .iinfo (numpy .int16 ).max
206217 for scale in [1 , 0.5 , 2 ]:
207218 audio = display .Audio (get_test_tone (scale ), rate = 44100 )
208219 actual_max_value = numpy .max (numpy .abs (read_wav (audio .data )))
209220 nt .assert_equal (actual_max_value , expected_max_value )
210221
222+ @skipif_not_numpy
211223 def test_audio_data_without_normalization (self ):
212224 max_int16 = numpy .iinfo (numpy .int16 ).max
213225 for scale in [1 , 0.5 , 0.2 ]:
@@ -233,6 +245,7 @@ def simulate_numpy_not_installed():
233245class TestAudioDataWithoutNumpy (TestAudioDataWithNumpy ):
234246 # All tests from `TestAudioDataWithNumpy` are inherited.
235247
248+ @skipif_not_numpy
236249 def test_audio_raises_for_nested_list (self ):
237250 stereo_signal = [list (get_test_tone ())] * 2
238251 nt .assert_raises (
0 commit comments