Python doctest 模块,DocTestSuite() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用doctest.DocTestSuite()

项目:scarlett_os    作者:bossjones    | 项目源码 | 文件源码
def run_test_module(test_modules_list=None, test_prefix=None):
    suite = unittest.TestSuite()
    finder = doctest.DocTestFinder(exclude_empty=False)  # finder for doctest
    if test_prefix:
        unittest.TestLoader.testMethodPrefix = test_prefix
    if not test_modules_list:
        test_modules_list = []
    elif not isinstance(test_modules_list, list):
        test_modules_list = [test_modules_list]
    test_modules_list.append('__main__')
    for test in test_modules_list:
        # Doctest
        suite.addTest(doctest.DocTestSuite(test, test_finder=finder))
        # unittest
        suite.addTest(unittest.loader.TestLoader().loadTestsFromModule(test))
    TestRunner().run(suite)
项目:athlib    作者:openath    | 项目源码 | 文件源码
def main():
    was_here = os.getcwd()
    try:
        import unittest
        import doctest
        import sys
        sys.path.insert(0, _rootdir)
        test_loader = unittest.TestLoader()
        test_suite = test_loader.discover('tests', pattern='test_*.py')

        from athlib.wma import agegrader
        test_suite.addTests(doctest.DocTestSuite(agegrader))

        from athlib import utils
        test_suite.addTests(doctest.DocTestSuite(utils))

        from athlib import codes
        test_suite.addTests(doctest.DocTestSuite(codes))
        unittest.TextTestRunner().run(test_suite)
    finally:
        os.chdir(was_here)
项目:acefile    作者:droe    | 项目源码 | 文件源码
def testsuite():
    import doctest
    return doctest.DocTestSuite(optionflags=doctest.IGNORE_EXCEPTION_DETAIL)
项目:orange3-timeseries    作者:biolab    | 项目源码 | 文件源码
def suite(package):
    """Assemble test suite for doctests in path (recursively)"""
    from importlib import import_module
    for module in find_modules(package.__file__):
        try:
            module = import_module(module)
            yield DocTestSuite(module,
                               globs=Context(module.__dict__.copy()),
                               optionflags=ELLIPSIS | NORMALIZE_WHITESPACE)
        except ValueError:
            pass  # No doctests in module
        except ImportError:
            import warnings
            warnings.warn('Unimportable module: {}'.format(module))

    # Add documentation tests
    yield DocFileSuite(path.normpath(path.join(path.dirname(__file__), '..', '..', '..', 'doc', 'scripting.rst')),
                       module_relative=False,
                       globs=Context(module.__dict__.copy()),
                       optionflags=ELLIPSIS | NORMALIZE_WHITESPACE
                       )
项目:web_ctp    作者:molebot    | 项目源码 | 文件源码
def test_main():
    suite = unittest.TestSuite()
    suite.addTest(DocTestSuite('_threading_local'))
    suite.addTest(unittest.makeSuite(ThreadLocalTest))
    suite.addTest(unittest.makeSuite(PyThreadingLocalTest))

    local_orig = _threading_local.local
    def setUp(test):
        _threading_local.local = _thread._local
    def tearDown(test):
        _threading_local.local = local_orig
    suite.addTest(DocTestSuite('_threading_local',
                               setUp=setUp, tearDown=tearDown)
                  )

    support.run_unittest(suite)
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
def test_main():
    suite = unittest.TestSuite()
    suite.addTest(DocTestSuite('_threading_local'))
    suite.addTest(unittest.makeSuite(ThreadLocalTest))
    suite.addTest(unittest.makeSuite(PyThreadingLocalTest))

    local_orig = _threading_local.local
    def setUp(test):
        _threading_local.local = _thread._local
    def tearDown(test):
        _threading_local.local = local_orig
    suite.addTest(DocTestSuite('_threading_local',
                               setUp=setUp, tearDown=tearDown)
                  )

    support.run_unittest(suite)
