diff --git a/IPython/extensions/sympy_printing.py b/IPython/extensions/sympy_printing.py index 191fa6c..5fb5514 100644 --- a/IPython/extensions/sympy_printing.py +++ b/IPython/extensions/sympy_printing.py @@ -15,13 +15,19 @@ Authors: #----------------------------------------------------------------------------- from IPython.lib.latextools import latex_to_png +from IPython.testing import decorators as dec + +try: + from sympy import pretty, latex +except ImportError: + pass -from sympy import pretty, latex #----------------------------------------------------------------------------- # Definitions of magic functions for use with IPython #----------------------------------------------------------------------------- +@dec.skipif_not_sympy def print_basic_unicode(o, p, cycle): """A function to pretty print sympy Basic objects.""" if cycle: @@ -32,6 +38,7 @@ def print_basic_unicode(o, p, cycle): p.text(out) +@dec.skipif_not_sympy def print_png(o): """A funciton to display sympy expression using LaTex -> PNG.""" s = latex(o, mode='inline') @@ -44,7 +51,7 @@ def print_png(o): _loaded = False - +@dec.skipif_not_sympy def load_ipython_extension(ip): """Load the extension in IPython.""" global _loaded diff --git a/IPython/testing/decorators.py b/IPython/testing/decorators.py index 7bd0fa9..6956294 100644 --- a/IPython/testing/decorators.py +++ b/IPython/testing/decorators.py @@ -274,19 +274,19 @@ def onlyif(condition, msg): #----------------------------------------------------------------------------- # Utility functions for decorators -def numpy_not_available(): - """Can numpy be imported? Returns true if numpy does NOT import. +def module_not_available(module): + """Can module be imported? Returns true if module does NOT import. - This is used to make a decorator to skip tests that require numpy to be + This is used to make a decorator to skip tests that require module to be available, but delay the 'import numpy' to test execution time. """ try: - import numpy - np_not_avail = False + mod = __import__(module) + mod_not_avail = False except ImportError: - np_not_avail = True + mod_not_avail = True - return np_not_avail + yield mod_not_avail #----------------------------------------------------------------------------- # Decorators for public use @@ -315,9 +315,11 @@ skip_if_not_osx = skipif(sys.platform != 'darwin', "This test only runs under OSX") # Other skip decorators -skipif_not_numpy = skipif(numpy_not_available,"This test requires numpy") +skipif_not_numpy = skipif(module_not_available('numpy'),"This test requires numpy") -skip_known_failure = skip('This test is known to fail') +skipif_not_sympy = skipif(module_not_available('sympy'),"This test requires sympy") + +skip_known_failure = knownfailureif(True,'This test is known to fail') # A null 'decorator', useful to make more readable code that needs to pick # between different decorators based on OS or other conditions