testing.doctester¶
Module: testing.doctester
¶
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.
Classes¶
NipyDoctest
¶
-
class
nipy.testing.doctester.
NipyDoctest
¶ 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 NumpyDocTestFinder
tolist
(val)wantFile
(file)-
__init__
()¶
-
addOptions
(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
options
instead.
-
add_options
(parser, env=None)¶ Non-camel-case version of func name for backwards compatibility.
Warning
DEPRECATED: Do not use this method, use
options
instead.
-
afterContext
()¶
-
can_configure
= False¶
-
configure
(options, config)¶
-
doctest_case_class
¶ alias of
NumpyDocTestCase
-
doctest_ignore
= ['generate_numpy_api.py', 'setup.py']¶
-
doctest_optflags
= 12¶
-
enableOpt
= None¶
-
enabled
= False¶
-
extension
= None¶
-
help
()¶ Return help for this plugin. This will be output as the help section of the –with-$name option that enables the plugin.
-
loadTestsFromFile
(filename)¶ Load doctests from the file.
Tests are loaded only if filename’s extension matches configured doctest extension.
-
loadTestsFromModule
(module)¶
-
makeTest
(obj, parent)¶ Look for doctests in the given object, which will be a function, method or class.
-
matches
(name)¶
-
name
= 'nipydoctest'¶
-
options
(parser, env={'DEB_BUILD_ARCH': 'amd64', 'DEB_BUILD_GNU_SYSTEM': 'linux-gnu', 'DEB_BUILD_MULTIARCH': 'x86_64-linux-gnu', 'DEB_TARGET_MULTIARCH': 'x86_64-linux-gnu', 'DEB_HOST_GNU_TYPE': 'x86_64-linux-gnu', 'DEB_BUILD_ARCH_OS': 'linux', 'DEB_TARGET_GNU_CPU': 'x86_64', 'DEB_BUILD_ARCH_CPU': 'amd64', 'DEB_TARGET_ARCH_CPU': 'amd64', 'FAKEROOTKEY': '883924502', 'MPLCONFIGDIR': '/build/nipy-J8v1YU/nipy-0.4.0+git26-gf8d3149/build', 'USER': 'buildd', 'PATH': '/build/nipy-J8v1YU/nipy-0.4.0+git26-gf8d3149/debian/tmp/usr/bin/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games', 'DEB_HOST_ARCH': 'amd64', 'HOME': '/build/nipy-J8v1YU/nipy-0.4.0+git26-gf8d3149/build', 'DEB_TARGET_ARCH': 'amd64', 'LD_LIBRARY_PATH': '/usr/lib/x86_64-linux-gnu/libfakeroot:/usr/lib64/libfakeroot:/usr/lib32/libfakeroot', 'MAKEFLAGS': 'w', 'DEB_HOST_ARCH_ENDIAN': 'little', 'LANG': 'C.UTF-8', 'DEB_BUILD_ARCH_BITS': '64', 'TERM': 'unknown', 'SHELL': '/bin/sh', 'DEB_BUILD_ARCH_ENDIAN': 'little', 'MAKELEVEL': '2', 'SHLVL': '1', 'DEB_TARGET_GNU_TYPE': 'x86_64-linux-gnu', 'DEB_HOST_GNU_CPU': 'x86_64', 'DEB_HOST_MULTIARCH': 'x86_64-linux-gnu', 'PYTHONPATH': '/build/nipy-J8v1YU/nipy-0.4.0+git26-gf8d3149/build/lib.linux-x86_64-2.7', 'SUDO_USER': 'buildd', 'MFLAGS': '-w', 'SOURCE_DATE_EPOCH': '1470279248', 'DEB_BUILD_GNU_TYPE': 'x86_64-linux-gnu', 'USERNAME': 'root', 'DH_VERBOSE': '1', 'DEB_HOST_ARCH_BITS': '64', 'SUDO_UID': '2001', 'FAKED_MODE': 'unknown-is-root', 'DEB_HOST_ARCH_OS': 'linux', 'MAIL': '/var/mail/buildd', 'DEB_BUILD_OPTIONS': 'parallel=4', '_': 'debian/rules', 'LD_PRELOAD': 'libfakeroot-sysv.so', 'SUDO_COMMAND': "/usr/sbin/chroot /home/buildd/build-PACKAGEBUILD-10568103/chroot-autobuild su buildd -s /bin/sh -c cd '/build/nipy-J8v1YU/nipy-0.4.0+git26-gf8d3149' && 'dpkg-buildpackage' '-us' '-uc' '-mLaunchpad Build Daemon <buildd@lcy01-13.buildd>' '-b' '-rfakeroot'", 'SUDO_GID': '2501', 'OLDPWD': '/build/nipy-J8v1YU/nipy-0.4.0+git26-gf8d3149', 'DEB_HOST_ARCH_CPU': 'amd64', 'DEB_TARGET_ARCH_BITS': '64', 'PWD': '/build/nipy-J8v1YU/nipy-0.4.0+git26-gf8d3149/doc', 'DEB_BUILD_GNU_CPU': 'x86_64', 'LOGNAME': 'buildd', 'DEB_HOST_GNU_SYSTEM': 'linux-gnu', 'DEB_TARGET_GNU_SYSTEM': 'linux-gnu', 'DEB_TARGET_ARCH_OS': 'linux', 'DEB_TARGET_ARCH_ENDIAN': 'little'})¶
-
out_check_class
¶ alias of
NipyOutputChecker
-
prepareTestLoader
(loader)¶ Capture loader’s suiteClass.
This is used to create test suites from doctest files.
-
score
= 1000¶
-
set_test_context
(test)¶
-
suiteClass
¶ alias of
DoctestSuite
-
test_finder_class
¶ alias of
NumpyDocTestFinder
-
tolist
(val)¶
-
wantFile
(file)¶
-
NipyOutputChecker
¶
-
class
nipy.testing.doctester.
NipyOutputChecker
¶ 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). -
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). optionflags is the set of option flags used to compare want and got.
-
Functions¶
-
nipy.testing.doctester.
ignore_dtype
(in_str)¶ Removes dtype=[dtype] from string in_str
Parameters: in_str : str
String maybe containing dtype specifier
Returns: out_str : str
String from which the dtype specifier has been removed.
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'
-
nipy.testing.doctester.
round_numbers
(in_str, precision)¶ Replace fp numbers in in_str with numbers rounded to precision
Parameters: in_str : str
string possibly containing floating point numbers
precision : int
number of decimal places to round to
Returns: out_str : str
in_str with any floating point numbers replaced with same numbers rounded to precision decimal places.
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")'
-
nipy.testing.doctester.
strip_array_repr
(in_str)¶ 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 theIGNORE_DTYPE
doctest option.Parameters: in_str : str
String maybe containing a repr for an array
Returns: out_str : str
String from which the array specific parts of the repr have been removed.
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]'