本文整理汇总了Python中doctest.testmod方法的典型用法代码示例。如果您正苦于以下问题:Python doctest.testmod方法的具体用法?Python doctest.testmod怎么用?Python doctest.testmod使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类doctest
的用法示例。
在下文中一共展示了doctest.testmod方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_basic_functions
# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import testmod [as 别名]
def test_basic_functions(self):
import code
import doctest
import sys
db = pg_simple.PgSimple(self.pool)
if sys.argv.count('--interact'):
db.log = sys.stdout
code.interact(local=locals())
else:
try:
# Setup tables
self._drop_tables(db)
self._create_tables(db, fill=True)
# Run tests
doctest.testmod(optionflags=doctest.ELLIPSIS)
finally:
# Drop tables
self._drop_tables(db)
self.assertEqual(True, True)
示例2: __init__
# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import testmod [as 别名]
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
示例3: _test
# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import testmod [as 别名]
def _test():
import os
import doctest
from pyspark.context import SparkContext
from pyspark.sql import Row
import pyspark.sql.session
os.chdir(os.environ["SPARK_HOME"])
globs = pyspark.sql.session.__dict__.copy()
sc = SparkContext('local[4]', 'PythonTest')
globs['sc'] = sc
globs['spark'] = SparkSession(sc)
globs['rdd'] = rdd = sc.parallelize(
[Row(field1=1, field2="row1"),
Row(field1=2, field2="row2"),
Row(field1=3, field2="row3")])
globs['df'] = rdd.toDF()
(failure_count, test_count) = doctest.testmod(
pyspark.sql.session, globs=globs,
optionflags=doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE)
globs['sc'].stop()
if failure_count:
sys.exit(-1)
示例4: _test
# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import testmod [as 别名]
def _test():
import os
import doctest
from pyspark.context import SparkContext
from pyspark.sql import Row
import pyspark.sql.session
os.chdir(os.environ["SPARK_HOME"])
globs = pyspark.sql.session.__dict__.copy()
sc = SparkContext('local[4]', 'PythonTest')
globs['sc'] = sc
globs['spark'] = SparkSession(sc)
globs['rdd'] = rdd = sc.parallelize(
[Row(field1=1, field2="row1"),
Row(field1=2, field2="row2"),
Row(field1=3, field2="row3")])
globs['df'] = rdd.toDF()
(failure_count, test_count) = doctest.testmod(
pyspark.sql.session, globs=globs,
optionflags=doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE)
globs['sc'].stop()
if failure_count:
exit(-1)
示例5: test
# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import testmod [as 别名]
def test():
import doctest
print("----------------------------------------------------------")
print("expr")
print("----------------------------------------------------------")
doctest.testmod(expr, verbose=True, raise_on_error=False, optionflags=doctest.ELLIPSIS)
expr.TestExpr().run()
print("----------------------------------------------------------")
print("algebraic")
print("----------------------------------------------------------")
doctest.testmod(algebraic, verbose=True, raise_on_error=True, optionflags=doctest.ELLIPSIS)
algebraic.TestAlgebraic().run()
print("----------------------------------------------------------")
print("brain")
print("----------------------------------------------------------")
doctest.testmod(brain, verbose=True, raise_on_error=True, optionflags=doctest.ELLIPSIS)
TestBrain().run()
示例6: _test
# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import testmod [as 别名]
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
示例7: rundoctests
# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import testmod [as 别名]
def rundoctests(verbose=False):
"""
Executes doctests
"""
import doctest
import lms as testmod1
import nlms as testmod2
import ap as testmod3
import misc as testmod4
import nlmsru as testmod5
lmsres = doctest.testmod(testmod1, verbose=verbose)
nlmsres = doctest.testmod(testmod2, verbose=verbose)
apres = doctest.testmod(testmod3, verbose=verbose)
miscres = doctest.testmod(testmod4, verbose=verbose)
nlmsrures = doctest.testmod(testmod5, verbose=verbose)
print ' LMS: ', lmsres
print ' NLMS: ', nlmsres
print 'NLMSRU: ', nlmsrures
print ' AP: ', apres
print ' MISC: ', miscres
示例8: test_symbols
# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import testmod [as 别名]
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)
示例9: test_ndarray
# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import testmod [as 别名]
def test_ndarray():
globs = {'np': numpy, 'mx': mxnet}
doctest.testmod(mxnet.ndarray, globs=globs, verbose=True)
示例10: run
# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import testmod [as 别名]
def run(self) -> doctest.TestResults:
return doctest.testmod(self.mod,
globs=self.test_globals,
report=False,
verbose=False)
示例11: _test
# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import testmod [as 别名]
def _test():
import doctest, difflib
return doctest.testmod(difflib)
示例12: run_doctest
# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import testmod [as 别名]
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.
示例13: _test
# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import testmod [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)
示例14: _test
# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import testmod [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)
示例15: test
# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import testmod [as 别名]
def test():
"Run unit tests on unification."
import doctest
doctest.testmod()