Inheritance diagram for nipy.testing.doctester:
Custom doctester based on Numpy doctester
To run doctests via nose, you’ll need nosetests nipy/testing/doctester.py --doctest-test, because this file will be identified as containing tests.
Bases: nipy.fixes.numpy.testing.noseclasses.NumpyDocTestFinder
Methods
find(obj[, name, module, globs, extraglobs]) | Return a list of the DocTests that are defined by the given object’s docstring, or by any of its contained objects’ docstrings. |
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.
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 {}.
Bases: nipy.fixes.numpy.testing.noseclasses.NumpyDoctest
Attributes
enableOpt | |
extension |
Methods
addOptions(parser[, env]) | Add command-line options for this plugin. |
add_options(parser[, env]) | Non-camel-case version of func name for backwards compatibility. |
afterContext() | |
configure(options, config) | |
doctest_case_class | alias of NumpyDocTestCase |
help() | Return help for this plugin. |
loadTestsFromFile(filename) | Load doctests from the file. |
loadTestsFromModule(module) | |
makeTest(obj, parent) | Look for doctests in the given object, which will be a function, method or class. |
matches(name) | |
options(parser[, env]) | |
out_check_class | alias of NipyOutputChecker |
prepareTestLoader(loader) | Capture loader’s suiteClass. |
set_test_context(test) | |
suiteClass | alias of DoctestSuite |
test_finder_class | alias of NipyDocTestFinder |
tolist(val) | |
wantFile(file) |
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 options instead.
Non-camel-case version of func name for backwards compatibility.
Warning
DEPRECATED: Do not use this method, use options instead.
alias of NumpyDocTestCase
Return help for this plugin. This will be output as the help section of the –with-$name option that enables the plugin.
Load doctests from the file.
Tests are loaded only if filename’s extension matches configured doctest extension.
Look for doctests in the given object, which will be a function, method or class.
alias of NipyOutputChecker
Capture loader’s suiteClass.
This is used to create test suites from doctest files.
alias of DoctestSuite
alias of NipyDocTestFinder
Bases: nipy.fixes.numpy.testing.noseclasses.NumpyOutputChecker
Methods
check_output(want, got, optionflags) | |
output_difference(example, got, optionflags) | Return a string describing the differences between the expected output for a given example (example) and the actual output (got). |
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.
Removes dtype=[dtype] from string in_str
Parameters: | in_str : str
|
---|---|
Returns: | out_str : str
|
Examples
>>> arr = np.arange(5, dtype='i2')
Here’s the normal repr:
>>> arr
array([0, 1, 2, 3, 4], dtype=int16)
The repr with the dtype bits removed
>>> ignore_dtype(repr(arr))
'array([0, 1, 2, 3, 4])'
>>> ignore_dtype('something(again, dtype=something)')
'something(again)'
Even if there are more closed brackets after the dtype
>>> ignore_dtype('something(again, dtype=something) (1, 2)')
'something(again) (1, 2)'
We need the close brackets to match
>>> ignore_dtype('again, dtype=something')
'again, dtype=something'
Replace fp numbers in in_str with numbers rounded to precision
Parameters: | in_str : str
precision : int
|
---|---|
Returns: | out_str : str
|
Examples
>>> round_numbers('A=0.234, B=12.345', 2)
'A=0.23, B=12.35'
Rounds the floating point value as it finds it in the string. This is even true for numbers with exponentials. Remember that:
>>> '%.3f' % 0.3339e-10
'0.000'
This routine will recognize an exponential as something to process, but only works on the decimal part (leaving the exponential part is it is):
>>> round_numbers('(0.3339e-10, "string")', 3)
'(0.334e-10, "string")'
Removes array-specific part of repr from string in_str
This parser only works on lines that contain only an array repr (and therefore start with array, and end with a close parenthesis. To remove dtypes in array reprs that may be somewhere within the line, use the IGNORE_DTYPE doctest option.
Parameters: | in_str : str
|
---|---|
Returns: | out_str : str
|
Examples
>>> arr = np.arange(5, dtype='i2')
Here’s the normal repr:
>>> arr
array([0, 1, 2, 3, 4], dtype=int16)
The repr with the ‘array’ bits removed:
>>> strip_array_repr(repr(arr))
'[0, 1, 2, 3, 4]'