numpy.testing.noseclasses
index
/usr/lib/python2.6/dist-packages/numpy/testing/noseclasses.py

# These classes implement a doctest runner plugin for nose, a "known failure"
# error class, and a customized TestProgram for NumPy.

 
Modules
       
doctest
inspect
nose
nose.plugins.doctests
numpy
os

 
Classes
       
DocTestFinder
NumpyDocTestFinder
OutputChecker
NumpyOutputChecker
Exception(BaseException)
KnownFailureTest
TestProgram(TestProgram)
NumpyTestProgram
DocTestCase(DocTestCase)
NumpyDocTestCase
Doctest(Plugin)
NumpyDoctest
ErrorClassPlugin(Plugin)
KnownFailure

 
class KnownFailure(ErrorClassPlugin)
    Plugin that installs a KNOWNFAIL error class for the
KnownFailureClass exception.  When KnownFailureTest is raised,
the exception will be logged in the knownfail attribute of the
result, 'K' or 'KNOWNFAIL' (verbose) will be output, and the
exception will not be counted as an error or failure.
 
 
Method resolution order:
KnownFailure
ErrorClassPlugin
Plugin
object

Methods defined here:
configure(self, options, conf)
options(self, parser, env={'LESS': '-d', 'WINDOWPATH': '7', 'LIBGL_DRIVERS...dent', 'PAGER': 'most', 'KDE_MULTIHEAD': 'false'})

Data and other attributes defined here:
enabled = True
errorClasses = ((<class 'numpy.testing.noseclasses.KnownFailureTest'>, ('knownfail', 'KNOWNFAIL', False)),)
knownfail = <nose.plugins.errorclass.ErrorClass object at 0x6f79bd0>

Methods inherited from ErrorClassPlugin:
addError(self, test, err)
patchResult(self, result)
prepareTestResult(self, result)

Data and other attributes inherited from ErrorClassPlugin:
__metaclass__ = <class 'nose.plugins.errorclass.MetaErrorClass'>
Metaclass for ErrorClassPlugins that allows error classes to be
set up in a declarative manner.
score = 1000

Methods inherited from Plugin:
__init__(self)
addOptions(self, parser, env=None)
Add command-line options for this plugin.
 
The base plugin class adds --with-$name by default, used to enable the
plugin.
 
.. warning :: Don't implement addOptions unless you want to override
              all default option handling behavior, including
              warnings for conflicting options. Implement
              :meth:`options
              <nose.plugins.base.IPluginInterface.options>`
              instead.
add_options(self, parser, env=None)
Non-camel-case version of func name for backwards compatibility.
 
.. warning ::
 
   DEPRECATED: Do not use this method,
   use :meth:`options <nose.plugins.base.IPluginInterface.options>`
   instead.
help(self)
Return help for this plugin. This will be output as the help
section of the --with-$name option that enables the plugin.
tolist(self, val)
# Compatiblity shim

Data descriptors inherited from Plugin:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

Data and other attributes inherited from Plugin:
can_configure = False
enableOpt = None
name = None

 
class KnownFailureTest(Exception)
    Raise this exception to mark a test as a known failing test.
 
 
Method resolution order:
KnownFailureTest
Exception
BaseException
object

Data descriptors defined here:
__weakref__
list of weak references to the object (if defined)

Methods inherited from Exception:
__init__(...)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature

Data and other attributes inherited from Exception:
__new__ = <built-in method __new__ of type object at 0x8108c0>
T.__new__(S, ...) -> a new object with type S, a subtype of T

Methods inherited from BaseException:
__delattr__(...)
x.__delattr__('name') <==> del x.name
__getattribute__(...)
x.__getattribute__('name') <==> x.name
__getitem__(...)
x.__getitem__(y) <==> x[y]
__getslice__(...)
x.__getslice__(i, j) <==> x[i:j]
 
Use of negative indices is not supported.
__reduce__(...)
__repr__(...)
x.__repr__() <==> repr(x)
__setattr__(...)
x.__setattr__('name', value) <==> x.name = value
__setstate__(...)
__str__(...)
x.__str__() <==> str(x)
__unicode__(...)

Data descriptors inherited from BaseException:
__dict__
args
message

 
class NumpyDocTestCase(DocTestCase)
    
Method resolution order:
NumpyDocTestCase
DocTestCase
DocTestCase
TestCase
object

