本文整理汇总了Python中doctest.testfile方法的典型用法代码示例。如果您正苦于以下问题:Python doctest.testfile方法的具体用法?Python doctest.testfile怎么用?Python doctest.testfile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类doctest
的用法示例。
在下文中一共展示了doctest.testfile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: collect
# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import testfile [as 别名]
def collect(self):
import doctest
# inspired by doctest.testfile; ideally we would use it directly,
# but it doesn't support passing a custom checker
encoding = self.config.getini("doctest_encoding")
text = self.fspath.read_text(encoding)
filename = str(self.fspath)
name = self.fspath.basename
globs = {"__name__": "__main__"}
optionflags = get_optionflags(self)
runner = _get_runner(
verbose=0,
optionflags=optionflags,
checker=_get_checker(),
continue_on_failure=_get_continue_on_failure(self.config),
)
parser = doctest.DocTestParser()
test = parser.get_doctest(text, globs, name, filename, 0)
if test.examples:
yield DoctestItem(test.name, self, runner, test)
示例2: run_doctest_suite
# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import testfile [as 别名]
def run_doctest_suite(pkg_mod_iter: Iterable[Tuple[Path, Iterable[Path]]]) -> None:
"""Doctest each module individually. With a few exclusions.
Might be simpler to use doctest.testfile()? However, the examples aren't laid out for this.
"""
for package, module_iter in pkg_mod_iter:
print()
print(package.name)
print("="*len(package.name))
print()
for module_path in module_iter:
if module_path.stem in DOCTEST_EXCLUDE:
print(f"Excluding {module_path}")
continue
result = subprocess.run(['python3', '-m', 'doctest', str(module_path)])
if result.returncode != 0:
sys.exit(f"Failure {result!r} in {module_path}")
示例3: runTest
# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import testfile [as 别名]
def runTest(self):
failure_count, test_count = doctest.testfile(
'../README.rst', optionflags=doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS
)
self.assertGreater(test_count, 0, (failure_count, test_count))
self.assertEqual(failure_count, 0, (failure_count, test_count))
示例4: doDoctestFile
# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import testfile [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])
示例5: test_lineendings
# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import testfile [as 别名]
def test_lineendings(): r"""
*nix systems use \n line endings, while Windows systems use \r\n. Python
handles this using universal newline mode for reading files. Let's make
sure doctest does so (issue 8473) by creating temporary test files using each
of the two line disciplines. One of the two will be the "wrong" one for the
platform the test is run on.
Windows line endings first:
>>> import tempfile, os
>>> fn = tempfile.mktemp()
>>> with open(fn, 'wb') as f:
... f.write('Test:\r\n\r\n >>> x = 1 + 1\r\n\r\nDone.\r\n')
>>> doctest.testfile(fn, module_relative=False, verbose=False)
TestResults(failed=0, attempted=1)
>>> os.remove(fn)
And now *nix line endings:
>>> fn = tempfile.mktemp()
>>> with open(fn, 'wb') as f:
... f.write('Test:\n\n >>> x = 1 + 1\n\nDone.\n')
>>> doctest.testfile(fn, module_relative=False, verbose=False)
TestResults(failed=0, attempted=1)
>>> os.remove(fn)
"""
# old_test1, ... used to live in doctest.py, but cluttered it. Note
# that these use the deprecated doctest.Tester, so should go away (or
# be rewritten) someday.
示例6: testfile
# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import testfile [as 别名]
def testfile(file):
# Child process
try:
if sys.platform == 'darwin':
from cysignals.signals import _setup_alt_stack
_setup_alt_stack()
failures, _ = doctest.testfile(file, module_relative=False, optionflags=flags, parser=parser)
if not failures:
os._exit(0)
except BaseException as E:
print(E)
finally:
os._exit(23)
示例7: main
# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import testfile [as 别名]
def main():
current_path = os.path.abspath(os.getcwd())
os.chdir(os.path.realpath(os.path.dirname(__file__) or os.curdir))
result = doctest.testfile('test_errmsg.txt') # evaluates to True on failure
if not result.failed:
result = doctest.testfile('test_cmdline.txt') # Evaluates to True on failure
os.chdir(current_path)
return int(result.failed)
示例8: test_lineendings
# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import testfile [as 别名]
def test_lineendings(): r"""
*nix systems use \n line endings, while Windows systems use \r\n. Python
handles this using universal newline mode for reading files. Let's make
sure doctest does so (issue 8473) by creating temporary test files using each
of the two line disciplines. One of the two will be the "wrong" one for the
platform the test is run on.
Windows line endings first:
>>> import tempfile, os
>>> fn = tempfile.mktemp()
>>> open(fn, 'w').write('Test:\r\n\r\n >>> x = 1 + 1\r\n\r\nDone.\r\n')
>>> doctest.testfile(fn, False)
TestResults(failed=0, attempted=1)
>>> os.remove(fn)
And now *nix line endings:
>>> fn = tempfile.mktemp()
>>> open(fn, 'w').write('Test:\n\n >>> x = 1 + 1\n\nDone.\n')
>>> doctest.testfile(fn, False)
TestResults(failed=0, attempted=1)
>>> os.remove(fn)
"""
# old_test1, ... used to live in doctest.py, but cluttered it. Note
# that these use the deprecated doctest.Tester, so should go away (or
# be rewritten) someday.
示例9: test_doctest
# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import testfile [as 别名]
def test_doctest():
failure, tot = doctest.testfile('index.rst', module_relative=False)
assert not failure, failure
示例10: collect
# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import testfile [as 别名]
def collect(self) -> Iterable[DoctestItem]:
import doctest
# inspired by doctest.testfile; ideally we would use it directly,
# but it doesn't support passing a custom checker
encoding = self.config.getini("doctest_encoding")
text = self.fspath.read_text(encoding)
filename = str(self.fspath)
name = self.fspath.basename
globs = {"__name__": "__main__"}
optionflags = get_optionflags(self)
runner = _get_runner(
verbose=False,
optionflags=optionflags,
checker=_get_checker(),
continue_on_failure=_get_continue_on_failure(self.config),
)
parser = doctest.DocTestParser()
test = parser.get_doctest(text, globs, name, filename, 0)
if test.examples:
yield DoctestItem.from_parent(
self, name=test.name, runner=runner, dtest=test
)
示例11: test
# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import testfile [as 别名]
def test():
import doctest
doctest.NORMALIZE_WHITESPACE = 1
doctest.testfile("README.txt", verbose=1)
示例12: test_docsHaveWorkingCodeExamples
# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import testfile [as 别名]
def test_docsHaveWorkingCodeExamples(self):
for root, _dirs, files in os.walk(armi.DOC):
for f in files:
fullpath = os.path.join(root, f)
base, xtn = os.path.splitext(fullpath)
if (
xtn != ".rst" or ".armidocs" in base
): # skip non rst and auto-generated rst
continue
try:
doctest.testfile(fullpath)
except Exception as ee:
pass
示例13: test_lineendings
# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import testfile [as 别名]
def test_lineendings(): r"""
*nix systems use \n line endings, while Windows systems use \r\n. Python
handles this using universal newline mode for reading files. Let's make
sure doctest does so (issue 8473) by creating temporary test files using each
of the two line disciplines. One of the two will be the "wrong" one for the
platform the test is run on.
Windows line endings first:
>>> import tempfile, os
>>> fn = tempfile.mktemp()
>>> with open(fn, 'wb') as f:
... f.write(b'Test:\r\n\r\n >>> x = 1 + 1\r\n\r\nDone.\r\n')
35
>>> doctest.testfile(fn, False)
TestResults(failed=0, attempted=1)
>>> os.remove(fn)
And now *nix line endings:
>>> fn = tempfile.mktemp()
>>> with open(fn, 'wb') as f:
... f.write(b'Test:\n\n >>> x = 1 + 1\n\nDone.\n')
30
>>> doctest.testfile(fn, False)
TestResults(failed=0, attempted=1)
>>> os.remove(fn)
"""
示例14: test_beniget_readme
# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import testfile [as 别名]
def test_beniget_readme(self):
failed, _ = doctest.testfile(os.path.join("..", "README.rst"))
self.assertEqual(failed, 0)
示例15: _main
# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import testfile [as 别名]
def _main():
markdown_files = glob("**/*.md", recursive=True)
exit_code = 0
for markdown_file in markdown_files:
failed, attempted = testfile(markdown_file, module_relative=False)
exit_code += failed
exit(exit_code)