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/noseclasses.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/noseclasses.py')
-rw-r--r-- | numpy/testing/noseclasses.py | 66 |
1 files changed, 31 insertions, 35 deletions
diff --git a/numpy/testing/noseclasses.py b/numpy/testing/noseclasses.py index f97ea9126..25f6662b7 100644 --- a/numpy/testing/noseclasses.py +++ b/numpy/testing/noseclasses.py @@ -185,16 +185,24 @@ print_state = numpy.get_printoptions() class NumpyDoctest(npd.Doctest): name = 'numpydoctest' # call nosetests with --with-numpydoctest - enabled = True + score = 1000 # load late, after doctest builtin def options(self, parser, env=os.environ): Plugin.options(self, parser, env) def configure(self, options, config): + # parent method sets enabled flag from command line --with-numpydoctest Plugin.configure(self, options, config) self.doctest_tests = True self.finder = NumpyDocTestFinder() self.parser = doctest.DocTestParser() + if self.enabled: + # Pull standard doctest out of plugin list; there's no reason to run + # both. In practice the Unplugger plugin above would cover us when + # run from a standard numpy.test() call; this is just in case + # someone wants to run our plugin outside the numpy.test() machinery + config.plugins.plugins = [p for p in config.plugins.plugins + if p.name != 'doctest'] # Turn on whitespace normalization, set a minimal execution context # for doctests, implement a "#random" directive to allow executing a @@ -263,6 +271,27 @@ class NumpyDoctest(npd.Doctest): return npd.Doctest.wantFile(self, file) +class Unplugger(object): + """ Nose plugin to remove named plugin late in loading + + By default it removes the "doctest" plugin. + """ + name = 'unplugger' + enabled = True # always enabled + score = 4000 # load late in order to be after builtins + + def __init__(self, to_unplug='doctest'): + self.to_unplug = to_unplug + + def options(self, parser, env): + pass + + def configure(self, options, config): + # Pull named plugin out of plugins list + config.plugins.plugins = [p for p in config.plugins.plugins + if p.name != self.to_unplug] + + class KnownFailureTest(Exception): '''Raise this exception to mark a test as a known failing test.''' pass @@ -295,41 +324,9 @@ class KnownFailure(ErrorClassPlugin): self.enabled = False -class NpConfig(nose.core.Config): - ''' Class to pull out nose doctest plugin after configuration - - This allows the user to set doctest related settings in their - configuration. For example, without this fix, a setting of - 'with-doctest=1' in the user's .noserc file would cause an error, if - we remove the doctest extension before this stage. Our configure - uses the plugin to parse any settings, but then removed the doctest - plugin because the numpy doctester should be used for doctests - instead. - ''' - def __init__(self, config): - self.__dict__ = config.__dict__ - - def configure(self, *args, **kwargs): - super(NpConfig, self).configure(*args, **kwargs) - self.plugins.plugins = [p for p in self.plugins.plugins - if p.name != 'doctest'] - - -# Our class has two uses. First, to allow us to use NpConfig above to -# remove the doctest plugin after it has parsed the configuration. -# Second we save the results of the tests in runTests - see runTests +# Class allows us to save the results of the tests in runTests - see runTests # method docstring for details class NumpyTestProgram(nose.core.TestProgram): - def makeConfig(self, *args, **kwargs): - """Load a Config, pre-filled with user config files if any are - found. - - We override this method only to allow us to return a NpConfig - object instead of a Config object. - """ - config = super(NumpyTestProgram, self).makeConfig(*args, **kwargs) - return NpConfig(config) - def runTests(self): """Run Tests. Returns true on success, false on failure, and sets self.success to the same value. @@ -345,7 +342,6 @@ class NumpyTestProgram(nose.core.TestProgram): plug_runner = self.config.plugins.prepareTestRunner(self.testRunner) if plug_runner is not None: self.testRunner = plug_runner - self.result = self.testRunner.run(self.test) self.success = self.result.wasSuccessful() return self.success |