Methods defined here:
__init__(self, test, optionflags=0, setUp=None, tearDown=None, checker=None, obj=None, result_var='_')

Methods inherited from DocTestCase:
__repr__(self)
__str__ = __repr__(self)
address(self)
id(self)
# doctests loaded via find(obj) omit the module name
# so we need to override id, __repr__ and shortDescription
# bonus: this will squash a 2.3 vs 2.4 incompatiblity
setUp(self)
shortDescription(self)
tearDown(self)

Methods inherited from DocTestCase:
debug(self)
Run the test case without results and without catching exceptions
 
The unit test framework includes a debug method on test cases
and test suites to support post-mortem debugging.  The test code
is run in such a way that errors are not caught.  This way a
caller can catch the errors and initiate post-mortem debugging.
 
The DocTestCase provides a debug method that raises
UnexpectedException errors if there is an unexepcted
exception:
 
  >>> test = DocTestParser().get_doctest('>>> raise KeyError\n42',
  ...                {}, 'foo', 'foo.py', 0)
  >>> case = DocTestCase(test)
  >>> try:
  ...     case.debug()
  ... except UnexpectedException, failure:
  ...     pass
 
The UnexpectedException contains the test, the example, and
the original exception:
 
  >>> failure.test is test
  True
 
  >>> failure.example.want
  '42\n'
 
  >>> exc_info = failure.exc_info
  >>> raise exc_info[0], exc_info[1], exc_info[2]
  Traceback (most recent call last):
  ...
  KeyError
 
If the output doesn't match, then a DocTestFailure is raised:
 
  >>> test = DocTestParser().get_doctest('''
  ...      >>> x = 1
  ...      >>> x
  ...      2
  ...      ''', {}, 'foo', 'foo.py', 0)
  >>> case = DocTestCase(test)
 
  >>> try:
  ...    case.debug()
  ... except DocTestFailure, failure:
  ...    pass
 
DocTestFailure objects provide access to the test:
 
  >>> failure.test is test
  True
 
As well as to the example:
 
  >>> failure.example.want
  '2\n'
 
and the actual output:
 
  >>> failure.got
  '1\n'
format_failure(self, err)
runTest(self)

Methods inherited from TestCase:
__call__(self, *args, **kwds)
__eq__(self, other)
__hash__(self)
__ne__(self, other)
assertAlmostEqual = failUnlessAlmostEqual(self, first, second, places=7, msg=None)
Fail if the two objects are unequal as determined by their
difference rounded to the given number of decimal places
(default 7) and comparing to zero.
 
Note that decimal places (from zero) are usually not the same
as significant digits (measured from the most signficant digit).
assertAlmostEquals = failUnlessAlmostEqual(self, first, second, places=7, msg=None)
Fail if the two objects are unequal as determined by their
difference rounded to the given number of decimal places
(default 7) and comparing to zero.
 
Note that decimal places (from zero) are usually not the same
as significant digits (measured from the most signficant digit).
assertEqual = failUnlessEqual(self, first, second, msg=None)
Fail if the two objects are unequal as determined by the '=='
operator.
assertEquals = failUnlessEqual(self, first, second, msg=None)
Fail if the two objects are unequal as determined by the '=='
operator.
assertFalse = failIf(self, expr, msg=None)
Fail the test if the expression is true.
assertNotAlmostEqual = failIfAlmostEqual(self, first, second, places=7, msg=None)
Fail if the two objects are equal as determined by their
difference rounded to the given number of decimal places
(default 7) and comparing to zero.
 
Note that decimal places (from zero) are usually not the same
as significant digits (measured from the most signficant digit).
assertNotAlmostEquals = failIfAlmostEqual(self, first, second, places=7, msg=None)
Fail if the two objects are equal as determined by their
difference rounded to the given number of decimal places
(default 7) and comparing to zero.
 
Note that decimal places (from zero) are usually not the same
as significant digits (measured from the most signficant digit).
assertNotEqual = failIfEqual(self, first, second, msg=None)
Fail if the two objects are equal as determined by the '=='
operator.
assertNotEquals = failIfEqual(self, first, second, msg=None)
Fail if the two objects are equal as determined by the '=='
operator.
assertRaises = failUnlessRaises(self, excClass, callableObj, *args, **kwargs)
Fail unless an exception of class excClass is thrown
by callableObj when invoked with arguments args and keyword
arguments kwargs. If a different type of exception is
thrown, it will not be caught, and the test case will be
deemed to have suffered an error, exactly as for an
unexpected exception.
assertTrue = failUnless(self, expr, msg=None)
Fail the test unless the expression is true.
assert_ = failUnless(self, expr, msg=None)
Fail the test unless the expression is true.
countTestCases(self)
defaultTestResult(self)
fail(self, msg=None)
Fail immediately, with the given message.
failIf(self, expr, msg=None)
Fail the test if the expression is true.
failIfAlmostEqual(self, first, second, places=7, msg=None)
Fail if the two objects are equal as determined by their
difference rounded to the given number of decimal places
(default 7) and comparing to zero.
 
