Orbits  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Pages
Classes | Functions | Variables
setuptools.tests.doctest Namespace Reference

Classes

class  _SpoofOut
 
class  _OutputRedirectingPdb
 
class  Example
 
class  DocTest
 
class  DocTestParser
 
class  DocTestFinder
 
class  DocTestRunner
 
class  OutputChecker
 
class  DocTestFailure
 
class  UnexpectedException
 
class  DebugRunner
 
class  Tester
 
class  DocTestCase
 
class  DocFileCase
 
class  _TestClass
 

Functions

def enumerate
 
def register_optionflag
 
def is_private
 Table of Contents. More...
 
def _extract_future_flags
 
def _normalize_module
 
def _indent
 
def _exception_traceback
 
def _ellipsis_match
 
def _comment_line
 
def _module_relative_path
 
def testmod
 
def testfile
 
def run_docstring_examples
 
def set_unittest_reportflags
 
def DocTestSuite
 
def DocFileTest
 
def DocFileSuite
 
def script_from_examples
 
def testsource
 
def debug_src
 
def debug_script
 
def debug
 
def _test
 

Variables

 basestring = str
 
string __docformat__ = 'reStructuredText en'
 
list __all__
 
dictionary OPTIONFLAGS_BY_NAME = {}
 
tuple DONT_ACCEPT_TRUE_FOR_1 = register_optionflag('DONT_ACCEPT_TRUE_FOR_1')
 
tuple DONT_ACCEPT_BLANKLINE = register_optionflag('DONT_ACCEPT_BLANKLINE')
 
tuple NORMALIZE_WHITESPACE = register_optionflag('NORMALIZE_WHITESPACE')
 
tuple ELLIPSIS = register_optionflag('ELLIPSIS')
 
tuple IGNORE_EXCEPTION_DETAIL = register_optionflag('IGNORE_EXCEPTION_DETAIL')
 
tuple COMPARISON_FLAGS
 
tuple REPORT_UDIFF = register_optionflag('REPORT_UDIFF')
 
tuple REPORT_CDIFF = register_optionflag('REPORT_CDIFF')
 
tuple REPORT_NDIFF = register_optionflag('REPORT_NDIFF')
 
tuple REPORT_ONLY_FIRST_FAILURE = register_optionflag('REPORT_ONLY_FIRST_FAILURE')
 
tuple REPORTING_FLAGS
 
string BLANKLINE_MARKER = '<BLANKLINE>'
 
string ELLIPSIS_MARKER = '...'
 
 master = None
 
int _unittest_reportflags = 0
 
dictionary __test__
 

Function Documentation

def setuptools.tests.doctest._comment_line (   line)
private
def setuptools.tests.doctest._ellipsis_match (   want,
  got 
)
private
Essentially the only subtle case:
>>> _ellipsis_match('aa...aa', 'aaa')
False
def setuptools.tests.doctest._exception_traceback (   exc_info)
private
Return a string containing a traceback message for the given
exc_info tuple (as returned by sys.exc_info()).
def setuptools.tests.doctest._extract_future_flags (   globs)
private
Return the compiler-flags associated with the future features that
have been imported into the given namespace (globs).
def setuptools.tests.doctest._indent (   s,
  indent = 4 
)
private
Add the given number of space characters to the beginning every
non-blank line in `s`, and return the result.
def setuptools.tests.doctest._module_relative_path (   module,
  path 
)
private
def setuptools.tests.doctest._normalize_module (   module,
  depth = 2 
)
private
Return the module specified by `module`.  In particular:
  - If `module` is a module, then return module.
  - If `module` is a string, then import and return the
    module with that name.
  - If `module` is None, then return the calling module.
    The calling module is assumed to be the module of
    the stack frame at the given depth in the call stack.
def setuptools.tests.doctest._test ( )
private
def setuptools.tests.doctest.debug (   module,
  name,
  pm = False 
)
Debug a single doctest docstring.

