testing Package

testing Package

doctest_support Module

Adpated from http://wiki.cython.org/FAQ#HowcanIrundoctestsinCythoncode.28pyxfiles.29.3F Use the testmod function from test_support, don’t use this directly. ====================================================================

Cython-compatible wrapper for doctest.testmod().

Usage example, assuming a Cython module mymod.pyx is compiled. This is run from the command line, passing a command to Python: python -c “import cydoctest, mymod; cydoctest.testmod(mymod)”

(This still won’t let a Cython module run its own doctests when called with “python mymod.py”, but it’s pretty close. Further options can be passed to testmod() as desired, e.g. verbose=True.)

class numba.testing.doctest_support.MyDocTestFinder(verbose=False, parser=<doctest.DocTestParser instance at 0x300cd88>, recurse=True, exclude_empty=True)

Bases: doctest.DocTestFinder

find(obj, **kws)

Extract docstrings from cython functions, that would be skipped by doctest otherwise.

numba.testing.doctest_support.from_module(module, object)

Return true if the given object is defined in the given module.

numba.testing.doctest_support.testmod(m=None, run_doctests=True, optionflags=12, verbosity=2)

Fix a Cython module’s doctests, then call doctest.testmod()

runner Module

class numba.testing.runner.FileFilter(matcher=None)

Bases: numba.testing.runner.Filter

filter(root, dirs, files)
class numba.testing.runner.Filter(matcher=None)

Bases: object

filter(root, dirs, files)
class numba.testing.runner.ModuleFilter(matcher=None)

Bases: numba.testing.runner.Filter

filter(root, dirs, files)
class numba.testing.runner.PackageFilter(matcher=None)

Bases: numba.testing.runner.Filter

filter(root, dirs, files)
class numba.testing.runner.TestRunner(print_failures_only)

Bases: object

Test runner used by runtests.py

class numba.testing.runner.Walker(root, filters)

Bases: object

numba.testing.runner.apply_filters(root, dirs, files, filters)
numba.testing.runner.make_path(root, predicate)

Call the predicate with a file path (e.g. numba/test/foo.py)

numba.testing.runner.match(items, modname)
numba.testing.runner.qualify_path(root, predicate)

Call the predicate with a dotted name (e.g. numba.tests.foo)

numba.testing.runner.run_tests(test_runner, filters, root='/home/mark/numba/numba')

Run tests:

  • Find tests in packages called ‘tests’
  • Run any test files under a ‘tests’ package or a subpackage
numba.testing.runner.test(whitelist=None, blacklist=None, print_failures_only=False, loop=False)

test_support Module

class numba.testing.test_support.ASTTestCase(methodName='runTest')

Bases: unittest.case.TestCase

static autojit(f)

Defines a numba function, that, when called, specializes on the input types. Uses the AST translator backend. For the bytecode translator, use @autojit.

backend = 'ast'
static jit(*args, **kw)
class numba.testing.test_support.StdoutReplacer

Bases: object


Rewrite docs for python 3

numba.testing.test_support.parametrize(*parameters, **named_parameters)

@parametrize(‘foo’, ‘bar’) def test_func(foo_or_bar):

print foo_or_bar # prints ‘foo’ or ‘bar’


@parametrize(x=[‘foo’, ‘bar’], y=[‘baz’, ‘quux’]) def test_func(x, y):

print x, y # prints all combinations

Generates a unittest TestCase in the function’s global scope named ‘test_func_testcase’ with parametrized test methods.

‘:return: The original function

numba.testing.test_support.skip_if(should_skip, message)
numba.testing.test_support.skip_unless(should_skip, message)
numba.testing.test_support.testmod(module=None, run=True, optionflags=None)

Tests a doctest modules with numba functions. When run in nosetests, only populates module.__test__, when run as main, runs the doctests.

user_support Module

Doctest support exposed to numba users.

numba.testing.user_support.testmod(module=None, run=True, optionflags=0, verbosity=2)

Tests a doctest modules with numba functions. When run in nosetests, only populates module.__test__, when run as main, runs the doctests.

module: the module to run the doctests in run: whether to run the doctests or just build a __test__ dict verbosity: verbosity level passed to unittest.TextTestRunner

The defualt is 2

optionflags: doctest options (e.g. doctest.ELLIPSIS)