Note that decimal places (from zero) are usually not the same
as significant digits (measured from the most signficant digit).
failIfEqual(self, first, second, msg=None)
Fail if the two objects are equal as determined by the '=='
operator.
failUnless(self, expr, msg=None)
Fail the test unless the expression is true.
failUnlessAlmostEqual(self, first, second, places=7, msg=None)
Fail if the two objects are unequal as determined by their
difference rounded to the given number of decimal places
(default 7) and comparing to zero.
 
Note that decimal places (from zero) are usually not the same
as significant digits (measured from the most signficant digit).
failUnlessEqual(self, first, second, msg=None)
Fail if the two objects are unequal as determined by the '=='
operator.
failUnlessRaises(self, excClass, callableObj, *args, **kwargs)
Fail unless an exception of class excClass is thrown
by callableObj when invoked with arguments args and keyword
arguments kwargs. If a different type of exception is
thrown, it will not be caught, and the test case will be
deemed to have suffered an error, exactly as for an
unexpected exception.
run(self, result=None)

Data descriptors inherited from TestCase:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

Data and other attributes inherited from TestCase:
failureException = <type 'exceptions.AssertionError'>
Assertion failed.

 
class NumpyDocTestFinder(DocTestFinder)
    #-----------------------------------------------------------------------------
# Modified version of the one in the stdlib, that fixes a python bug (doctests
# not found in extension modules, http://bugs.python.org/issue3158)
 
  Methods inherited from DocTestFinder:
__init__(self, verbose=False, parser=<doctest.DocTestParser instance at 0x6dbab90>, recurse=True, exclude_empty=True)
Create a new doctest finder.
 
The optional argument `parser` specifies a class or
function that should be used to create new DocTest objects (or
objects that implement the same interface as DocTest).  The
signature for this factory function should match the signature
of the DocTest constructor.
 
If the optional argument `recurse` is false, then `find` will
only examine the given object, and not any contained objects.
 
If the optional argument `exclude_empty` is false, then `find`
will include tests for objects with empty docstrings.
find(self, obj, name=None, module=None, globs=None, extraglobs=None)
Return a list of the DocTests that are defined by the given
object's docstring, or by any of its contained objects'
docstrings.
 
The optional parameter `module` is the module that contains
the given object.  If the module is not specified or is None, then
the test finder will attempt to automatically determine the
correct module.  The object's module is used:
 
    - As a default namespace, if `globs` is not specified.
    - To prevent the DocTestFinder from extracting DocTests
      from objects that are imported from other modules.
    - To find the name of the file containing the object.
    - To help find the line number of the object within its
      file.
 
Contained objects whose module does not match `module` are ignored.
 
If `module` is False, no attempt to find the module will be made.
This is obscure, of use mostly in tests:  if `module` is False, or
is None but cannot be found automatically, then all objects are
considered to belong to the (non-existent) module, so all contained
objects will (recursively) be searched for doctests.
 
The globals for each DocTest is formed by combining `globs`
and `extraglobs` (bindings in `extraglobs` override bindings
in `globs`).  A new copy of the globals dictionary is created
for each DocTest.  If `globs` is not specified, then it
defaults to the module's `__dict__`, if specified, or {}
otherwise.  If `extraglobs` is not specified, then it defaults
to {}.

 
class NumpyDoctest(Doctest)
    
Method resolution order:
NumpyDoctest
Doctest
Plugin
object

Methods defined here:
afterContext(self)
# Add an afterContext method to nose.plugins.doctests.Doctest in order
# to restore print options to the original state after each doctest
configure(self, options, config)
loadTestsFromModule(self, module)
# Turn on whitespace normalization, set a minimal execution context
# for doctests, implement a "#random" directive to allow executing a
# command while ignoring its output.
options(self, parser, env={'LESS': '-d', 'WINDOWPATH': '7', 'LIBGL_DRIVERS...dent', 'PAGER': 'most', 'KDE_MULTIHEAD': 'false'})
wantFile(self, file)
# Ignore NumPy-specific build files that shouldn't be searched for tests

