##// END OF EJS Templates
skip sympy tests if sympy not installed
Paul Ivanov -
Show More
@@ -15,13 +15,19 b' Authors:'
15 #-----------------------------------------------------------------------------
15 #-----------------------------------------------------------------------------
16
16
17 from IPython.lib.latextools import latex_to_png
17 from IPython.lib.latextools import latex_to_png
18 from IPython.testing import decorators as dec
19
20 try:
21 from sympy import pretty, latex
22 except ImportError:
23 pass
18
24
19 from sympy import pretty, latex
20
25
21 #-----------------------------------------------------------------------------
26 #-----------------------------------------------------------------------------
22 # Definitions of magic functions for use with IPython
27 # Definitions of magic functions for use with IPython
23 #-----------------------------------------------------------------------------
28 #-----------------------------------------------------------------------------
24
29
30 @dec.skipif_not_sympy
25 def print_basic_unicode(o, p, cycle):
31 def print_basic_unicode(o, p, cycle):
26 """A function to pretty print sympy Basic objects."""
32 """A function to pretty print sympy Basic objects."""
27 if cycle:
33 if cycle:
@@ -32,6 +38,7 b' def print_basic_unicode(o, p, cycle):'
32 p.text(out)
38 p.text(out)
33
39
34
40
41 @dec.skipif_not_sympy
35 def print_png(o):
42 def print_png(o):
36 """A funciton to display sympy expression using LaTex -> PNG."""
43 """A funciton to display sympy expression using LaTex -> PNG."""
37 s = latex(o, mode='inline')
44 s = latex(o, mode='inline')
@@ -44,7 +51,7 b' def print_png(o):'
44
51
45 _loaded = False
52 _loaded = False
46
53
47
54 @dec.skipif_not_sympy
48 def load_ipython_extension(ip):
55 def load_ipython_extension(ip):
49 """Load the extension in IPython."""
56 """Load the extension in IPython."""
50 global _loaded
57 global _loaded
@@ -274,19 +274,19 b' def onlyif(condition, msg):'
274
274
275 #-----------------------------------------------------------------------------
275 #-----------------------------------------------------------------------------
276 # Utility functions for decorators
276 # Utility functions for decorators
277 def numpy_not_available():
277 def module_not_available(module):
278 """Can numpy be imported? Returns true if numpy does NOT import.
278 """Can module be imported? Returns true if module does NOT import.
279
279
280 This is used to make a decorator to skip tests that require numpy to be
280 This is used to make a decorator to skip tests that require module to be
281 available, but delay the 'import numpy' to test execution time.
281 available, but delay the 'import numpy' to test execution time.
282 """
282 """
283 try:
283 try:
284 import numpy
284 mod = __import__(module)
285 np_not_avail = False
285 mod_not_avail = False
286 except ImportError:
286 except ImportError:
287 np_not_avail = True
287 mod_not_avail = True
288
288
289 return np_not_avail
289 yield mod_not_avail
290
290
291 #-----------------------------------------------------------------------------
291 #-----------------------------------------------------------------------------
292 # Decorators for public use
292 # Decorators for public use
@@ -315,9 +315,11 b" skip_if_not_osx = skipif(sys.platform != 'darwin',"
315 "This test only runs under OSX")
315 "This test only runs under OSX")
316
316
317 # Other skip decorators
317 # Other skip decorators
318 skipif_not_numpy = skipif(numpy_not_available,"This test requires numpy")
318 skipif_not_numpy = skipif(module_not_available('numpy'),"This test requires numpy")
319
319
320 skip_known_failure = skip('This test is known to fail')
320 skipif_not_sympy = skipif(module_not_available('sympy'),"This test requires sympy")
321
322 skip_known_failure = knownfailureif(True,'This test is known to fail')
321
323
322 # A null 'decorator', useful to make more readable code that needs to pick
324 # A null 'decorator', useful to make more readable code that needs to pick
323 # between different decorators based on OS or other conditions
325 # between different decorators based on OS or other conditions
General Comments 0
You need to be logged in to leave comments. Login now