项目:Chromium_DepotTools    作者:p07r0457    | 项目源码 | 文件源码
def __call__(self, result=None, runcondition=None, options=None):\
        # pylint: disable=W0613
        try:
            finder = DocTestFinder(skipped=self.skipped)
            suite = doctest.DocTestSuite(self.module, test_finder=finder)
            # XXX iirk
            doctest.DocTestCase._TestCase__exc_info = sys.exc_info
        except AttributeError:
            suite = SkippedSuite()
        # doctest may gork the builtins dictionnary
        # This happen to the "_" entry used by gettext
        old_builtins = builtins.__dict__.copy()
        try:
            return suite.run(result)
        finally:
            builtins.__dict__.clear()
            builtins.__dict__.update(old_builtins)
项目:wradlib    作者:wradlib    | 项目源码 | 文件源码
def create_doctest_testsuite():
    # gather information on doctests, search in only wradlib folder
    root_dir = 'wradlib/'
    files = []
    skip = ['__init__.py', 'version.py', 'bufr.py', 'test_']
    for root, _, filenames in os.walk(root_dir):
        for filename in filenames:
            if filename in skip or filename[-3:] != '.py':
                continue
            if 'wradlib/tests' in root:
                continue
            f = os.path.join(root, filename)
            f = f.replace('/', '.')
            f = f[:-3]
            files.append(f)

    # put modules in doctest suite
    suite = unittest.TestSuite()
    for module in files:
        suite.addTest(doctest.DocTestSuite(module))
    return suite
项目:node-gn    作者:Shouqun    | 项目源码 | 文件源码
def __call__(self, result=None, runcondition=None, options=None):\
        # pylint: disable=W0613
        try:
            finder = DocTestFinder(skipped=self.skipped)
            suite = doctest.DocTestSuite(self.module, test_finder=finder)
            # XXX iirk
            doctest.DocTestCase._TestCase__exc_info = sys.exc_info
        except AttributeError:
            suite = SkippedSuite()
        # doctest may gork the builtins dictionnary
        # This happen to the "_" entry used by gettext
        old_builtins = builtins.__dict__.copy()
        try:
            return suite.run(result)
        finally:
            builtins.__dict__.clear()
            builtins.__dict__.update(old_builtins)
项目:Adwear    作者:Uberi    | 项目源码 | 文件源码
def load_tests(loader, tests, ignore):
    module_doctests = [
        urwid.widget,
        urwid.wimp,
        urwid.decoration,
        urwid.display_common,
        urwid.main_loop,
        urwid.monitored_list,
        urwid.raw_display,
        'urwid.split_repr', # override function with same name
        urwid.util,
        urwid.signals,
        ]
    for m in module_doctests:
        tests.addTests(doctest.DocTestSuite(m,
            optionflags=doctest.ELLIPSIS | doctest.IGNORE_EXCEPTION_DETAIL))
    return tests
项目:python-gnupg    作者:vsajip    | 项目源码 | 文件源码
def suite(args=None):
    if args is None:
        args = sys.argv[1:]
    if not args or args == ['--no-doctests']:
        result = unittest.TestLoader().loadTestsFromTestCase(GPGTestCase)
        want_doctests = not args
    else:  # pragma: no cover
        tests = set()
        want_doctests = False
        for arg in args:
            if arg in TEST_GROUPS:
                tests.update(TEST_GROUPS[arg])
            elif arg == "doc":
                want_doctests = True
            else:
                print("Ignoring unknown test group %r" % arg)
        result = unittest.TestSuite(list(map(GPGTestCase, tests)))
    if want_doctests:
        result.addTest(doctest.DocTestSuite(gnupg))
    return result
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
def test_main():
    suite = unittest.TestSuite()
    suite.addTest(DocTestSuite('_threading_local'))
    suite.addTest(unittest.makeSuite(ThreadLocalTest))
    suite.addTest(unittest.makeSuite(PyThreadingLocalTest))

    local_orig = _threading_local.local
    def setUp(test):
        _threading_local.local = _thread._local
    def tearDown(test):
        _threading_local.local = local_orig
    suite.addTest(DocTestSuite('_threading_local',
                               setUp=setUp, tearDown=tearDown)
                  )

    support.run_unittest(suite)
