本文整理汇总了Python中doctest.master方法的典型用法代码示例。如果您正苦于以下问题:Python doctest.master方法的具体用法?Python doctest.master怎么用?Python doctest.master使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类doctest
的用法示例。
在下文中一共展示了doctest.master方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _test
# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import master [as 别名]
def _test(reset=0):
import doctest, wntools
if reset:
doctest.master = None # This keeps doctest from complaining after a reload.
return doctest.testmod(wntools)
示例2: _test
# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import master [as 别名]
def _test(reset=0):
import doctest, wordnet
if reset:
doctest.master = None # This keeps doctest from complaining after a reload.
return doctest.testmod(wordnet)
示例3: doDoctestFile
# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import master [as 别名]
def doDoctestFile(self, module):
log = []
old_master, doctest.master = doctest.master, None
try:
doctest.testfile(
'xyz.txt', package=module, module_relative=True,
globs=locals()
)
finally:
doctest.master = old_master
self.assertEqual(log,[True])
示例4: doctest_reload
# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import master [as 别名]
def doctest_reload():
"""Properly reload doctest to reuse it interactively.
This routine:
- imports doctest but does NOT reload it (see below).
- resets its global 'master' attribute to None, so that multiple uses of
the module interactively don't produce cumulative reports.
- Monkeypatches its core test runner method to protect it from IPython's
modified displayhook. Doctest expects the default displayhook behavior
deep down, so our modification breaks it completely. For this reason, a
hard monkeypatch seems like a reasonable solution rather than asking
users to manually use a different doctest runner when under IPython.
Notes
-----
As of Python 2.6.6, 2.7.1 and 3.2, this monkeypatching is no longer required.
doctest now takes care of resetting sys.displayhook itself. This function
remains for now in case anyone has to work with older versions, but it's
no longer called during IPython startup.
This function *used to* reload doctest, but this has been disabled because
reloading doctest unconditionally can cause massive breakage of other
doctest-dependent modules already in memory, such as those for IPython's
own testing system. The name wasn't changed to avoid breaking people's
code, but the reload call isn't actually made anymore."""
import doctest
doctest.master = None
doctest.DocTestRunner.run = dhook_wrap(doctest.DocTestRunner.run)
示例5: test
# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import master [as 别名]
def test(self, label='fast', verbose=1, extra_argv=['--exe'],
doctests=False, coverage=False, **kwargs):
''' Run tests for module using nose
%(test_header)s
doctests : boolean
If True, run doctests in module, default False
coverage : boolean
If True, report coverage of NumPy code, default False
(Requires the coverage module:
http://nedbatchelder.com/code/modules/coverage.html)
kwargs
Passed to numpy.errstate. See its documentation for details.
'''
# cap verbosity at 3 because nose becomes *very* verbose beyond that
verbose = min(verbose, 3)
from numpy.testing import utils
utils.verbose = verbose
if doctests:
print("Running unit tests and doctests for %s" % self.package_name)
else:
print("Running unit tests for %s" % self.package_name)
self._show_system_info()
# reset doctest state on every run
import doctest
doctest.master = None
argv, plugins = self.prepare_test_args(label, verbose, extra_argv,
doctests, coverage)
from numpy.testing.noseclasses import NumpyTestProgram
with errstate(**kwargs):
simplefilter('ignore', category=DeprecationWarning)
t = NumpyTestProgram(argv=argv, exit=False, plugins=plugins)
return t.result
示例6: dash_R_cleanup
# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import master [as 别名]
def dash_R_cleanup(fs, ps, pic):
import gc, copy_reg
import _strptime, linecache, dircache
import urlparse, urllib, urllib2, mimetypes, doctest
import struct, filecmp
from distutils.dir_util import _path_created
# Restore some original values.
warnings.filters[:] = fs
copy_reg.dispatch_table.clear()
copy_reg.dispatch_table.update(ps)
sys.path_importer_cache.clear()
sys.path_importer_cache.update(pic)
# Clear assorted module caches.
_path_created.clear()
re.purge()
_strptime._regex_cache.clear()
urlparse.clear_cache()
urllib.urlcleanup()
urllib2.install_opener(None)
dircache.reset()
linecache.clearcache()
mimetypes._default_mime_types()
struct._cache.clear()
filecmp._cache.clear()
doctest.master = None
# Collect cyclic trash.
gc.collect()
示例7: run_test_file_with_config
# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import master [as 别名]
def run_test_file_with_config(filename, globs, optionflags):
"""Modified from doctest.py to use custom checker."""
text, filename = _load_testfile(filename)
name = os.path.basename(filename)
if globs is None:
globs = {}
else:
globs = globs.copy()
if '__name__' not in globs:
globs['__name__'] = '__main__'
checker = Py23DocChecker()
runner = TestRunner(checker=checker, verbose=None, optionflags=optionflags)
parser = doctest.DocTestParser()
test = parser.get_doctest(text, globs, name, filename, 0)
flags = (
print_function.compiler_flag
| absolute_import.compiler_flag
| division.compiler_flag
)
runner.run(test, flags)
results = runner.summarize()
if doctest.master is None:
doctest.master = runner
else:
doctest.master.merge(runner)
return results
示例8: summarize
# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import master [as 别名]
def summarize(self, verbose=None):
"""
Print a summary of all the test cases that have been run by
this DocTestRunner, and return a tuple `(f, t)`, where `f` is
the total number of failed examples, and `t` is the total
number of tried examples.
The optional `verbose` argument controls how detailed the
summary is. If the verbosity is not specified, then the
DocTestRunner's verbosity is used.
"""
if verbose is None:
verbose = self._verbose
notests = []
passed = []
failed = []
totalt = totalf = 0
for x in self._name2ft.items():
name, (f, t) = x
assert f <= t
totalt += t
totalf += f
if t == 0:
notests.append(name)
elif f == 0:
passed.append( (name, t) )
else:
failed.append(x)
if verbose:
if notests:
print len(notests), "items had no tests:"
notests.sort()
for thing in notests:
print " ", thing
if passed:
print len(passed), "items passed all tests:"
passed.sort()
for thing, count in passed:
print " %3d tests in %s" % (count, thing)
if failed:
print self.DIVIDER
print len(failed), "items had failures:"
failed.sort()
for thing, (f, t) in failed:
print " %3d of %3d in %s" % (f, t, thing)
if verbose:
print totalt, "tests in", len(self._name2ft), "items."
print totalt - totalf, "passed and", totalf, "failed."
if totalf:
print "***Test Failed***", totalf, "failures."
elif verbose:
print "Test passed."
return totalf, totalt
#/////////////////////////////////////////////////////////////////
# Backward compatibility cruft to maintain doctest.master.
#/////////////////////////////////////////////////////////////////
示例9: summarize
# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import master [as 别名]
def summarize(self, verbose=None):
"""
Print a summary of all the test cases that have been run by
this DocTestRunner, and return a tuple `(f, t)`, where `f` is
the total number of failed examples, and `t` is the total
number of tried examples.
The optional `verbose` argument controls how detailed the
summary is. If the verbosity is not specified, then the
DocTestRunner's verbosity is used.
"""
if verbose is None:
verbose = self._verbose
notests = []
passed = []
failed = []
totalt = totalf = 0
for x in self._name2ft.items():
name, (f, t) = x
assert f <= t
totalt += t
totalf += f
if t == 0:
notests.append(name)
elif f == 0:
passed.append( (name, t) )
else:
failed.append(x)
if verbose:
if notests:
print len(notests), "items had no tests:"
notests.sort()
for thing in notests:
print " ", thing
if passed:
print len(passed), "items passed all tests:"
passed.sort()
for thing, count in passed:
print " %3d tests in %s" % (count, thing)
if failed:
print self.DIVIDER
print len(failed), "items had failures:"
failed.sort()
for thing, (f, t) in failed:
print " %3d of %3d in %s" % (f, t, thing)
if verbose:
print totalt, "tests in", len(self._name2ft), "items."
print totalt - totalf, "passed and", totalf, "failed."
if totalf:
print "***Test Failed***", totalf, "failures."
elif verbose:
print "Test passed."
return TestResults(totalf, totalt)
#/////////////////////////////////////////////////////////////////
# Backward compatibility cruft to maintain doctest.master.
#/////////////////////////////////////////////////////////////////
示例10: summarize
# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import master [as 别名]
def summarize(self, verbose=None):
"""
Print a summary of all the test cases that have been run by
this DocTestRunner, and return a tuple `(f, t)`, where `f` is
the total number of failed examples, and `t` is the total
number of tried examples.
The optional `verbose` argument controls how detailed the
summary is. If the verbosity is not specified, then the
DocTestRunner's verbosity is used.
"""
if verbose is None:
verbose = self._verbose
notests = []
passed = []
failed = []
totalt = totalf = 0
for x in self._name2ft.items():
name, (f, t) = x
assert f <= t
totalt += t
totalf += f
if t == 0:
notests.append(name)
elif f == 0:
passed.append( (name, t) )
else:
failed.append(x)
if verbose:
if notests:
print(len(notests), "items had no tests:")
notests.sort()
for thing in notests:
print(" ", thing)
if passed:
print(len(passed), "items passed all tests:")
passed.sort()
for thing, count in passed:
print(" %3d tests in %s" % (count, thing))
if failed:
print(self.DIVIDER)
print(len(failed), "items had failures:")
failed.sort()
for thing, (f, t) in failed:
print(" %3d of %3d in %s" % (f, t, thing))
if verbose:
print(totalt, "tests in", len(self._name2ft), "items.")
print(totalt - totalf, "passed and", totalf, "failed.")
if totalf:
print("***Test Failed***", totalf, "failures.")
elif verbose:
print("Test passed.")
return totalf, totalt
#/////////////////////////////////////////////////////////////////
# Backward compatibility cruft to maintain doctest.master.
#/////////////////////////////////////////////////////////////////
示例11: dash_R_cleanup
# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import master [as 别名]
def dash_R_cleanup(fs, ps, pic, zdc, abcs):
import gc, copy_reg
import _strptime, linecache
dircache = test_support.import_module('dircache', deprecated=True)
import urlparse, urllib, urllib2, mimetypes, doctest
import struct, filecmp
from distutils.dir_util import _path_created
# Clear the warnings registry, so they can be displayed again
for mod in sys.modules.values():
if hasattr(mod, '__warningregistry__'):
del mod.__warningregistry__
# Restore some original values.
warnings.filters[:] = fs
copy_reg.dispatch_table.clear()
copy_reg.dispatch_table.update(ps)
sys.path_importer_cache.clear()
sys.path_importer_cache.update(pic)
try:
import zipimport
except ImportError:
pass # Run unmodified on platforms without zipimport support
else:
zipimport._zip_directory_cache.clear()
zipimport._zip_directory_cache.update(zdc)
# clear type cache
sys._clear_type_cache()
# Clear ABC registries, restoring previously saved ABC registries.
for abc, registry in abcs.items():
abc._abc_registry = registry.copy()
abc._abc_cache.clear()
abc._abc_negative_cache.clear()
# Clear assorted module caches.
_path_created.clear()
re.purge()
_strptime._regex_cache.clear()
urlparse.clear_cache()
urllib.urlcleanup()
urllib2.install_opener(None)
dircache.reset()
linecache.clearcache()
mimetypes._default_mime_types()
filecmp._cache.clear()
struct._clearcache()
doctest.master = None
try:
import ctypes
except ImportError:
# Don't worry about resetting the cache if ctypes is not supported
pass
else:
ctypes._reset_cache()
# Collect cyclic trash.
gc.collect()
示例12: summarize
# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import master [as 别名]
def summarize(self, verbose=None):
"""
Print a summary of all the test cases that have been run by
this DocTestRunner, and return a tuple `(f, t)`, where `f` is
the total number of failed examples, and `t` is the total
number of tried examples.
The optional `verbose` argument controls how detailed the
summary is. If the verbosity is not specified, then the
DocTestRunner's verbosity is used.
"""
if verbose is None:
verbose = self._verbose
notests = []
passed = []
failed = []
totalt = totalf = 0
for x in self._name2ft.items():
name, (f, t) = x
assert f <= t
totalt += t
totalf += f
if t == 0:
notests.append(name)
elif f == 0:
passed.append( (name, t) )
else:
failed.append(x)
if verbose:
if notests:
print(len(notests), "items had no tests:")
notests.sort()
for thing in notests:
print(" ", thing)
if passed:
print(len(passed), "items passed all tests:")
passed.sort()
for thing, count in passed:
print(" %3d tests in %s" % (count, thing))
if failed:
print(self.DIVIDER)
print(len(failed), "items had failures:")
failed.sort()
for thing, (f, t) in failed:
print(" %3d of %3d in %s" % (f, t, thing))
if verbose:
print(totalt, "tests in", len(self._name2ft), "items.")
print(totalt - totalf, "passed and", totalf, "failed.")
if totalf:
print("***Test Failed***", totalf, "failures.")
elif verbose:
print("Test passed.")
return TestResults(totalf, totalt)
#/////////////////////////////////////////////////////////////////
# Backward compatibility cruft to maintain doctest.master.
#/////////////////////////////////////////////////////////////////