Python doctest.testmod() Examples

The following are code examples for showing how to use doctest.testmod(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: pyblish-win   Author: pyblish   File: doctest.py    GNU Lesser General Public License v3.0 6 votes vote down vote up
def _test():
    testfiles = [arg for arg in sys.argv[1:] if arg and arg[0] != '-']
    if not testfiles:
        name = os.path.basename(sys.argv[0])
        if '__loader__' in globals():          # python -m
            name, _ = os.path.splitext(name)
        print("usage: {0} [-v] file ...".format(name))
        return 2
    for filename in testfiles:
        if filename.endswith(".py"):
            # It is a module -- insert its dir into sys.path and try to
            # import it. If it is part of a package, that possibly
            # won't work because of package imports.
            dirname, filename = os.path.split(filename)
            sys.path.insert(0, dirname)
            m = __import__(filename[:-3])
            del sys.path[0]
            failures, _ = testmod(m)
        else:
            failures, _ = testfile(filename, module_relative=False)
        if failures:
            return 1
    return 0 
Example 2
Project: flasky   Author: RoseOu   File: doctest.py    MIT License 6 votes vote down vote up
def __init__(self, verbose=False, parser=DocTestParser(),
                 recurse=True, _namefilter=None, exclude_empty=True):
        """
        Create a new doctest finder.

        The optional argument `parser` specifies a class or
        function that should be used to create new DocTest objects (or
        objects that implement the same interface as DocTest).  The
        signature for this factory function should match the signature
        of the DocTest constructor.

        If the optional argument `recurse` is false, then `find` will
        only examine the given object, and not any contained objects.

        If the optional argument `exclude_empty` is false, then `find`
        will include tests for objects with empty docstrings.
        """
        self._parser = parser
        self._verbose = verbose
        self._recurse = recurse
        self._exclude_empty = exclude_empty
        # _namefilter is undocumented, and exists only for temporary backward-
        # compatibility support of testmod's deprecated isprivate mess.
        self._namefilter = _namefilter 
Example 3
Project: Flask_Blog   Author: sugarguo   File: doctest.py    GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, verbose=False, parser=DocTestParser(),
                 recurse=True, _namefilter=None, exclude_empty=True):
        """
        Create a new doctest finder.

        The optional argument `parser` specifies a class or
        function that should be used to create new DocTest objects (or
        objects that implement the same interface as DocTest).  The
        signature for this factory function should match the signature
        of the DocTest constructor.

        If the optional argument `recurse` is false, then `find` will
        only examine the given object, and not any contained objects.

        If the optional argument `exclude_empty` is false, then `find`
        will include tests for objects with empty docstrings.
        """
        self._parser = parser
        self._verbose = verbose
        self._recurse = recurse
        self._exclude_empty = exclude_empty
        # _namefilter is undocumented, and exists only for temporary backward-
        # compatibility support of testmod's deprecated isprivate mess.
        self._namefilter = _namefilter 
Example 4
Project: neo4j-social-network   Author: bestvibes   File: doctest.py    MIT License 6 votes vote down vote up
def __init__(self, verbose=False, parser=DocTestParser(),
                 recurse=True, _namefilter=None, exclude_empty=True):
        """
        Create a new doctest finder.

        The optional argument `parser` specifies a class or
        function that should be used to create new DocTest objects (or
        objects that implement the same interface as DocTest).  The
        signature for this factory function should match the signature
        of the DocTest constructor.

        If the optional argument `recurse` is false, then `find` will
        only examine the given object, and not any contained objects.

        If the optional argument `exclude_empty` is false, then `find`
        will include tests for objects with empty docstrings.
        """
        self._parser = parser
        self._verbose = verbose
        self._recurse = recurse
        self._exclude_empty = exclude_empty
        # _namefilter is undocumented, and exists only for temporary backward-
        # compatibility support of testmod's deprecated isprivate mess.
        self._namefilter = _namefilter 