项目:oscars2016    作者:0x0ece    | 项目源码 | 文件源码
def additional_tests(suite=None):
    import simplejson
    import simplejson.encoder
    import simplejson.decoder
    if suite is None:
        suite = unittest.TestSuite()
    for mod in (simplejson, simplejson.encoder, simplejson.decoder):
        suite.addTest(doctest.DocTestSuite(mod))
    suite.addTest(doctest.DocFileSuite('../../index.rst'))
    return suite
项目:runcommands    作者:wylee    | 项目源码 | 文件源码
def load_tests(loader, tests, ignore):
    tests.addTests(DocTestSuite('runcommands.util.decorators'))
    tests.addTests(DocTestSuite('runcommands.util.path'))
    return tests
项目:runcommands    作者:wylee    | 项目源码 | 文件源码
def load_tests(loader, tests, ignore):
    tests.addTests(DocTestSuite('runcommands.config'))
    return tests
项目:wagtail-pg-search-backend    作者:wagtail    | 项目源码 | 文件源码
def load_tests(loader, tests, ignore):
    """
    Creates a ``DocTestSuite`` for each module named in ``DOCTEST_MODULES``
    and adds it to the test run.
    """
    for module in DOCTEST_MODULES:
        tests.addTests(doctest.DocTestSuite(module))
    return tests
项目:sndlatr    作者:Schibum    | 项目源码 | 文件源码
def test_suite():
    "For the Z3 test runner"
    return DocTestSuite()
项目:sndlatr    作者:Schibum    | 项目源码 | 文件源码
def test_suite():
    suite = unittest.TestSuite()
    suite.addTest(doctest.DocTestSuite('pytz'))
    suite.addTest(doctest.DocTestSuite('pytz.tzinfo'))
    import test_tzinfo
    suite.addTest(unittest.defaultTestLoader.loadTestsFromModule(test_tzinfo))
    return suite
项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
def doctests():
    import doctest
    return doctest.DocTestSuite()
项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
def doctests():
    import doctest
    return doctest.DocTestSuite()
项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
def doctests():
    import doctest
    return doctest.DocTestSuite()
项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
def doctests():
    import doctest
    return doctest.DocTestSuite()
项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
def doctests():
    import doctest
    return doctest.DocTestSuite()
项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
def doctests():
    import doctest
    return doctest.DocTestSuite()
项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
def doctests():
    import doctest
    return doctest.DocTestSuite()
项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
def doctests():
    import doctest
    return doctest.DocTestSuite()
项目:pykit    作者:baishancloud    | 项目源码 | 文件源码
def additional_tests():
    suite = unittest.TestSuite()
    for mod in (json, json.encoder, json.decoder):
        suite.addTest(doctest.DocTestSuite(mod))
    suite.addTest(TestPyTest('test_pyjson'))
    suite.addTest(TestCTest('test_cjson'))
    return suite
项目:health-mosconi    作者:GNUHealth-Mosconi    | 项目源码 | 文件源码
def suite():
    suite = unittest.TestSuite()
    suite.addTest(doctest.DocTestSuite(descriptors))
    return suite
项目:health-mosconi    作者:GNUHealth-Mosconi    | 项目源码 | 文件源码
def suite():
    func = unittest.TestLoader().loadTestsFromTestCase
    suite = unittest.TestSuite()
    for testcase in (ToolsTestCase,):
        suite.addTests(func(testcase))
    suite.addTest(doctest.DocTestSuite(decimal_))
    return suite
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def __init__(self, testModule):
        TestSuite.__init__(self)
        suite = doctest.DocTestSuite(testModule)
        for test in suite._tests: #yay encapsulation
            self.addTest(DocTestCase(test))
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def loadDoctests(self, module):
        """
        Return a suite of tests for all the doctests defined in C{module}.

        @param module: A module object or a module name.
        """
        if isinstance(module, str):
            try:
                module = reflect.namedAny(module)
            except:
                return ErrorHolder(module, failure.Failure())
        if not inspect.ismodule(module):
            warnings.warn("trial only supports doctesting modules")
            return
        return DocTestSuite(module)
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def test_suite():
    return doctest.DocTestSuite(distutils.versionpredicate)
