我们从Python开源项目中,提取了以下37个代码示例,用于说明如何使用numpy.test()。
def __init__(self, test, optionflags=0, setUp=None, tearDown=None, checker=None, obj=None, result_var='_'): self._result_var = result_var self._nose_obj = obj doctest.DocTestCase.__init__(self, test, optionflags=optionflags, setUp=setUp, tearDown=tearDown, checker=checker)
def options(self, parser, env=os.environ): Plugin.options(self, parser, env) # Test doctests in 'test' files / directories. Standard plugin default # is False self.doctest_tests = True # Variable name; if defined, doctest results stored in this variable in # the top-level namespace. None is the standard default self.doctest_result_var = None
def configure(self, options, config): # parent method sets enabled flag from command line --with-numpydoctest Plugin.configure(self, options, config) self.finder = self.test_finder_class() 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']
def loadTestsFromModule(self, module): if not self.matches(module.__name__): npd.log.debug("Doctest doesn't want module %s", module) return try: tests = self.finder.find(module) except AttributeError: # nose allows module.__test__ = False; doctest does not and # throws AttributeError return if not tests: return tests.sort() module_file = src(module.__file__) for test in tests: if not test.examples: continue if not test.filename: test.filename = module_file # Set test namespace; test altered in place self.set_test_context(test) yield self.doctest_case_class(test, optionflags=self.doctest_optflags, checker=self.out_check_class(), result_var=self.doctest_result_var) # Add an afterContext method to nose.plugins.doctests.Doctest in order # to restore print options to the original state after each doctest
def monkey_patch_doctest(): # # Doctest and coverage don't get along, so we need to create # a monkeypatch that will replace the part of doctest that # interferes with coverage reports. # # The monkeypatch is based on this zope patch: # http://svn.zope.org/Zope3/trunk/src/zope/testing/doctest.py?rev=28679&r1=28703&r2=28705 # try: import doctest _orp = doctest._OutputRedirectingPdb class NoseOutputRedirectingPdb(_orp): def __init__(self, out): self.__debugger_used = False _orp.__init__(self, out) def set_trace(self): self.__debugger_used = True _orp.set_trace(self) def set_continue(self): # Calling set_continue unconditionally would break unit test coverage # reporting, as Bdb.set_continue calls sys.settrace(None). if self.__debugger_used: _orp.set_continue(self) doctest._OutputRedirectingPdb = NoseOutputRedirectingPdb except: pass
def monkey_patch_numpy(): # Numpy pushes its tests into every importers namespace, yeccch. try: import numpy numpy.test = None except: pass
def set_test_context(self, test): """ Configure `test` object to set test context We set the numpy / scipy standard doctest namespace Parameters ---------- test : test object with ``globs`` dictionary defining namespace Returns ------- None Notes ----- `test` object modified in place """ # set the namespace for tests pkg_name = get_package_name(os.path.dirname(test.filename)) # Each doctest should execute in an environment equivalent to # starting Python and executing "import numpy as np", and, # for SciPy packages, an additional import of the local # package (so that scipy.linalg.basic.py's doctests have an # implicit "from scipy import linalg" as well. # # Note: __file__ allows the doctest in NoseTester to run # without producing an error test.globs = {'__builtins__':__builtins__, '__file__':'__main__', '__name__':'__main__', 'np':numpy} # add appropriate scipy import for SciPy tests if 'scipy' in pkg_name: p = pkg_name.split('.') p2 = p[-1] test.globs[p2] = __import__(pkg_name, test.globs, {}, [p2]) # Override test loading to customize test context (with set_test_context # method), set standard docstring options, and install our own test output # checker