本文整理匯總了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)