项目:touch-pay-client    作者:HackPucBemobi    | 项目源码 | 文件源码
def load_tests(loader, tests, ignore):

    tests.addTests(
        doctest.DocTestSuite('gluon.html')
        )
    tests.addTests(
        doctest.DocTestSuite('gluon.utf8')
        )

    tests.addTests(
        doctest.DocTestSuite('gluon.contrib.markmin.markmin2html',
        )
    )

    return tests
项目:endpointer    作者:devjack    | 项目源码 | 文件源码
def load_tests(loader, tests, ignore):
    tests.addTests(doctest.DocTestSuite("endpointer.definition"))
    tests.addTests(doctest.DocTestSuite("endpointer.specification"))
    return tests
项目:xreload    作者:JayfonLin    | 项目源码 | 文件源码
def test_suite():
    return doctest.DocTestSuite(setUp=setUp, tearDown=tearDown)
项目:flasky    作者:RoseOu    | 项目源码 | 文件源码
def suite():
    from jinja2 import utils, sandbox, runtime, meta, loaders, \
        ext, environment, bccache, nodes
    suite = unittest.TestSuite()
    suite.addTest(doctest.DocTestSuite(utils))
    suite.addTest(doctest.DocTestSuite(sandbox))
    suite.addTest(doctest.DocTestSuite(runtime))
    suite.addTest(doctest.DocTestSuite(meta))
    suite.addTest(doctest.DocTestSuite(loaders))
    suite.addTest(doctest.DocTestSuite(ext))
    suite.addTest(doctest.DocTestSuite(environment))
    suite.addTest(doctest.DocTestSuite(bccache))
    suite.addTest(doctest.DocTestSuite(nodes))
    return suite
项目:Orator-Google-App-Engine    作者:MakarenaLabs    | 项目源码 | 文件源码
def additional_tests(suite=None):
    import simplejson
    import simplejson.encoder
    import simplejson.decoder
    if suite is None:
        suite = unittest.TestSuite()
    for mod in (simplejson, simplejson.encoder, simplejson.decoder):
        suite.addTest(doctest.DocTestSuite(mod))
    suite.addTest(doctest.DocFileSuite('../../index.rst'))
    return suite
项目:calmjs    作者:calmjs    | 项目源码 | 文件源码
def make_suite():  # pragma: no cover
    import calmjs.registry
    test_loader = unittest.TestLoader()
    test_suite = test_loader.discover(
        'calmjs.tests', pattern='test_*.py',
        top_level_dir=dirname(__file__),
    )
    # setting up the finder is a bit annoying for just a one-off.
    test_suite.addTest(doctest.DocTestSuite(calmjs.registry))
    return test_suite
项目:true_review_web2py    作者:lucadealfaro    | 项目源码 | 文件源码
def load_tests(loader, tests, ignore):

    tests.addTests(
        doctest.DocTestSuite('html')
        )
    tests.addTests(
        doctest.DocTestSuite('utf8')
        )

    tests.addTests(
        doctest.DocTestSuite('contrib.markmin.markmin2html',
        )
    )

    return tests
项目:oa_qian    作者:sunqb    | 项目源码 | 文件源码
def suite():
    from jinja2 import utils, sandbox, runtime, meta, loaders, \
        ext, environment, bccache, nodes
    suite = unittest.TestSuite()
    suite.addTest(doctest.DocTestSuite(utils))
    suite.addTest(doctest.DocTestSuite(sandbox))
    suite.addTest(doctest.DocTestSuite(runtime))
    suite.addTest(doctest.DocTestSuite(meta))
    suite.addTest(doctest.DocTestSuite(loaders))
    suite.addTest(doctest.DocTestSuite(ext))
    suite.addTest(doctest.DocTestSuite(environment))
    suite.addTest(doctest.DocTestSuite(bccache))
    suite.addTest(doctest.DocTestSuite(nodes))
    return suite
