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