Provide the module (or dotted name of the module) containing the
test to be debugged and the name (within the module) of the object
with the docstring with tests to be debugged.
def setuptools.tests.doctest.debug_script (   src,
  pm = False,
  globs = None 
)
def setuptools.tests.doctest.debug_src (   src,
  pm = False,
  globs = None 
)
Debug a single doctest docstring, in argument `src`'
def setuptools.tests.doctest.DocFileSuite (   paths,
  kw 
)
A unittest suite for one or more doctest files.

The path to each doctest file is given as a string; the
interpretation of that string depends on the keyword argument
"module_relative".

A number of options may be provided as keyword arguments:

module_relative
  If "module_relative" is True, then the given file paths are
  interpreted as os-independent module-relative paths.  By
  default, these paths are relative to the calling module's
  directory; but if the "package" argument is specified, then
  they are relative to that package.  To ensure os-independence,
  "filename" should use "/" characters to separate path
  segments, and may not be an absolute path (i.e., it may not
  begin with "/").

  If "module_relative" is False, then the given file paths are
  interpreted as os-specific paths.  These paths may be absolute
  or relative (to the current working directory).

package
  A Python package or the name of a Python package whose directory
  should be used as the base directory for module relative paths.
  If "package" is not specified, then the calling module's
  directory is used as the base directory for module relative
  filenames.  It is an error to specify "package" if
  "module_relative" is False.

setUp
  A set-up function.  This is called before running the
  tests in each file. The setUp function will be passed a DocTest
  object.  The setUp function can access the test globals as the
  globs attribute of the test passed.

tearDown
  A tear-down function.  This is called after running the
  tests in each file.  The tearDown function will be passed a DocTest
  object.  The tearDown function can access the test globals as the
  globs attribute of the test passed.

globs
  A dictionary containing initial global variables for the tests.

optionflags
  A set of doctest option flags expressed as an integer.

parser
  A DocTestParser (or subclass) that should be used to extract
  tests from the files.
def setuptools.tests.doctest.DocFileTest (   path,
  module_relative = True,
  package = None,
  globs = None,
  parser = DocTestParser(),
  options 
)
def setuptools.tests.doctest.DocTestSuite (   module = None,
  globs = None,
  extraglobs = None,
  test_finder = None,
  options 
)
Convert doctest tests for a module to a unittest test suite.

This converts each documentation string in a module that
contains doctest tests to a unittest test case.  If any of the
tests in a doc string fail, then the test case fails.  An exception
is raised showing the name of the file containing the test and a
(sometimes approximate) line number.

The `module` argument provides the module to be tested.  The argument
can be either a module or a module name.

If no argument is given, the calling module is used.

A number of options may be provided as keyword arguments:

setUp
  A set-up function.  This is called before running the
  tests in each file. The setUp function will be passed a DocTest
  object.  The setUp function can access the test globals as the
  globs attribute of the test passed.

tearDown
  A tear-down function.  This is called after running the
  tests in each file.  The tearDown function will be passed a DocTest
  object.  The tearDown function can access the test globals as the
  globs attribute of the test passed.

globs
  A dictionary containing initial global variables for the tests.

optionflags
   A set of doctest option flags expressed as an integer.
def setuptools.tests.doctest.enumerate (   seq)
def setuptools.tests.doctest.is_private (   prefix,
  base 
)

Table of Contents.

  1. Utility Functions
  2. Example & DocTest – store test cases
  3. DocTest Parser – extracts examples from strings
  4. DocTest Finder – extracts test cases from objects
  5. DocTest Runner – runs test cases
  6. Test Functions – convenient wrappers for testing
  7. Tester Class – for backwards compatibility
  8. Unittest Support
  9. Debugging Support

