Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e1b53e9

Browse files
committed
Properly don't require numpy to run tests.
Import explicitly instead of *-import to make sure we do not use non-mocked features. And skip tests that would actually require numpy. Make it easier to test on nightly when numpy is hard to build. Closes #11709
1 parent f14271f commit e1b53e9

6 files changed

Lines changed: 22 additions & 11 deletions

File tree

IPython/core/tests/test_completer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def test_forward_unicode_completion():
183183
nt.assert_equal(matches[0], 'Ⅴ')
184184

185185
@nt.nottest # now we have a completion for \jmath
186-
@decorators.dec.knownfailureif(sys.platform == 'win32', 'Fails if there is a C:\\j... path')
186+
@decorators.knownfailureif(sys.platform == 'win32', 'Fails if there is a C:\\j... path')
187187
def test_no_ascii_back_completion():
188188
ip = get_ipython()
189189
with TemporaryWorkingDirectory(): # Avoid any filename completions
@@ -234,7 +234,7 @@ def test_has_open_quotes4():
234234
nt.assert_false(completer.has_open_quotes(s))
235235

236236

237-
@decorators.dec.knownfailureif(sys.platform == 'win32', "abspath completions fail on Windows")
237+
@decorators.knownfailureif(sys.platform == 'win32', "abspath completions fail on Windows")
238238
def test_abspath_file_completions():
239239
ip = get_ipython()
240240
with TemporaryDirectory() as tmpdir:

IPython/core/tests/test_run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ def test_run_tb():
538538
nt.assert_in("RuntimeError", out)
539539
nt.assert_equal(out.count("---->"), 3)
540540

541-
@dec.dec.knownfailureif(sys.platform == 'win32', "writes to io.stdout aren't captured on Windows")
541+
@dec.knownfailureif(sys.platform == 'win32', "writes to io.stdout aren't captured on Windows")
542542
def test_script_tb():
543543
"""Test traceback offset in `ipython script.py`"""
544544
with TemporaryDirectory() as td:

IPython/external/decorators/__init__.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
try:
2-
from numpy.testing import *
3-
from numpy.testing import dec
4-
from numpy.testing.noseclasses import KnownFailure
2+
from numpy.testing.noseclasses import KnownFailure, knownfailureif
53
except ImportError:
6-
from ._decorators import *
4+
from ._decorators import knownfailureif
75
try:
86
from ._numpy_testing_noseclasses import KnownFailure
97
except ImportError:

IPython/lib/tests/test_display.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,17 @@
2626

2727
# Third-party imports
2828
import nose.tools as nt
29-
import numpy
29+
30+
try:
31+
import numpy
32+
except ImportError:
33+
pass
3034

3135
# Our own imports
3236
from 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

190196
class 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():
233245
class 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(

IPython/testing/decorators.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
# Grab the numpy-specific decorators which we keep in a file that we
4848
# occasionally update from upstream: decorators.py is a copy of
4949
# numpy.testing.decorators, we expose all of it here.
50-
from IPython.external.decorators import *
50+
from IPython.external.decorators import knownfailureif
5151

5252
#-----------------------------------------------------------------------------
5353
# Classes and functions
@@ -333,7 +333,7 @@ def skip_file_no_x11(name):
333333

334334
skipif_not_sympy = skip_without('sympy')
335335

336-
skip_known_failure = dec.knownfailureif(True,'This test is known to fail')
336+
skip_known_failure = knownfailureif(True,'This test is known to fail')
337337

338338
# A null 'decorator', useful to make more readable code that needs to pick
339339
# between different decorators based on OS or other conditions

IPython/testing/iptest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
from IPython.utils.py3compat import decode
3838
from IPython.utils.importstring import import_item
3939
from IPython.testing.plugin.ipdoctest import IPythonDoctest
40-
from IPython.external.decorators import KnownFailure, dec
40+
from IPython.external.decorators import KnownFailure, knownfailureif
4141

4242
pjoin = path.join
4343

0 commit comments

Comments
 (0)