我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用doctest.DocTestSuite()。
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)
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)
def testsuite(): import doctest return doctest.DocTestSuite(optionflags=doctest.IGNORE_EXCEPTION_DETAIL)
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 )
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)
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)
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
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
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
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
def load_tests(loader, tests, ignore): tests.addTests(DocTestSuite('runcommands.util.decorators')) tests.addTests(DocTestSuite('runcommands.util.path')) return tests
def load_tests(loader, tests, ignore): tests.addTests(DocTestSuite('runcommands.config')) return tests
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
def test_suite(): "For the Z3 test runner" return DocTestSuite()
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
def doctests(): import doctest return doctest.DocTestSuite()
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
def suite(): suite = unittest.TestSuite() suite.addTest(doctest.DocTestSuite(descriptors)) return suite
def suite(): func = unittest.TestLoader().loadTestsFromTestCase suite = unittest.TestSuite() for testcase in (ToolsTestCase,): suite.addTests(func(testcase)) suite.addTest(doctest.DocTestSuite(decimal_)) return suite
def __init__(self, testModule): TestSuite.__init__(self) suite = doctest.DocTestSuite(testModule) for test in suite._tests: #yay encapsulation self.addTest(DocTestCase(test))
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)
def test_suite(): return doctest.DocTestSuite(distutils.versionpredicate)
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
def load_tests(loader, tests, ignore): tests.addTests(doctest.DocTestSuite("endpointer.definition")) tests.addTests(doctest.DocTestSuite("endpointer.specification")) return tests
def test_suite(): return doctest.DocTestSuite(setUp=setUp, tearDown=tearDown)
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
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
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
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
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)
def test_suite(): import doctest return doctest.DocTestSuite()
def test_main(): difflib.HtmlDiff._default_prefix = 0 Doctests = doctest.DocTestSuite(difflib) run_unittest( TestWithAscii, TestAutojunk, TestSFpatches, TestSFbugs, TestOutputFormat, Doctests)
def load_tests(loader, tests, ignore): tests.addTests(doctest.DocTestSuite(mydoctests)) return tests