• Facebook
  • Twitter
  • Reddit
  • StumbleUpon
  • Digg
  • email

All Samples(300)  |  Call(295)  |  Derive(0)  |  Import(5)
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
    SKIP
    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.

Optional keyword arg "encoding" specifies an encoding that should
be used to convert the file to unicode.

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 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(),
             encoding=None):
    """
    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
        SKIP
        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.

    Optional keyword arg "encoding" specifies an encoding that should
    be used to convert the file to unicode.

    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.
    """
    global master

    if package and not module_relative:
        raise ValueError("Package may only be specified for module-"
                         "relative paths.")

    # Relativize the path
    text, filename = _load_testfile(filename, package, module_relative)

    # If no name was given, then use the file's name.
    if name is None:
        name = os.path.basename(filename)

    # Assemble the globals.
    if globs is None:
        globs = {}
    else:
        globs = globs.copy()
    if extraglobs is not None:
        globs.update(extraglobs)
    if '__name__' not in globs:
        globs['__name__'] = '__main__'

    if raise_on_error:
        runner = DebugRunner(verbose=verbose, optionflags=optionflags)
    else:
        runner = DocTestRunner(verbose=verbose, optionflags=optionflags)

    if encoding is not None:
        text = text.decode(encoding)

    # Read the file, convert it to a test, and run it.
    test = parser.get_doctest(text, globs, name, filename, 0)
    runner.run(test)

    if report:
        runner.summarize()

    if master is None:
        master = runner
    else:
        master.merge(runner)

    return TestResults(runner.failures, runner.tries)
        


src/s/c/ScopeFormatter-1.0.3/setup.py   ScopeFormatter(Download)
from __future__ import print_function
from distutils.core import setup
from doctest import testfile
import os.path as Path
import sys
 
dist_dir = Path.dirname(Path.abspath(__file__))
 
if __name__ == '__main__' and sys.argv[-1] == 'test':
    try:
        failure_count = testfile(doc_path('README'), module_relative=False)[0]
    except IOError:
        print("The 'test' command requires {0}.".format(
            Path.basename(doc_path('README'))), file=sys.stderr)

src/g/i/GitPrompt-0.1.1/setup.py   GitPrompt(Download)
from __future__ import print_function
from distutils.core import setup
from doctest import testfile
import os.path as Path
import sys
 
dist_dir = Path.dirname(Path.abspath(__file__))
 
if __name__ == '__main__' and sys.argv[-1] == 'test':
    try:
        failure_count = testfile(doc_path('README'), module_relative=False)[0]
    except IOError:
        print("The 'test' command requires {0}.".format(
            Path.basename(doc_path('README'))), file=sys.stderr)

src/p/y/python-ptrace-0.6.2/test_doc.py   python-ptrace(Download)
#!/usr/bin/env python
from doctest import testfile, ELLIPSIS, testmod
from sys import exit, path as sys_path
from os.path import dirname
 
def testDoc(filename, name=None):
    print "--- %s: Run tests" % filename
    failure, nb_test = testfile(
        filename, optionflags=ELLIPSIS, name=name)

src/f/u/fusil-1.3.2/test_doc.py   fusil(Download)
#!/usr/bin/python
from doctest import testfile, ELLIPSIS, testmod
from sys import exit, path as sys_path
from os.path import dirname
 
def testDoc(filename, name=None):
    print "--- %s: Run tests" % filename
    failure, nb_test = testfile(
        filename, optionflags=ELLIPSIS, name=name)

src/g/i/giblets-0.2.1/tests/test_documentation.py   giblets(Download)
def test_docs():
    from doctest import testfile
    import os
    docdir = '../doc'
    total_failures = 0
    total_tests = 0
    for root, dirs, files in os.walk(docdir):
        for fn in files:
            if fn.endswith('.rst'):
                docfile = os.path.join(root, fn)
                fail, nt = testfile(docfile)