项目:athlib    作者:openath    | 项目源码 | 文件源码
def my_test_suite():
    test_loader = unittest.TestLoader()
    test_suite = test_loader.discover('tests', pattern='test_*.py')

    from athlib.wma import agegrader
    test_suite.addTests(doctest.DocTestSuite(agegrader))

    from athlib import utils
    test_suite.addTests(doctest.DocTestSuite(utils))

    from athlib import codes
    test_suite.addTests(doctest.DocTestSuite(codes))

    return test_suite
项目:athlib    作者:openath    | 项目源码 | 文件源码
def my_test_suite():
    test_loader = unittest.TestLoader()
    test_suite = test_loader.discover('tests', pattern='test_*.py')

    from athlib.wma import agegrader
    test_suite.addTests(doctest.DocTestSuite(agegrader))

    from athlib import utils
    test_suite.addTests(doctest.DocTestSuite(utils))

    from athlib import codes
    test_suite.addTests(doctest.DocTestSuite(codes))

    return test_suite
项目:Liljimbo-Chatbot    作者:chrisjim316    | 项目源码 | 文件源码
def additional_tests(suite=None):
    import simplejson
    import simplejson.encoder
    import simplejson.decoder
    if suite is None:
        suite = unittest.TestSuite()
    for mod in (simplejson, simplejson.encoder, simplejson.decoder):
        suite.addTest(doctest.DocTestSuite(mod))
    suite.addTest(doctest.DocFileSuite('../../index.rst'))
    return suite
项目:epg-dk.bundle    作者:ukdtom    | 项目源码 | 文件源码
def test_suite():
    suite = unittest.TestSuite()
    suite.addTest(doctest.DocTestSuite('pytz'))
    suite.addTest(doctest.DocTestSuite('pytz.tzinfo'))
    import test_tzinfo
    suite.addTest(unittest.defaultTestLoader.loadTestsFromModule(test_tzinfo))
    return suite
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
def additional_tests(suite=None):
    import simplejson
    import simplejson.encoder
    import simplejson.decoder
    if suite is None:
        suite = unittest.TestSuite()
    for mod in (simplejson, simplejson.encoder, simplejson.decoder):
        suite.addTest(doctest.DocTestSuite(mod))
    suite.addTest(doctest.DocFileSuite('../../index.rst'))
    return suite
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
def test_main(verbose=None):
    NamedTupleDocs = doctest.DocTestSuite(module=collections)
    test_classes = [TestNamedTuple, NamedTupleDocs, TestOneTrickPonyABCs,
                    TestCollectionABCs, TestCounter, TestChainMap,
                    TestOrderedDict, GeneralMappingTests, SubclassMappingTests]
    support.run_unittest(*test_classes)
    support.run_doctest(collections, verbose)
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
def test_suite():
    import doctest
    return doctest.DocTestSuite()
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
def additional_tests():
    suite = unittest.TestSuite()
    for mod in (json, json.encoder, json.decoder):
        suite.addTest(doctest.DocTestSuite(mod))
    suite.addTest(TestPyTest('test_pyjson'))
    suite.addTest(TestCTest('test_cjson'))
    return suite
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
def test_main():
    difflib.HtmlDiff._default_prefix = 0
    Doctests = doctest.DocTestSuite(difflib)
    run_unittest(
        TestWithAscii, TestAutojunk, TestSFpatches, TestSFbugs,
        TestOutputFormat, Doctests)
项目:Django-Web-Development-with-Python    作者:PacktPublishing    | 项目源码 | 文件源码
def load_tests(loader, tests, ignore):
    tests.addTests(doctest.DocTestSuite(mydoctests))
    return tests