Data and other attributes defined here:
enabled = True
name = 'numpydoctest'

Methods inherited from Doctest:
loadTestsFromFile(self, filename)
Load doctests from the file.
 
Tests are loaded only if filename's extension matches
configured doctest extension.
makeTest(self, obj, parent)
Look for doctests in the given object, which will be a
function, method or class.
matches(self, name)
prepareTestLoader(self, loader)
Capture loader's suiteClass.
 
This is used to create test suites from doctest files.

Data and other attributes inherited from Doctest:
extension = None
suiteClass = <class 'nose.plugins.doctests.DoctestSuite'>
Doctest suites are parallelizable at the module or file level only,
since they may be attached to objects that are not individually
addressable (like properties). This suite subclass is used when
loading doctests from a module to ensure that behavior.
 
This class is used only if the plugin is not fully prepared;
in normal use, the loader's suiteClass is used.

Methods inherited from Plugin:
__init__(self)
addOptions(self, parser, env=None)
Add command-line options for this plugin.
 
The base plugin class adds --with-$name by default, used to enable the
plugin.
 
.. warning :: Don't implement addOptions unless you want to override
              all default option handling behavior, including
              warnings for conflicting options. Implement
              :meth:`options
              <nose.plugins.base.IPluginInterface.options>`
              instead.
add_options(self, parser, env=None)
Non-camel-case version of func name for backwards compatibility.
 
.. warning ::
 
   DEPRECATED: Do not use this method,
   use :meth:`options <nose.plugins.base.IPluginInterface.options>`
   instead.
help(self)
Return help for this plugin. This will be output as the help
section of the --with-$name option that enables the plugin.
tolist(self, val)
# Compatiblity shim

Data descriptors inherited from Plugin:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

Data and other attributes inherited from Plugin:
can_configure = False
enableOpt = None
score = 100

 
class NumpyOutputChecker(OutputChecker)
    # second-chance checker; if the default comparison doesn't
# pass, then see if the expected output string contains flags that
# tell us to ignore the output
 
  Methods defined here:
check_output(self, want, got, optionflags)

Methods inherited from OutputChecker:
output_difference(self, example, got, optionflags)
Return a string describing the differences between the
expected output for a given example (`example`) and the actual
output (`got`).  `optionflags` is the set of option flags used
to compare `want` and `got`.

 
class NumpyTestProgram(TestProgram)
    # Because nose currently discards the test result object, but we need
# to return it to the user, override TestProgram.runTests to retain
# the result
 
 
Method resolution order:
NumpyTestProgram
TestProgram
TestProgram
object

Methods defined here:
runTests(self)
Run Tests. Returns true on success, false on failure, and
sets self.success to the same value.

Methods inherited from TestProgram:
__init__(self, module=None, defaultTest='.', argv=None, testRunner=None, testLoader=None, env=None, config=None, suite=None, exit=True, plugins=None, addplugins=None)
createTests(self)
Create the tests to run. If a self.suite
is set, then that suite will be used. Otherwise, tests will be
loaded from the given test names (self.testNames) using the
test loader.
makeConfig(self, env, plugins=None)
Load a Config, pre-filled with user config files if any are
found.
parseArgs(self, argv)
Parse argv and env and configure running environment.
showPlugins(self)
Print list of available plugins.

Class methods inherited from TestProgram:
usage(cls) from type

Data and other attributes inherited from TestProgram:
verbosity = 1

Methods inherited from TestProgram:
usageExit(self, msg=None)

Data descriptors inherited from TestProgram:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

Data and other attributes inherited from TestProgram:
USAGE = 'Usage: %(progName)s [options] [test] [...]\n\nOpti... in MyTestCase\n'

 
Data
        __file__ = '/usr/lib/python2.6/dist-packages/numpy/testing/noseclasses.pyc'
__name__ = 'numpy.testing.noseclasses'
__package__ = 'numpy.testing'
_doctest_ignore = ['generate_numpy_api.py', 'scons_support.py', 'setupscons.py', 'setup.py']
print_state = {'edgeitems': 3, 'infstr': 'Inf', 'linewidth': 75, 'nanstr': 'NaN', 'precision': 8, 'suppress': False, 'threshold': 1000}