Example Usage

  1. Utility Functions
    prefix, base -> true iff name prefix + "." + base is "private".
    
    Prefix may be an empty string, and base does not contain a period.
    Prefix is ignored (although functions you write conforming to this
    protocol may make use of it).
    Return true iff base begins with an (at least one) underscore, but
    does not both begin and end with (at least) two underscores.
    
    >>> is_private("a.b", "my_func")
    False
    >>> is_private("____", "_my_func")
    True
    >>> is_private("someclass", "__init__")
    False
    >>> is_private("sometypo", "__init_")
    True
    >>> is_private("x.y.z", "_")
    True
    >>> is_private("_x.y.z", "__")
    False
    >>> is_private("", "")  # senseless but consistent
    False
    
def setuptools.tests.doctest.register_optionflag (   name)
def setuptools.tests.doctest.run_docstring_examples (   f,
  globs,
  verbose = False,
  name = "NoName",
  compileflags = None,
  optionflags = 0 
)
Test examples in the given object's docstring (`f`), using `globs`
as globals.  Optional argument `name` is used in failure messages.
If the optional argument `verbose` is true, then generate output
even if there are no failures.

`compileflags` gives the set of flags that should be used by the
Python compiler when running the examples.  If not specified, then
it will default to the set of future-import flags that apply to
`globs`.

Optional keyword arg `optionflags` specifies options for the
testing and output.  See the documentation for `testmod` for more
information.
def setuptools.tests.doctest.script_from_examples (   s)
  1. Debugging Support
def setuptools.tests.doctest.set_unittest_reportflags (   flags)
Sets the unittest option flags.

The old flag is returned so that a runner could restore the old
value if it wished to:

  >>> old = _unittest_reportflags
  >>> set_unittest_reportflags(REPORT_NDIFF |
  ...                          REPORT_ONLY_FIRST_FAILURE) == old
  True

  >>> import doctest
  >>> doctest._unittest_reportflags == (REPORT_NDIFF |
  ...                                   REPORT_ONLY_FIRST_FAILURE)
  True

Only reporting flags can be set:

  >>> set_unittest_reportflags(ELLIPSIS)
  Traceback (most recent call last):
  ...
  ValueError: ('Only reporting flags allowed', 8)

  >>> set_unittest_reportflags(old) == (REPORT_NDIFF |
  ...                                   REPORT_ONLY_FIRST_FAILURE)
  True