Example 5
Project: centreon-discovery   Author: Centreon-Community   File: doctest.py    GNU General Public License v2.0 6 votes vote down vote up
def __init__(self, verbose=False, parser=DocTestParser(),
                 recurse=True, _namefilter=None, exclude_empty=True):
        """
        Create a new doctest finder.

        The optional argument `parser` specifies a class or
        function that should be used to create new DocTest objects (or
        objects that implement the same interface as DocTest).  The
        signature for this factory function should match the signature
        of the DocTest constructor.

        If the optional argument `recurse` is false, then `find` will
        only examine the given object, and not any contained objects.

        If the optional argument `exclude_empty` is false, then `find`
        will include tests for objects with empty docstrings.
        """
        self._parser = parser
        self._verbose = verbose
        self._recurse = recurse
        self._exclude_empty = exclude_empty
        # _namefilter is undocumented, and exists only for temporary backward-
        # compatibility support of testmod's deprecated isprivate mess.
        self._namefilter = _namefilter 
Example 6
Project: pyblish-win   Author: pyblish   File: Cookie.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def _test():
    import doctest, Cookie
    return doctest.testmod(Cookie) 
Example 7
Project: pyblish-win   Author: pyblish   File: test_objects.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test(self):
        failures, tests = doctest.testmod(ctypes.test.test_objects)
        self.assertFalse(failures, 'doctests failed, see output above') 
Example 8
Project: pyblish-win   Author: pyblish   File: difflib.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def _test():
    import doctest, difflib
    return doctest.testmod(difflib) 
Example 9
Project: pyblish-win   Author: pyblish   File: pickle.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def _test():
    import doctest
    return doctest.testmod() 
Example 10
Project: pyblish-win   Author: pyblish   File: doctest.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def __init__(self, checker=None, verbose=None, optionflags=0):
        """
        Create a new test runner.

        Optional keyword arg `checker` is the `OutputChecker` that
        should be used to compare the expected outputs and actual
        outputs of doctest examples.

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

        Optional argument `optionflags` can be used to control how the
        test runner compares expected output to actual output, and how
        it displays failures.  See the documentation for `testmod` for
        more information.
        """
        self._checker = checker or OutputChecker()
        if verbose is None:
            verbose = '-v' in sys.argv
        self._verbose = verbose
        self.optionflags = optionflags
        self.original_optionflags = optionflags

        # Keep track of the examples we've run.
        self.tries = 0
        self.failures = 0
        self._name2ft = {}

        # Create a fake output target for capturing doctest output.
        self._fakeout = _SpoofOut()

    #/////////////////////////////////////////////////////////////////
    # Reporting methods
    #///////////////////////////////////////////////////////////////// 
