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.NumpyDoctestAttributes
enableOptextensionMethods
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_classalias of NumpyDocTestCasehelp()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_classalias of NipyOutputCheckerprepareTestLoader(loader)Capture loader’s suiteClass. set_test_context(test)suiteClassalias of DoctestSuitetest_finder_classalias of NumpyDocTestFindertolist(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
optionsinstead.
-
add_options(parser, env=None)¶ Non-camel-case version of func name for backwards compatibility.
Warning
DEPRECATED: Do not use this method, use
optionsinstead.
-
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': 'armhf', 'DEB_BUILD_GNU_SYSTEM': 'linux-gnueabihf', 'DEB_BUILD_MULTIARCH': 'arm-linux-gnueabihf', 'DEB_TARGET_MULTIARCH': 'arm-linux-gnueabihf', 'DEB_HOST_GNU_TYPE': 'arm-linux-gnueabihf', 'DEB_BUILD_ARCH_OS': 'linux', 'DEB_TARGET_GNU_CPU': 'arm', 'DEB_BUILD_ARCH_CPU': 'arm', 'DEB_BUILD_OPTIONS': 'parallel=4', 'DEB_TARGET_ARCH_CPU': 'arm', 'DEB_HOST_ARCH_LIBC': 'gnu', 'SSH_CLIENT': '192.168.1.2 34360 22', 'MAKE_TERMERR': '/dev/pts/3', 'MPLCONFIGDIR': '/nipy-0.4.0+git26-gf8d3149/build', 'DEB_BUILD_ARCH_LIBC': 'gnu', 'HOME': '/nipy-0.4.0+git26-gf8d3149/build', 'DEB_HOST_ARCH': 'armhf', 'PATH': '/nipy-0.4.0+git26-gf8d3149/debian/tmp/usr/bin/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', 'DEB_TARGET_ARCH': 'armhf', 'MAKEFLAGS': 'w', 'DEB_HOST_ARCH_ENDIAN': 'little', 'LANG': 'en_GB.UTF-8', 'DEB_BUILD_ARCH_BITS': '32', 'TERM': 'screen', 'SHELL': '/bin/bash', 'DEB_TARGET_ARCH_LIBC': 'gnu', 'LANGUAGE': 'en_GB:en', 'MAKELEVEL': '2', 'SHLVL': '3', 'DEB_HOST_GNU_CPU': 'arm', 'WINDOW': '0', 'DEB_BUILD_ARCH_ABI': 'eabihf', 'DEB_HOST_MULTIARCH': 'arm-linux-gnueabihf', 'PYTHONPATH': '/nipy-0.4.0+git26-gf8d3149/build/lib.linux-armv7l-2.7', 'DEB_TARGET_GNU_TYPE': 'arm-linux-gnueabihf', 'DEB_HOST_ARCH_ABI': 'eabihf', 'MFLAGS': '-w', 'SOURCE_DATE_EPOCH': '1509764862', 'DEB_BUILD_GNU_TYPE': 'arm-linux-gnueabihf', 'MAKE_TERMOUT': '/dev/pts/3', 'DH_VERBOSE': '1', 'DEB_HOST_ARCH_BITS': '32', 'SSH_AUTH_SOCK': '/tmp/ssh-6Tu4KSLzde/agent.25045', 'DEB_HOST_ARCH_OS': 'linux', 'MAIL': '/var/mail/root', 'STY': '25063.pts-0.cuboxi4x4', '_': '/usr/bin/dpkg-buildpackage', 'TERMCAP': 'SC|screen|VT 100/ANSI X3.64 virtual terminal:\\\n\t:DO=\\E[%dB:LE=\\E[%dD:RI=\\E[%dC:UP=\\E[%dA:bs:bt=\\E[Z:\\\n\t:cd=\\E[J:ce=\\E[K:cl=\\E[H\\E[J:cm=\\E[%i%d;%dH:ct=\\E[3g:\\\n\t:do=^J:nd=\\E[C:pt:rc=\\E8:rs=\\Ec:sc=\\E7:st=\\EH:up=\\EM:\\\n\t:le=^H:bl=^G:cr=^M:it#8:ho=\\E[H:nw=\\EE:ta=^I:is=\\E)0:\\\n\t:li#24:co#80:am:xn:xv:LP:sr=\\EM:al=\\E[L:AL=\\E[%dL:\\\n\t:cs=\\E[%i%d;%dr:dl=\\E[M:DL=\\E[%dM:dc=\\E[P:DC=\\E[%dP:\\\n\t:im=\\E[4h:ei=\\E[4l:mi:IC=\\E[%d@:ks=\\E[?1h\\E=:\\\n\t:ke=\\E[?1l\\E>:vi=\\E[?25l:ve=\\E[34h\\E[?25h:vs=\\E[34l:\\\n\t:ti=\\E[?1049h:te=\\E[?1049l:us=\\E[4m:ue=\\E[24m:so=\\E[3m:\\\n\t:se=\\E[23m:mb=\\E[5m:md=\\E[1m:mh=\\E[2m:mr=\\E[7m:\\\n\t:me=\\E[m:ms:\\\n\t:Co#8:pa#64:AF=\\E[3%dm:AB=\\E[4%dm:op=\\E[39;49m:AX:\\\n\t:vb=\\Eg:G0:as=\\E(0:ae=\\E(B:\\\n\t:ac=\\140\\140aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~..--++, hhII00:\\\n\t:po=\\E[5i:pf=\\E[4i:Km=\\E[M:k0=\\E[10~:k1=\\EOP:k2=\\EOQ:\\\n\t:k3=\\EOR:k4=\\EOS:k5=\\E[15~:k6=\\E[17~:k7=\\E[18~:\\\n\t:k8=\\E[19~:k9=\\E[20~:k;=\\E[21~:F1=\\E[23~:F2=\\E[24~:\\\n\t:F3=\\E[1;2P:F4=\\E[1;2Q:F5=\\E[1;2R:F6=\\E[1;2S:\\\n\t:F7=\\E[15;2~:F8=\\E[17;2~:F9=\\E[18;2~:FA=\\E[19;2~:\\\n\t:FB=\\E[20;2~:FC=\\E[21;2~:FD=\\E[23;2~:FE=\\E[24;2~:kb=\x7f:\\\n\t:K2=\\EOE:kB=\\E[Z:kF=\\E[1;2B:kR=\\E[1;2A:*4=\\E[3;2~:\\\n\t:*7=\\E[1;2F:#2=\\E[1;2H:#3=\\E[2;2~:#4=\\E[1;2D:%c=\\E[6;2~:\\\n\t:%e=\\E[5;2~:%i=\\E[1;2C:kh=\\E[1~:@1=\\E[1~:kH=\\E[4~:\\\n\t:@7=\\E[4~:kN=\\E[6~:kP=\\E[5~:kI=\\E[2~:kD=\\E[3~:ku=\\EOA:\\\n\t:kd=\\EOB:kr=\\EOC:kl=\\EOD:km:', 'DEB_TARGET_GNU_SYSTEM': 'linux-gnueabihf', 'DEB_BUILD_ARCH_ENDIAN': 'little', 'SSH_TTY': '/dev/pts/0', 'OLDPWD': '/nipy-0.4.0+git26-gf8d3149', 'DEB_HOST_ARCH_CPU': 'arm', 'DEB_TARGET_ARCH_BITS': '32', 'PWD': '/nipy-0.4.0+git26-gf8d3149/doc', 'DEB_BUILD_GNU_CPU': 'arm', 'DEB_TARGET_ARCH_ENDIAN': 'little', 'LOGNAME': 'root', 'DEB_HOST_GNU_SYSTEM': 'linux-gnueabihf', 'SSH_CONNECTION': '192.168.1.2 34360 192.168.1.49 22', 'DEB_TARGET_ARCH_OS': 'linux', 'DEB_TARGET_ARCH_ABI': 'eabihf', 'USER': 'root'})¶
-
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.NumpyOutputCheckerMethods
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_DTYPEdoctest 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]'