diff options
author | Matthew Brett <matthew.brett@gmail.com> | 2011-08-10 19:06:48 -0700 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2011-08-16 10:44:29 -0600 |
commit | b0c1f6b67ecd5cf865cf6945bff632f81473b81a (patch) | |
tree | 97debdbb7c4b173d9f2d988bcd841dc5beeebcbb /numpy/testing/nosetester.py | |
parent | 5cf0a07396b88b48b6f8a922fe8b1147406cb4bc (diff) | |
download | numpy-b0c1f6b67ecd5cf865cf6945bff632f81473b81a.tar.gz |
ENH: refactor of docteset plugin management
We previously had a baroque inheritance scheme to deal with the case
where the user had normal nose doctests enabled in their environment.
However, this scheme didn't deal with bench() routine, and was
complicated. This commit uses a null Unplugger plugin to pull the
doctest plugin off the nose configuration after it has been initialized.
We can use this for bench() and test(), and it allows the doctest module
to be enabled (by the user environment) and then thrown away.
Also rejigged the docstrings and removed the automated docstring
addition as the docstrings have already been copied and adapted in the
code.
Diffstat (limited to 'numpy/testing/nosetester.py')
-rw-r--r-- | numpy/testing/nosetester.py | 95 |
1 files changed, 40 insertions, 55 deletions
diff --git a/numpy/testing/nosetester.py b/numpy/testing/nosetester.py index 90e09f880..9e27352ab 100644 --- a/numpy/testing/nosetester.py +++ b/numpy/testing/nosetester.py @@ -79,33 +79,6 @@ def run_module_suite(file_to_run = None): import_nose().run(argv=['',file_to_run]) -# contructs NoseTester method docstrings -def _docmethod(meth, testtype): - if not meth.__doc__: - return - - test_header = \ - '''Parameters - ---------- - label : {'fast', 'full', '', attribute identifer} - Identifies the %(testtype)ss to run. This can be a string to - pass to the nosetests executable with the '-A' option, or one of - several special values. - Special values are: - 'fast' - the default - which corresponds to nosetests -A option - of 'not slow'. - 'full' - fast (as above) and slow %(testtype)ss as in the - no -A option to nosetests - same as '' - None or '' - run all %(testtype)ss - attribute_identifier - string passed directly to nosetests as '-A' - verbose : integer - verbosity value for test outputs, 1-10 - extra_argv : list - List with any extra args to pass to nosetests''' \ - % {'testtype': testtype} - - meth.__doc__ = meth.__doc__ % {'test_header':test_header} - class NoseTester(object): """ @@ -171,7 +144,19 @@ class NoseTester(object): def _test_argv(self, label, verbose, extra_argv): ''' Generate argv for nosetest command - %(test_header)s + Parameters + ---------- + label : {'fast', 'full', '', attribute identifier}, optional + see ``test`` docstring + verbose : int, optional + Verbosity value for test outputs, in the range 1-10. Default is 1. + extra_argv : list, optional + List with any extra arguments to pass to nosetests. + + Returns + ------- + argv : list + command line arguments that will be passed to nose ''' argv = [__file__, self.package_path, '-s'] if label and label != 'full': @@ -239,12 +224,13 @@ class NoseTester(object): argv += ['--exclude','pyrex_ext'] argv += ['--exclude','swig_ext'] - nose = import_nose() + # fail with nice error message if nose is not present + import_nose() # construct list of plugins import nose.plugins.builtin - from noseclasses import NumpyDoctest, KnownFailure - plugins = [NumpyDoctest(), KnownFailure()] + from noseclasses import NumpyDoctest, KnownFailure, Unplugger + plugins = [NumpyDoctest(), KnownFailure(), Unplugger()] plugins += [p() for p in nose.plugins.builtin.plugins] return argv, plugins @@ -256,15 +242,14 @@ class NoseTester(object): Parameters ---------- label : {'fast', 'full', '', attribute identifier}, optional - Identifies the tests to run. This can be a string to pass to the - nosetests executable with the '-A' option, or one of - several special values. - Special values are: - 'fast' - the default - which corresponds to the ``nosetests -A`` - option of 'not slow'. - 'full' - fast (as above) and slow tests as in the - 'no -A' option to nosetests - this is the same as ''. - None or '' - run all tests. + Identifies the tests to run. This can be a string to pass to + the nosetests executable with the '-A' option, or one of several + special values. Special values are: + * 'fast' - the default - which corresponds to the ``nosetests -A`` + option of 'not slow'. + * 'full' - fast (as above) and slow tests as in the + 'no -A' option to nosetests - this is the same as ''. + * None or '' - run all tests. attribute_identifier - string passed directly to nosetests as '-A'. verbose : int, optional Verbosity value for test outputs, in the range 1-10. Default is 1. @@ -336,18 +321,17 @@ class NoseTester(object): Parameters ---------- label : {'fast', 'full', '', attribute identifier}, optional - Identifies the tests to run. This can be a string to pass to the - nosetests executable with the '-A' option, or one of - several special values. - Special values are: - 'fast' - the default - which corresponds to the ``nosetests -A`` - option of 'not slow'. - 'full' - fast (as above) and slow tests as in the - 'no -A' option to nosetests - this is the same as ''. - None or '' - run all tests. + Identifies the benchmarks to run. This can be a string to pass to + the nosetests executable with the '-A' option, or one of several + special values. Special values are: + * 'fast' - the default - which corresponds to the ``nosetests -A`` + option of 'not slow'. + * 'full' - fast (as above) and slow benchmarks as in the + 'no -A' option to nosetests - this is the same as ''. + * None or '' - run all tests. attribute_identifier - string passed directly to nosetests as '-A'. verbose : int, optional - Verbosity value for test outputs, in the range 1-10. Default is 1. + Verbosity value for benchmark outputs, in the range 1-10. Default is 1. extra_argv : list, optional List with any extra arguments to pass to nosetests. @@ -392,13 +376,14 @@ class NoseTester(object): argv = self._test_argv(label, verbose, extra_argv) argv += ['--match', r'(?:^|[\\b_\\.%s-])[Bb]ench' % os.sep] + # import nose or make informative error nose = import_nose() - return nose.run(argv=argv) - # generate method docstrings - _docmethod(_test_argv, '(testtype)') - _docmethod(test, 'test') - _docmethod(bench, 'benchmark') + # get plugin to disable doctests + from noseclasses import Unplugger + add_plugins = [Unplugger('doctest')] + + return nose.run(argv=argv, addplugins=add_plugins) ######################################################################## |