Example 11
Project: pyblish-win   Author: pyblish   File: doctest.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def 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.
    """
    # Find, parse, and run all tests in the given module.
    finder = DocTestFinder(verbose=verbose, recurse=False)
    runner = DocTestRunner(verbose=verbose, optionflags=optionflags)
    for test in finder.find(f, name, globs=globs):
        runner.run(test, compileflags=compileflags)

######################################################################
## 7. Tester
######################################################################
# This is provided only for backwards compatibility.  It's not
# actually used in any way. 
Example 12
Project: pyblish-win   Author: pyblish   File: test_support.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def run_doctest(module, verbosity=None):
    """Run doctest on the given module.  Return (#failures, #tests).

    If optional argument verbosity is not specified (or is None), pass
    test_support's belief about verbosity on to doctest.  Else doctest's
    usual behavior is used (it searches sys.argv for -v).
    """

    import doctest

    if verbosity is None:
        verbosity = verbose
    else:
        verbosity = None

    # Direct doctest output (normally just errors) to real stdout; doctest
    # output shouldn't be compared by regrtest.
    save_stdout = sys.stdout
    sys.stdout = get_original_stdout()
    try:
        f, t = doctest.testmod(module, verbose=verbosity)
        if f:
            raise TestFailed("%d of %d doctests failed" % (f, t))
    finally:
        sys.stdout = save_stdout
    if verbose:
        print 'doctest (%s) ... %d tests with zero failures' % (module.__name__, t)
    return f, t

#=======================================================================
# Threading support to prevent reporting refleaks when running regrtest.py -R

# NOTE: we use thread._count() rather than threading.enumerate() (or the
# moral equivalent thereof) because a threading.Thread object is still alive
# until its __bootstrap() method has returned, even after it has been
# unregistered from the threading module.
# thread._count(), on the other hand, only gets decremented *after* the
# __bootstrap() method has returned, which gives us reliable reference counts
# at the end of a test run. 
Example 13
Project: pyblish-win   Author: pyblish   File: test_zipimport_support.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_doctest_main_issue4197(self):
        test_src = textwrap.dedent("""\
                    class Test:
                        ">>> 'line 2'"
                        pass

                    import doctest
                    doctest.testmod()
                    """)
        pattern = 'File "%s", line 2, in %s'
        with temp_dir() as d:
            script_name = make_script(d, 'script', test_src)
            exit_code, data = run_python(script_name)
            expected = pattern % (script_name, "__main__.Test")
            if verbose:
                print "Expected line", expected
                print "Got stdout:"
                print data
            self.assertIn(expected, data)
            zip_name, run_name = make_zip_script(d, "test_zip",
                                                script_name, '__main__.py')
            exit_code, data = run_python(zip_name)
            expected = pattern % (run_name, "__main__.Test")
            if verbose:
                print "Expected line", expected
                print "Got stdout:"
                print data
            self.assertIn(expected, data) 
Example 14
Project: flasky   Author: RoseOu   File: doctest.py    MIT License 5 votes vote down vote up
def __init__(self, checker=None, verbose=None, optionflags=0):
        """
        Create a new test runner.

        Optional keyword arg `checker` is the `OutputChecker` that
        should be used to compare the expected outputs and actual
        outputs of doctest examples.

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

        Optional argument `optionflags` can be used to control how the
        test runner compares expected output to actual output, and how
        it displays failures.  See the documentation for `testmod` for
        more information.
        """
        self._checker = checker or OutputChecker()
        if verbose is None:
            verbose = '-v' in sys.argv
        self._verbose = verbose
        self.optionflags = optionflags
        self.original_optionflags = optionflags

        # Keep track of the examples we've run.
        self.tries = 0
        self.failures = 0
        self._name2ft = {}

        # Create a fake output target for capturing doctest output.
        self._fakeout = _SpoofOut()

    #/////////////////////////////////////////////////////////////////
    # Reporting methods
    #///////////////////////////////////////////////////////////////// 
Example 15
Project: flasky   Author: RoseOu   File: doctest.py    MIT License 5 votes vote down vote up
def report_failure(self, out, test, example, got):
        raise DocTestFailure(test, example, got)

######################################################################
## 6. Test Functions
######################################################################
# These should be backwards compatible.

# For backward compatibility, a global instance of a DocTestRunner
# class, updated by testmod. 
Example 16
Project: flasky   Author: RoseOu   File: doctest.py    MIT License 5 votes vote down vote up
def 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.
    """
    # Find, parse, and run all tests in the given module.
    finder = DocTestFinder(verbose=verbose, recurse=False)
    runner = DocTestRunner(verbose=verbose, optionflags=optionflags)
    for test in finder.find(f, name, globs=globs):
        runner.run(test, compileflags=compileflags)

######################################################################
## 7. Tester
######################################################################
# This is provided only for backwards compatibility.  It's not
# actually used in any way. 
Example 17
Project: dynamic-training-with-apache-mxnet-on-aws   Author: awslabs   File: test_docstring.py    Apache License 2.0 5 votes vote down vote up
def test_symbols():
    globs = {'np': numpy, 'mx': mxnet, 'test_utils': mxnet.test_utils, 'SymbolDoc': mxnet.symbol_doc.SymbolDoc}

    # make sure all the operators are available
    import_into(globs, mxnet.symbol)
    doctest.testmod(mxnet.symbol_doc, globs=globs, verbose=True) 
Example 18
Project: dynamic-training-with-apache-mxnet-on-aws   Author: awslabs   File: test_docstring.py    Apache License 2.0 5 votes vote down vote up
def test_ndarray():
    globs = {'np': numpy, 'mx': mxnet}

    doctest.testmod(mxnet.ndarray, globs=globs, verbose=True) 
Example 19
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: vm_vdi_cleaner.py    Apache License 2.0 5 votes vote down vote up
def main():
    """Main loop."""
    config.parse_args(sys.argv)
    args = CONF(args=sys.argv[1:], usage='%(prog)s [options] --command={' +
            '|'.join(ALLOWED_COMMANDS) + '}')

    command = CONF.command
    if not command or command not in ALLOWED_COMMANDS:
        CONF.print_usage()
        sys.exit(1)

    if CONF.zombie_instance_updated_at_window < CONF.resize_confirm_window:
        raise Exception("`zombie_instance_updated_at_window` has to be longer"
                " than `resize_confirm_window`.")

    # NOTE(blamar) This tool does not require DB access, so passing in the
    # 'abstract' VirtAPI class is acceptable
    xenapi = xenapi_driver.XenAPIDriver(virtapi.VirtAPI())

    if command == "list-vdis":
        if CONF.verbose:
            print "Connected VDIs:\n"
        orphaned_vdi_uuids = find_orphaned_vdi_uuids(xenapi)
        if CONF.verbose:
            print "\nOrphaned VDIs:\n"
        list_orphaned_vdis(orphaned_vdi_uuids)
    elif command == "clean-vdis":
        orphaned_vdi_uuids = find_orphaned_vdi_uuids(xenapi)
        clean_orphaned_vdis(xenapi, orphaned_vdi_uuids)
    elif command == "list-instances":
        orphaned_instances = find_orphaned_instances(xenapi)
        list_orphaned_instances(orphaned_instances)
    elif command == "clean-instances":
        orphaned_instances = find_orphaned_instances(xenapi)
        clean_orphaned_instances(xenapi, orphaned_instances)
    elif command == "test":
        doctest.testmod()
    else:
        print "Unknown command '%s'" % command
        sys.exit(1) 
Example 20
Project: bigquerylayers   Author: smandaric   File: __init__.py    GNU General Public License v3.0 5 votes vote down vote up
def _test():
    import doctest
    sys.path.insert(0, os.pardir)
    import pytz
    return doctest.testmod(pytz) 
Example 21
Project: openhatch   Author: campbe13   File: __init__.py    GNU Affero General Public License v3.0 5 votes vote down vote up
def _test():
    import doctest, os, sys
    sys.path.insert(0, os.pardir)
    import pytz
    return doctest.testmod(pytz) 
Example 22
Project: jawfish   Author: war-and-code   File: difflib.py    MIT License 5 votes vote down vote up
def _test():
    import doctest, difflib
    return doctest.testmod(difflib) 
Example 23
Project: jawfish   Author: war-and-code   File: support.py    MIT License 5 votes vote down vote up
def run_doctest(module, verbosity=None, optionflags=0):
    """Run doctest on the given module.  Return (#failures, #tests).

    If optional argument verbosity is not specified (or is None), pass
    support's belief about verbosity on to doctest.  Else doctest's
    usual behavior is used (it searches sys.argv for -v).
    """

    import doctest

    if verbosity is None:
        verbosity = verbose
    else:
        verbosity = None

    f, t = doctest.testmod(module, verbose=verbosity, optionflags=optionflags)
    if f:
        raise TestFailed("%d of %d doctests failed" % (f, t))
    if verbose:
        print('doctest (%s) ... %d tests with zero failures' %
              (module.__name__, t))
    return f, t


#=======================================================================
# Support for saving and restoring the imported modules. 
Example 24
Project: Repobot   Author: Desgard   File: support.py    MIT License 5 votes vote down vote up
def run_doctest(module, verbosity=None, optionflags=0):
    """Run doctest on the given module.  Return (#failures, #tests).

    If optional argument verbosity is not specified (or is None), pass
    support's belief about verbosity on to doctest.  Else doctest's
    usual behavior is used (it searches sys.argv for -v).
    """

    import doctest

    if verbosity is None:
        verbosity = verbose
    else:
        verbosity = None

    f, t = doctest.testmod(module, verbose=verbosity, optionflags=optionflags)
    if f:
        raise TestFailed("%d of %d doctests failed" % (f, t))
    if verbose:
        print('doctest (%s) ... %d tests with zero failures' %
              (module.__name__, t))
    return f, t


#=======================================================================
# Support for saving and restoring the imported modules. 
Example 25
Project: razzy-spinner   Author: rafasashi   File: wntools.py    GNU General Public License v3.0 5 votes vote down vote up
def _test(reset=0):
    import doctest, wntools
    if reset:
        doctest.master = None # This keeps doctest from complaining after a reload.
    return doctest.testmod(wntools) 
Example 26
Project: razzy-spinner   Author: rafasashi   File: wordnet.py    GNU General Public License v3.0 5 votes vote down vote up
def _test(reset=0):
    import doctest, wordnet
    if reset:
        doctest.master = None # This keeps doctest from complaining after a reload.
    return doctest.testmod(wordnet) 
Example 27
Project: razzy-spinner   Author: rafasashi   File: featurelite.py    GNU General Public License v3.0 5 votes vote down vote up
def test():
    "Run unit tests on unification."
    import doctest
    doctest.testmod() 
Example 28
Project: razzy-spinner   Author: rafasashi   File: wntools.py    GNU General Public License v3.0 5 votes vote down vote up
def _test(reset=0):
    import doctest, wntools
    if reset:
        doctest.master = None # This keeps doctest from complaining after a reload.
    return doctest.testmod(wntools) 
Example 29
Project: razzy-spinner   Author: rafasashi   File: wordnet.py    GNU General Public License v3.0 5 votes vote down vote up
def _test(reset=0):
    import doctest, wordnet
    if reset:
        doctest.master = None # This keeps doctest from complaining after a reload.
    return doctest.testmod(wordnet) 
Example 30
Project: robot-navigation   Author: ronaldahmed   File: Executor.py    MIT License 5 votes vote down vote up
def test():
    import doctest
    doctest.testmod() 
Example 31
Project: robot-navigation   Author: ronaldahmed   File: CompoundAction.py    MIT License 5 votes vote down vote up
def _test(suite='All',verbose=False):
    import doctest
    if suite != 'All':
        doctest.run_docstring_examples(suite, globals(), verbose=verbose)
    else: doctest.testmod(verbose=verbose) 
Example 32
Project: robot-navigation   Author: ronaldahmed   File: Recognizers_POMDP_Antie_Sim.py    MIT License 5 votes vote down vote up
def _test(verbose=False):
    import doctest, Recognizers_Compound, CompoundAction, ViewCache
    doctest.testmod(verbose=verbose)
    d= Recognizers_Compound.__dict__.copy()
    d['PomdpAntieSimRecognizer'] = PomdpAntieSimRecognizer
    d['ViewCache'] = ViewCache.ViewCache
    d['logger'] = logger
    d.update(CompoundAction.__dict__)
    doctest.testmod(Recognizers_Compound, globs=d, verbose=verbose) 
Example 33
Project: robot-navigation   Author: ronaldahmed   File: Recognizers_HSSH.py    MIT License 5 votes vote down vote up
def _test(verbose=False):
    import doctest
    doctest.testmod(verbose=verbose) 
Example 34
Project: robot-navigation   Author: ronaldahmed   File: SmallScaleStar.py    MIT License 5 votes vote down vote up
def _test(verbose=False):
    import doctest
    doctest.testmod(verbose=verbose) 
Example 35
Project: robot-navigation   Author: ronaldahmed   File: __init__.py    MIT License 5 votes vote down vote up
def _test(reset=0):
    import doctest, wordnet
    if reset:
        doctest.master = None # This keeps doctest from complaining after a reload.
    return doctest.testmod(wordnet) 
Example 36
Project: robot-navigation   Author: ronaldahmed   File: tools.py    MIT License 5 votes vote down vote up
def _test(reset=0):
    import doctest, wntools
    if reset:
        doctest.master = None # This keeps doctest from complaining after a reload.
    return doctest.testmod(wntools) 
Example 37
Project: GroundStation   Author: ClydeSpace-GroundStation   File: __init__.py    MIT License 5 votes vote down vote up
def _test():
    import os
    this_dir = os.path.dirname(globals()['__file__'])
    xml_path = this_dir + "/example/xml/"
    di = DoxyIndex(xml_path)
    # Get the Aadvark class
    aad = di.get_member('Aadvark')
    aad.brief_description
    import doctest
    return doctest.testmod() 
Example 38
Project: GroundStation   Author: ClydeSpace-GroundStation   File: __init__.py    MIT License 5 votes vote down vote up
def _test():
    import os
    this_dir = os.path.dirname(globals()['__file__'])
    xml_path = this_dir + "/example/xml/"
    di = DoxyIndex(xml_path)
    # Get the Aadvark class
    aad = di.get_member('Aadvark')
    aad.brief_description
    import doctest
    return doctest.testmod() 
Example 39
Project: GroundStation   Author: ClydeSpace-GroundStation   File: __init__.py    MIT License 5 votes vote down vote up
def _test():
    import os
    this_dir = os.path.dirname(globals()['__file__'])
    xml_path = this_dir + "/example/xml/"
    di = DoxyIndex(xml_path)
    # Get the Aadvark class
    aad = di.get_member('Aadvark')
    aad.brief_description
    import doctest
    return doctest.testmod() 
Example 40
Project: GroundStation   Author: ClydeSpace-GroundStation   File: __init__.py    MIT License 5 votes vote down vote up
def _test():
    import os
    this_dir = os.path.dirname(globals()['__file__'])
    xml_path = this_dir + "/example/xml/"
    di = DoxyIndex(xml_path)
    # Get the Aadvark class
    aad = di.get_member('Aadvark')
    aad.brief_description
    import doctest
    return doctest.testmod() 
Example 41
Project: GroundStation   Author: ClydeSpace-GroundStation   File: __init__.py    MIT License 5 votes vote down vote up
def _test():
    import os
    this_dir = os.path.dirname(globals()['__file__'])
    xml_path = this_dir + "/example/xml/"
    di = DoxyIndex(xml_path)
    # Get the Aadvark class
    aad = di.get_member('Aadvark')
    aad.brief_description
    import doctest
    return doctest.testmod() 
Example 42
Project: GroundStation   Author: ClydeSpace-GroundStation   File: __init__.py    MIT License 5 votes vote down vote up
def _test():
    import os
    this_dir = os.path.dirname(globals()['__file__'])
    xml_path = this_dir + "/example/xml/"
    di = DoxyIndex(xml_path)
    # Get the Aadvark class
    aad = di.get_member('Aadvark')
    aad.brief_description
    import doctest
    return doctest.testmod() 
Example 43
Project: Flask_Blog   Author: sugarguo   File: doctest.py    GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, checker=None, verbose=None, optionflags=0):
        """
        Create a new test runner.

        Optional keyword arg `checker` is the `OutputChecker` that
        should be used to compare the expected outputs and actual
        outputs of doctest examples.

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

        Optional argument `optionflags` can be used to control how the
        test runner compares expected output to actual output, and how
        it displays failures.  See the documentation for `testmod` for
        more information.
        """
        self._checker = checker or OutputChecker()
        if verbose is None:
            verbose = '-v' in sys.argv
        self._verbose = verbose
        self.optionflags = optionflags
        self.original_optionflags = optionflags

        # Keep track of the examples we've run.
        self.tries = 0
        self.failures = 0
        self._name2ft = {}

        # Create a fake output target for capturing doctest output.
        self._fakeout = _SpoofOut()

    #/////////////////////////////////////////////////////////////////
    # Reporting methods
    #///////////////////////////////////////////////////////////////// 