def setuptools.tests.doctest.testfile (   filename,
  module_relative = True,
  name = None,
  package = None,
  globs = None,
  verbose = None,
  report = True,
  optionflags = 0,
  extraglobs = None,
  raise_on_error = False,
  parser = DocTestParser() 
)
Test examples in the given file.  Return (#failures, #tests).

Optional keyword arg "module_relative" specifies how filenames
should be interpreted:

  - If "module_relative" is True (the default), then "filename"
     specifies a module-relative path.  By default, this path is
     relative to the calling module's directory; but if the
     "package" argument is specified, then it is relative to that
     package.  To ensure os-independence, "filename" should use
     "/" characters to separate path segments, and should not
     be an absolute path (i.e., it may not begin with "/").

  - If "module_relative" is False, then "filename" specifies an
    os-specific path.  The path may be absolute or relative (to
    the current working directory).

Optional keyword arg "name" gives the name of the test; by default
use the file's basename.

Optional keyword argument "package" is a Python package or the
name of a Python package whose directory should be used as the
base directory for a module relative filename.  If no package is
specified, then the calling module's directory is used as the base
directory for module relative filenames.  It is an error to
specify "package" if "module_relative" is False.

Optional keyword arg "globs" gives a dict to be used as the globals
when executing examples; by default, use {}.  A copy of this dict
is actually used for each docstring, so that each docstring's
examples start with a clean slate.

Optional keyword arg "extraglobs" gives a dictionary that should be
merged into the globals that are used to execute examples.  By
default, no extra globals are used.

Optional keyword arg "verbose" prints lots of stuff if true, prints
only failures if false; by default, it's true iff "-v" is in sys.argv.

Optional keyword arg "report" prints a summary at the end when true,
else prints nothing at the end.  In verbose mode, the summary is
detailed, else very brief (in fact, empty if all tests passed).

Optional keyword arg "optionflags" or's together module constants,
and defaults to 0.  Possible values (see the docs for details):

    DONT_ACCEPT_TRUE_FOR_1
    DONT_ACCEPT_BLANKLINE
    NORMALIZE_WHITESPACE
    ELLIPSIS
    IGNORE_EXCEPTION_DETAIL
    REPORT_UDIFF
    REPORT_CDIFF
    REPORT_NDIFF
    REPORT_ONLY_FIRST_FAILURE

Optional keyword arg "raise_on_error" raises an exception on the
first unexpected exception or failure. This allows failures to be
post-mortem debugged.

Optional keyword arg "parser" specifies a DocTestParser (or
subclass) that should be used to extract tests from the files.

Advanced tomfoolery:  testmod runs methods of a local instance of
class doctest.Tester, then merges the results into (or creates)
global Tester instance doctest.master.  Methods of doctest.master
can be called directly too, if you want to do something unusual.
Passing report=0 to testmod is especially useful then, to delay
displaying a summary.  Invoke doctest.master.summarize(verbose)
when you're done fiddling.
def setuptools.tests.doctest.testmod (   m = None,
  name = None,
  globs = None,
  verbose = None,
  isprivate = None,
  report = True,
  optionflags = 0,
  extraglobs = None,
  raise_on_error = False,
  exclude_empty = False 
)
m=None, name=None, globs=None, verbose=None, isprivate=None,
   report=True, optionflags=0, extraglobs=None, raise_on_error=False,
   exclude_empty=False

Test examples in docstrings in functions and classes reachable
from module m (or the current module if m is not supplied), starting
with m.__doc__.  Unless isprivate is specified, private names
are not skipped.

Also test examples reachable from dict m.__test__ if it exists and is
not None.  m.__test__ maps names to functions, classes and strings;
function and class docstrings are tested even if the name is private;
strings are tested directly, as if they were docstrings.

Return (#failures, #tests).

See doctest.__doc__ for an overview.

Optional keyword arg "name" gives the name of the module; by default
use m.__name__.

Optional keyword arg "globs" gives a dict to be used as the globals
when executing examples; by default, use m.__dict__.  A copy of this
dict is actually used for each docstring, so that each docstring's
examples start with a clean slate.

Optional keyword arg "extraglobs" gives a dictionary that should be
merged into the globals that are used to execute examples.  By
default, no extra globals are used.  This is new in 2.4.

Optional keyword arg "verbose" prints lots of stuff if true, prints
only failures if false; by default, it's true iff "-v" is in sys.argv.

Optional keyword arg "report" prints a summary at the end when true,
else prints nothing at the end.  In verbose mode, the summary is
detailed, else very brief (in fact, empty if all tests passed).

Optional keyword arg "optionflags" or's together module constants,
and defaults to 0.  This is new in 2.3.  Possible values (see the
docs for details):

    DONT_ACCEPT_TRUE_FOR_1
    DONT_ACCEPT_BLANKLINE
    NORMALIZE_WHITESPACE
    ELLIPSIS
    IGNORE_EXCEPTION_DETAIL
    REPORT_UDIFF
    REPORT_CDIFF
    REPORT_NDIFF
    REPORT_ONLY_FIRST_FAILURE

Optional keyword arg "raise_on_error" raises an exception on the
first unexpected exception or failure. This allows failures to be
post-mortem debugged.

Deprecated in Python 2.4:
Optional keyword arg "isprivate" specifies a function used to
determine whether a name is private.  The default function is
treat all functions as public.  Optionally, "isprivate" can be
set to doctest.is_private to skip over functions marked as private
using the underscore naming convention; see its docs for details.

Advanced tomfoolery:  testmod runs methods of a local instance of
class doctest.Tester, then merges the results into (or creates)
global Tester instance doctest.master.  Methods of doctest.master
can be called directly too, if you want to do something unusual.
Passing report=0 to testmod is especially useful then, to delay
displaying a summary.  Invoke doctest.master.summarize(verbose)
when you're done fiddling.
def setuptools.tests.doctest.testsource (   module,
  name 
)
Extract the test sources from a doctest docstring as a script.

Provide the module (or dotted name of the module) containing the
test to be debugged and the name (within the module) of the object
with the doc string with tests to be debugged.

Variable Documentation

list setuptools.tests.doctest.__all__
string setuptools.tests.doctest.__docformat__ = 'reStructuredText en'
dictionary setuptools.tests.doctest.__test__
Initial value:
1 = {"_TestClass": _TestClass,
2  "string": r""" Example of a string object, searched as-is. >>> x = 1; y = 2 >>> x + y, x * y (3, 2) """,
3 
4  "bool-int equivalence": r""" In 2.2, boolean expressions displayed 0 or 1. By default, we still accept them. This can be disabled by passing DONT_ACCEPT_TRUE_FOR_1 to the new optionflags argument. >>> 4 == 4 1 >>> 4 == 4 True >>> 4 > 4 0 >>> 4 > 4 False """,
5 
6  "blank lines": r""" Blank lines can be marked with <BLANKLINE>: >>> print 'foo\n\nbar\n' foo <BLANKLINE> bar <BLANKLINE> """,
7 
8  "ellipsis": r""" If the ellipsis flag is used, then '...' can be used to elide substrings in the desired output: >>> print range(1000) #doctest: +ELLIPSIS [0, 1, 2, ..., 999] """,
9 
10  "whitespace normalization": r""" If the whitespace normalization flag is used, then differences in whitespace are ignored. >>> print range(30) #doctest: +NORMALIZE_WHITESPACE [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29] """,
11  }
int setuptools.tests.doctest._unittest_reportflags = 0
  1. Unittest Support
setuptools.tests.doctest.basestring = str
string setuptools.tests.doctest.BLANKLINE_MARKER = '<BLANKLINE>'
tuple setuptools.tests.doctest.COMPARISON_FLAGS
Initial value:
1 = (DONT_ACCEPT_TRUE_FOR_1 |
2  DONT_ACCEPT_BLANKLINE |
3  NORMALIZE_WHITESPACE |
4  ELLIPSIS |
5  IGNORE_EXCEPTION_DETAIL)
tuple setuptools.tests.doctest.DONT_ACCEPT_BLANKLINE = register_optionflag('DONT_ACCEPT_BLANKLINE')
tuple setuptools.tests.doctest.DONT_ACCEPT_TRUE_FOR_1 = register_optionflag('DONT_ACCEPT_TRUE_FOR_1')
tuple setuptools.tests.doctest.ELLIPSIS = register_optionflag('ELLIPSIS')
string setuptools.tests.doctest.ELLIPSIS_MARKER = '...'
tuple setuptools.tests.doctest.IGNORE_EXCEPTION_DETAIL = register_optionflag('IGNORE_EXCEPTION_DETAIL')
setuptools.tests.doctest.master = None
  1. Test Functions

These should be backwards compatible.

tuple setuptools.tests.doctest.NORMALIZE_WHITESPACE = register_optionflag('NORMALIZE_WHITESPACE')
dictionary setuptools.tests.doctest.OPTIONFLAGS_BY_NAME = {}
tuple setuptools.tests.doctest.REPORT_CDIFF = register_optionflag('REPORT_CDIFF')
tuple setuptools.tests.doctest.REPORT_NDIFF = register_optionflag('REPORT_NDIFF')
tuple setuptools.tests.doctest.REPORT_ONLY_FIRST_FAILURE = register_optionflag('REPORT_ONLY_FIRST_FAILURE')
tuple setuptools.tests.doctest.REPORT_UDIFF = register_optionflag('REPORT_UDIFF')
tuple setuptools.tests.doctest.REPORTING_FLAGS
Initial value:
1 = (REPORT_UDIFF |
2  REPORT_CDIFF |
3  REPORT_NDIFF |
4  REPORT_ONLY_FIRST_FAILURE)

Copyright 2014 Google Inc. All rights reserved.