##// END OF EJS Templates
Move skip_doctest decorator to separate module, so that it can be used without triggering other imports.
Thomas Kluyver -
Show More
@@ -0,0 +1,15 b''
1 """This decorator marks that a doctest should be skipped.
2
3 The IPython.testing.decorators module triggers various extra imports, including
4 numpy and sympy if they're present. Since this decorator is used in core parts
5 of IPython, it's in a separate module so that running IPython doesn't trigger
6 those imports."""
7
8 def skip_doctest(f):
9 """Decorator - mark a function or method for skipping its doctest.
10
11 This decorator allows you to mark a function whose docstring you wish to
12 omit from testing, while preserving the docstring for introspection, help,
13 etc."""
14 f.skip_doctest = True
15 return f
@@ -23,7 +23,7 b' import threading'
23 # Our own packages
23 # Our own packages
24 from IPython.config.configurable import Configurable
24 from IPython.config.configurable import Configurable
25
25
26 from IPython.testing import decorators as testdec
26 from IPython.testing.skipdoctest import skip_doctest
27 from IPython.utils import io
27 from IPython.utils import io
28 from IPython.utils.traitlets import Bool, Dict, Instance, Int, List, Unicode
28 from IPython.utils.traitlets import Bool, Dict, Instance, Int, List, Unicode
29 from IPython.utils.warn import warn
29 from IPython.utils.warn import warn
@@ -548,7 +548,7 b' def _format_lineno(session, line):'
548 return str(line)
548 return str(line)
549 return "%s#%s" % (session, line)
549 return "%s#%s" % (session, line)
550
550
551 @testdec.skip_doctest
551 @skip_doctest
552 def magic_history(self, parameter_s = ''):
552 def magic_history(self, parameter_s = ''):
553 """Print input history (_i<n> variables), with most recent last.
553 """Print input history (_i<n> variables), with most recent last.
554
554
@@ -51,7 +51,7 b' from IPython.core import page'
51 from IPython.core.prefilter import ESC_MAGIC
51 from IPython.core.prefilter import ESC_MAGIC
52 from IPython.lib.pylabtools import mpl_runner
52 from IPython.lib.pylabtools import mpl_runner
53 from IPython.external.Itpl import itpl, printpl
53 from IPython.external.Itpl import itpl, printpl
54 from IPython.testing import decorators as testdec
54 from IPython.testing.skipdoctest import skip_doctest
55 from IPython.utils.io import file_read, nlprint
55 from IPython.utils.io import file_read, nlprint
56 from IPython.utils.path import get_py_filename
56 from IPython.utils.path import get_py_filename
57 from IPython.utils.process import arg_split, abbrev_cwd
57 from IPython.utils.process import arg_split, abbrev_cwd
@@ -435,7 +435,7 b' Currently the magic system has the following functions:\\n"""'
435 self.shell.automagic = not self.shell.automagic
435 self.shell.automagic = not self.shell.automagic
436 print '\n' + Magic.auto_status[self.shell.automagic]
436 print '\n' + Magic.auto_status[self.shell.automagic]
437
437
438 @testdec.skip_doctest
438 @skip_doctest
439 def magic_autocall(self, parameter_s = ''):
439 def magic_autocall(self, parameter_s = ''):
440 """Make functions callable without having to type parentheses.
440 """Make functions callable without having to type parentheses.
441
441
@@ -564,7 +564,7 b' Currently the magic system has the following functions:\\n"""'
564 self.shell._inspect('pinfo', parameter_s, detail_level=1,
564 self.shell._inspect('pinfo', parameter_s, detail_level=1,
565 namespaces=namespaces)
565 namespaces=namespaces)
566
566
567 @testdec.skip_doctest
567 @skip_doctest
568 def magic_pdef(self, parameter_s='', namespaces=None):
568 def magic_pdef(self, parameter_s='', namespaces=None):
569 """Print the definition header for any callable object.
569 """Print the definition header for any callable object.
570
570
@@ -725,7 +725,7 b' Currently the magic system has the following functions:\\n"""'
725 except:
725 except:
726 shell.showtraceback()
726 shell.showtraceback()
727
727
728 @testdec.skip_doctest
728 @skip_doctest
729 def magic_who_ls(self, parameter_s=''):
729 def magic_who_ls(self, parameter_s=''):
730 """Return a sorted list of all interactive variables.
730 """Return a sorted list of all interactive variables.
731
731
@@ -766,7 +766,7 b' Currently the magic system has the following functions:\\n"""'
766 out.sort()
766 out.sort()
767 return out
767 return out
768
768
769 @testdec.skip_doctest
769 @skip_doctest
770 def magic_who(self, parameter_s=''):
770 def magic_who(self, parameter_s=''):
771 """Print all interactive variables, with some minimal formatting.
771 """Print all interactive variables, with some minimal formatting.
772
772
@@ -827,7 +827,7 b' Currently the magic system has the following functions:\\n"""'
827 print
827 print
828 print
828 print
829
829
830 @testdec.skip_doctest
830 @skip_doctest
831 def magic_whos(self, parameter_s=''):
831 def magic_whos(self, parameter_s=''):
832 """Like %who, but gives some extra information about each variable.
832 """Like %who, but gives some extra information about each variable.
833
833
@@ -1265,7 +1265,7 b' Currently the magic system has the following functions:\\n"""'
1265 """
1265 """
1266 self.shell.debugger(force=True)
1266 self.shell.debugger(force=True)
1267
1267
1268 @testdec.skip_doctest
1268 @skip_doctest
1269 def magic_prun(self, parameter_s ='',user_mode=1,
1269 def magic_prun(self, parameter_s ='',user_mode=1,
1270 opts=None,arg_lst=None,prog_ns=None):
1270 opts=None,arg_lst=None,prog_ns=None):
1271
1271
@@ -1438,7 +1438,7 b' Currently the magic system has the following functions:\\n"""'
1438 else:
1438 else:
1439 return None
1439 return None
1440
1440
1441 @testdec.skip_doctest
1441 @skip_doctest
1442 def magic_run(self, parameter_s ='',runner=None,
1442 def magic_run(self, parameter_s ='',runner=None,
1443 file_finder=get_py_filename):
1443 file_finder=get_py_filename):
1444 """Run the named file inside IPython as a program.
1444 """Run the named file inside IPython as a program.
@@ -1732,7 +1732,7 b' Currently the magic system has the following functions:\\n"""'
1732
1732
1733 return stats
1733 return stats
1734
1734
1735 @testdec.skip_doctest
1735 @skip_doctest
1736 def magic_timeit(self, parameter_s =''):
1736 def magic_timeit(self, parameter_s =''):
1737 """Time execution of a Python statement or expression
1737 """Time execution of a Python statement or expression
1738
1738
@@ -1869,7 +1869,7 b' Currently the magic system has the following functions:\\n"""'
1869 if tc > tc_min:
1869 if tc > tc_min:
1870 print "Compiler time: %.2f s" % tc
1870 print "Compiler time: %.2f s" % tc
1871
1871
1872 @testdec.skip_doctest
1872 @skip_doctest
1873 @needs_local_scope
1873 @needs_local_scope
1874 def magic_time(self,parameter_s = ''):
1874 def magic_time(self,parameter_s = ''):
1875 """Time execution of a Python statement or expression.
1875 """Time execution of a Python statement or expression.
@@ -1963,7 +1963,7 b' Currently the magic system has the following functions:\\n"""'
1963 print "Compiler : %.2f s" % tc
1963 print "Compiler : %.2f s" % tc
1964 return out
1964 return out
1965
1965
1966 @testdec.skip_doctest
1966 @skip_doctest
1967 def magic_macro(self,parameter_s = ''):
1967 def magic_macro(self,parameter_s = ''):
1968 """Define a macro for future re-execution. It accepts ranges of history,
1968 """Define a macro for future re-execution. It accepts ranges of history,
1969 filenames or string objects.
1969 filenames or string objects.
@@ -2127,7 +2127,7 b' Currently the magic system has the following functions:\\n"""'
2127 """Alias to %edit."""
2127 """Alias to %edit."""
2128 return self.magic_edit(parameter_s)
2128 return self.magic_edit(parameter_s)
2129
2129
2130 @testdec.skip_doctest
2130 @skip_doctest
2131 def magic_edit(self,parameter_s='',last_call=['','']):
2131 def magic_edit(self,parameter_s='',last_call=['','']):
2132 """Bring up an editor and execute the resulting code.
2132 """Bring up an editor and execute the resulting code.
2133
2133
@@ -2524,7 +2524,7 b' Defaulting color scheme to \'NoColor\'"""'
2524 #......................................................................
2524 #......................................................................
2525 # Functions to implement unix shell-type things
2525 # Functions to implement unix shell-type things
2526
2526
2527 @testdec.skip_doctest
2527 @skip_doctest
2528 def magic_alias(self, parameter_s = ''):
2528 def magic_alias(self, parameter_s = ''):
2529 """Define an alias for a system command.
2529 """Define an alias for a system command.
2530
2530
@@ -2686,7 +2686,7 b' Defaulting color scheme to \'NoColor\'"""'
2686 finally:
2686 finally:
2687 os.chdir(savedir)
2687 os.chdir(savedir)
2688
2688
2689 @testdec.skip_doctest
2689 @skip_doctest
2690 def magic_pwd(self, parameter_s = ''):
2690 def magic_pwd(self, parameter_s = ''):
2691 """Return the current working directory path.
2691 """Return the current working directory path.
2692
2692
@@ -2699,7 +2699,7 b' Defaulting color scheme to \'NoColor\'"""'
2699 """
2699 """
2700 return os.getcwd()
2700 return os.getcwd()
2701
2701
2702 @testdec.skip_doctest
2702 @skip_doctest
2703 def magic_cd(self, parameter_s=''):
2703 def magic_cd(self, parameter_s=''):
2704 """Change the current working directory.
2704 """Change the current working directory.
2705
2705
@@ -2904,7 +2904,7 b' Defaulting color scheme to \'NoColor\'"""'
2904 header = 'Directory history (kept in _dh)',
2904 header = 'Directory history (kept in _dh)',
2905 start=ini,stop=fin)
2905 start=ini,stop=fin)
2906
2906
2907 @testdec.skip_doctest
2907 @skip_doctest
2908 def magic_sc(self, parameter_s=''):
2908 def magic_sc(self, parameter_s=''):
2909 """Shell capture - execute a shell command and capture its output.
2909 """Shell capture - execute a shell command and capture its output.
2910
2910
@@ -3328,7 +3328,7 b' Defaulting color scheme to \'NoColor\'"""'
3328 """Reload an IPython extension by its module name."""
3328 """Reload an IPython extension by its module name."""
3329 self.extension_manager.reload_extension(module_str)
3329 self.extension_manager.reload_extension(module_str)
3330
3330
3331 @testdec.skip_doctest
3331 @skip_doctest
3332 def magic_install_profiles(self, s):
3332 def magic_install_profiles(self, s):
3333 """Install the default IPython profiles into the .ipython dir.
3333 """Install the default IPython profiles into the .ipython dir.
3334
3334
@@ -3386,14 +3386,14 b' Defaulting color scheme to \'NoColor\'"""'
3386 # Pylab support: simple wrappers that activate pylab, load gui input
3386 # Pylab support: simple wrappers that activate pylab, load gui input
3387 # handling and modify slightly %run
3387 # handling and modify slightly %run
3388
3388
3389 @testdec.skip_doctest
3389 @skip_doctest
3390 def _pylab_magic_run(self, parameter_s=''):
3390 def _pylab_magic_run(self, parameter_s=''):
3391 Magic.magic_run(self, parameter_s,
3391 Magic.magic_run(self, parameter_s,
3392 runner=mpl_runner(self.shell.safe_execfile))
3392 runner=mpl_runner(self.shell.safe_execfile))
3393
3393
3394 _pylab_magic_run.__doc__ = magic_run.__doc__
3394 _pylab_magic_run.__doc__ = magic_run.__doc__
3395
3395
3396 @testdec.skip_doctest
3396 @skip_doctest
3397 def magic_pylab(self, s):
3397 def magic_pylab(self, s):
3398 """Load numpy and matplotlib to work interactively.
3398 """Load numpy and matplotlib to work interactively.
3399
3399
@@ -3437,7 +3437,7 b' Defaulting color scheme to \'NoColor\'"""'
3437 See %xmode for changing exception reporting modes."""
3437 See %xmode for changing exception reporting modes."""
3438 self.shell.showtraceback()
3438 self.shell.showtraceback()
3439
3439
3440 @testdec.skip_doctest
3440 @skip_doctest
3441 def magic_precision(self, s=''):
3441 def magic_precision(self, s=''):
3442 """Set floating point precision for pretty printing.
3442 """Set floating point precision for pretty printing.
3443
3443
@@ -19,7 +19,7 b' import re'
19
19
20 from IPython.core.plugin import Plugin
20 from IPython.core.plugin import Plugin
21 from IPython.utils.traitlets import Bool, Any, Instance
21 from IPython.utils.traitlets import Bool, Any, Instance
22 from IPython.testing import decorators as testdec
22 from IPython.testing.skipdoctest import skip_doctest
23
23
24 #-----------------------------------------------------------------------------
24 #-----------------------------------------------------------------------------
25 # Definitions of magic functions for use with IPython
25 # Definitions of magic functions for use with IPython
@@ -50,7 +50,7 b' class ParalleMagic(Plugin):'
50 self.shell.define_magic('px', self.magic_px)
50 self.shell.define_magic('px', self.magic_px)
51 self.shell.define_magic('autopx', self.magic_autopx)
51 self.shell.define_magic('autopx', self.magic_autopx)
52
52
53 @testdec.skip_doctest
53 @skip_doctest
54 def magic_result(self, ipself, parameter_s=''):
54 def magic_result(self, ipself, parameter_s=''):
55 """Print the result of command i on all engines..
55 """Print the result of command i on all engines..
56
56
@@ -82,7 +82,7 b' class ParalleMagic(Plugin):'
82 result = self.active_view.get_result(index)
82 result = self.active_view.get_result(index)
83 return result
83 return result
84
84
85 @testdec.skip_doctest
85 @skip_doctest
86 def magic_px(self, ipself, parameter_s=''):
86 def magic_px(self, ipself, parameter_s=''):
87 """Executes the given python command in parallel.
87 """Executes the given python command in parallel.
88
88
@@ -108,7 +108,7 b' class ParalleMagic(Plugin):'
108 result.get()
108 result.get()
109 self._maybe_display_output(result)
109 self._maybe_display_output(result)
110
110
111 @testdec.skip_doctest
111 @skip_doctest
112 def magic_autopx(self, ipself, parameter_s=''):
112 def magic_autopx(self, ipself, parameter_s=''):
113 """Toggles auto parallel mode.
113 """Toggles auto parallel mode.
114
114
@@ -26,7 +26,7 b' from IPython.core.usage import interactive_usage, default_banner'
26 from IPython.core.interactiveshell import InteractiveShell, InteractiveShellABC
26 from IPython.core.interactiveshell import InteractiveShell, InteractiveShellABC
27 from IPython.lib.inputhook import enable_gui
27 from IPython.lib.inputhook import enable_gui
28 from IPython.lib.pylabtools import pylab_activate
28 from IPython.lib.pylabtools import pylab_activate
29 from IPython.testing import decorators as testdec
29 from IPython.testing.skipdoctest import skip_doctest
30 from IPython.utils.terminal import toggle_set_term_title, set_term_title
30 from IPython.utils.terminal import toggle_set_term_title, set_term_title
31 from IPython.utils.process import abbrev_cwd
31 from IPython.utils.process import abbrev_cwd
32 from IPython.utils.warn import warn
32 from IPython.utils.warn import warn
@@ -448,7 +448,7 b' class TerminalInteractiveShell(InteractiveShell):'
448 self.shell.set_autoindent()
448 self.shell.set_autoindent()
449 print "Automatic indentation is:",['OFF','ON'][self.shell.autoindent]
449 print "Automatic indentation is:",['OFF','ON'][self.shell.autoindent]
450
450
451 @testdec.skip_doctest
451 @skip_doctest
452 def magic_cpaste(self, parameter_s=''):
452 def magic_cpaste(self, parameter_s=''):
453 """Paste & execute a pre-formatted code block from clipboard.
453 """Paste & execute a pre-formatted code block from clipboard.
454
454
@@ -12,7 +12,7 b''
12
12
13 import warnings
13 import warnings
14
14
15 from IPython.testing import decorators as testdec
15 from IPython.testing.skipdoctest import skip_doctest
16
16
17 from . import map as Map
17 from . import map as Map
18 from .asyncresult import AsyncMapResult
18 from .asyncresult import AsyncMapResult
@@ -21,7 +21,7 b' from .asyncresult import AsyncMapResult'
21 # Decorators
21 # Decorators
22 #-----------------------------------------------------------------------------
22 #-----------------------------------------------------------------------------
23
23
24 @testdec.skip_doctest
24 @skip_doctest
25 def remote(view, block=None, **flags):
25 def remote(view, block=None, **flags):
26 """Turn a function into a remote function.
26 """Turn a function into a remote function.
27
27
@@ -36,7 +36,7 b' def remote(view, block=None, **flags):'
36 return RemoteFunction(view, f, block=block, **flags)
36 return RemoteFunction(view, f, block=block, **flags)
37 return remote_function
37 return remote_function
38
38
39 @testdec.skip_doctest
39 @skip_doctest
40 def parallel(view, dist='b', block=None, **flags):
40 def parallel(view, dist='b', block=None, **flags):
41 """Turn a function into a parallel remote function.
41 """Turn a function into a parallel remote function.
42
42
@@ -197,4 +197,4 b' class ParallelFunction(RemoteFunction):'
197 del self._map
197 del self._map
198 return ret
198 return ret
199
199
200 __all__ = ['remote', 'parallel', 'RemoteFunction', 'ParallelFunction'] No newline at end of file
200 __all__ = ['remote', 'parallel', 'RemoteFunction', 'ParallelFunction']
@@ -18,9 +18,8 b' from types import ModuleType'
18
18
19 import zmq
19 import zmq
20
20
21 from IPython.testing import decorators as testdec
21 from IPython.testing.skipdoctest import skip_doctest
22 from IPython.utils.traitlets import HasTraits, Any, Bool, List, Dict, Set, Int, Instance, CFloat, CInt
22 from IPython.utils.traitlets import HasTraits, Any, Bool, List, Dict, Set, Int, Instance, CFloat, CInt
23
24 from IPython.external.decorator import decorator
23 from IPython.external.decorator import decorator
25
24
26 from IPython.parallel import util
25 from IPython.parallel import util
@@ -69,7 +68,7 b' def spin_after(f, self, *args, **kwargs):'
69 # Classes
68 # Classes
70 #-----------------------------------------------------------------------------
69 #-----------------------------------------------------------------------------
71
70
72 @testdec.skip_doctest
71 @skip_doctest
73 class View(HasTraits):
72 class View(HasTraits):
74 """Base View class for more convenint apply(f,*args,**kwargs) syntax via attributes.
73 """Base View class for more convenint apply(f,*args,**kwargs) syntax via attributes.
75
74
@@ -360,7 +359,7 b' class View(HasTraits):'
360 block = self.block if block is None else block
359 block = self.block if block is None else block
361 return parallel(self, dist=dist, block=block, **flags)
360 return parallel(self, dist=dist, block=block, **flags)
362
361
363 @testdec.skip_doctest
362 @skip_doctest
364 class DirectView(View):
363 class DirectView(View):
365 """Direct Multiplexer View of one or more engines.
364 """Direct Multiplexer View of one or more engines.
366
365
@@ -772,7 +771,7 b' class DirectView(View):'
772 pmagic.active_view = self
771 pmagic.active_view = self
773
772
774
773
775 @testdec.skip_doctest
774 @skip_doctest
776 class LoadBalancedView(View):
775 class LoadBalancedView(View):
777 """An load-balancing View that only executes via the Task scheduler.
776 """An load-balancing View that only executes via the Task scheduler.
778
777
@@ -1039,4 +1038,4 b' class LoadBalancedView(View):'
1039 pf = ParallelFunction(self, f, block=block, chunksize=chunksize)
1038 pf = ParallelFunction(self, f, block=block, chunksize=chunksize)
1040 return pf.map(*sequences)
1039 return pf.map(*sequences)
1041
1040
1042 __all__ = ['LoadBalancedView', 'DirectView'] No newline at end of file
1041 __all__ = ['LoadBalancedView', 'DirectView']
@@ -292,13 +292,6 b' def module_not_available(module):'
292 #-----------------------------------------------------------------------------
292 #-----------------------------------------------------------------------------
293 # Decorators for public use
293 # Decorators for public use
294
294
295 skip_doctest = make_label_dec('skip_doctest',
296 """Decorator - mark a function or method for skipping its doctest.
297
298 This decorator allows you to mark a function whose docstring you wish to
299 omit from testing, while preserving the docstring for introspection, help,
300 etc.""")
301
302 # Decorators to skip certain tests on specific platforms.
295 # Decorators to skip certain tests on specific platforms.
303 skip_win32 = skipif(sys.platform == 'win32',
296 skip_win32 = skipif(sys.platform == 'win32',
304 "This test does not run under Windows")
297 "This test does not run under Windows")
@@ -5,7 +5,6 b''
5 import inspect
5 import inspect
6
6
7 # Our own
7 # Our own
8 from IPython.testing import decorators as dec
9
8
10 #-----------------------------------------------------------------------------
9 #-----------------------------------------------------------------------------
11 # Testing functions
10 # Testing functions
@@ -38,8 +37,7 b' def doctest_ivars():'
38 In [6]: zz
37 In [6]: zz
39 Out[6]: 1
38 Out[6]: 1
40 """
39 """
41
40
42 #@dec.skip_doctest
43 def doctest_refs():
41 def doctest_refs():
44 """DocTest reference holding issues when running scripts.
42 """DocTest reference holding issues when running scripts.
45
43
@@ -12,6 +12,7 b' import nose.tools as nt'
12
12
13 # Our own
13 # Our own
14 from IPython.testing import decorators as dec
14 from IPython.testing import decorators as dec
15 from IPython.testing.skipdoctest import skip_doctest
15 from IPython.testing.ipunittest import ParametricTestCase
16 from IPython.testing.ipunittest import ParametricTestCase
16
17
17 #-----------------------------------------------------------------------------
18 #-----------------------------------------------------------------------------
@@ -79,7 +80,7 b' def test_deliberately_broken2():'
79
80
80 # Verify that we can correctly skip the doctest for a function at will, but
81 # Verify that we can correctly skip the doctest for a function at will, but
81 # that the docstring itself is NOT destroyed by the decorator.
82 # that the docstring itself is NOT destroyed by the decorator.
82 @dec.skip_doctest
83 @skip_doctest
83 def doctest_bad(x,y=1,**k):
84 def doctest_bad(x,y=1,**k):
84 """A function whose doctest we need to skip.
85 """A function whose doctest we need to skip.
85
86
@@ -127,7 +128,7 b' class FooClass(object):'
127 2
128 2
128 """
129 """
129
130
130 @dec.skip_doctest
131 @skip_doctest
131 def __init__(self,x):
132 def __init__(self,x):
132 """Make a FooClass.
133 """Make a FooClass.
133
134
@@ -139,7 +140,7 b' class FooClass(object):'
139 print 'Making a FooClass.'
140 print 'Making a FooClass.'
140 self.x = x
141 self.x = x
141
142
142 @dec.skip_doctest
143 @skip_doctest
143 def bar(self,y):
144 def bar(self,y):
144 """Example:
145 """Example:
145
146
General Comments 0
You need to be logged in to leave comments. Login now