Example 44
Project: Flask_Blog   Author: sugarguo   File: doctest.py    GNU General Public License v3.0 5 votes vote down vote up
def report_failure(self, out, test, example, got):
        raise DocTestFailure(test, example, got)

######################################################################
## 6. Test Functions
######################################################################
# These should be backwards compatible.

# For backward compatibility, a global instance of a DocTestRunner
# class, updated by testmod. 
Example 45
Project: Flask_Blog   Author: sugarguo   File: doctest.py    GNU General Public License v3.0 5 votes vote down vote up
def 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.
    """
    # Find, parse, and run all tests in the given module.
    finder = DocTestFinder(verbose=verbose, recurse=False)
    runner = DocTestRunner(verbose=verbose, optionflags=optionflags)
    for test in finder.find(f, name, globs=globs):
        runner.run(test, compileflags=compileflags)

######################################################################
## 7. Tester
######################################################################
# This is provided only for backwards compatibility.  It's not
# actually used in any way. 
Example 46
Project: epg-dk.bundle   Author: ukdtom   File: __init__.py    The Unlicense 5 votes vote down vote up
def _test():
    import doctest, os, sys
    sys.path.insert(0, os.pardir)
    import pytz
    return doctest.testmod(pytz) 
Example 47
Project: NiujiaoDebugger   Author: MrSrc   File: test_objects.py    GNU General Public License v3.0 5 votes vote down vote up
def test(self):
        failures, tests = doctest.testmod(ctypes.test.test_objects)
        self.assertFalse(failures, 'doctests failed, see output above') 
Example 48
Project: NiujiaoDebugger   Author: MrSrc   File: difflib.py    GNU General Public License v3.0 5 votes vote down vote up
def _test():
    import doctest, difflib
    return doctest.testmod(difflib) 
Example 49
Project: NiujiaoDebugger   Author: MrSrc   File: pickle.py    GNU General Public License v3.0 5 votes vote down vote up
def _test():
    import doctest
    return doctest.testmod() 
Example 50
Project: NiujiaoDebugger   Author: MrSrc   File: doctest.py    GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, checker=None, verbose=None, optionflags=0):
        """
        Create a new test runner.

        Optional keyword arg `checker` is the `OutputChecker` that
        should be used to compare the expected outputs and actual
        outputs of doctest examples.

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

        Optional argument `optionflags` can be used to control how the
        test runner compares expected output to actual output, and how
        it displays failures.  See the documentation for `testmod` for
        more information.
        """
        self._checker = checker or OutputChecker()
        if verbose is None:
            verbose = '-v' in sys.argv
        self._verbose = verbose
        self.optionflags = optionflags
        self.original_optionflags = optionflags

        # Keep track of the examples we've run.
        self.tries = 0
        self.failures = 0
        self._name2ft = {}

        # Create a fake output target for capturing doctest output.
        self._fakeout = _SpoofOut()

    #/////////////////////////////////////////////////////////////////
    # Reporting methods
    #/////////////////////////////////////////////////////////////////