当前位置: 首页>>代码示例>>Python>>正文


Python doctest.testfile方法代码示例

本文整理汇总了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) 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:26,代码来源:doctest.py

示例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}") 
开发者ID:PacktPublishing,项目名称:Mastering-Object-Oriented-Python-Second-Edition,代码行数:19,代码来源:test_all.py

示例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)) 
开发者ID:vinci1it2000,项目名称:formulas,代码行数:8,代码来源:test_readme.py

示例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]) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:13,代码来源:test_zipimport.py

示例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. 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:33,代码来源:test_doctest.py

示例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) 
开发者ID:sagemath,项目名称:cysignals,代码行数:15,代码来源:rundoctests.py

示例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) 
开发者ID:boriel,项目名称:zxbasic,代码行数:10,代码来源:test_.py

示例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. 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:31,代码来源:test_doctest.py

示例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 
开发者ID:micheles,项目名称:plac,代码行数:5,代码来源:test_plac.py

示例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
            ) 
开发者ID:pytest-dev,项目名称:pytest,代码行数:28,代码来源:doctest.py

示例11: test

# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import testfile [as 别名]
def test():
    import doctest
    doctest.NORMALIZE_WHITESPACE = 1
    doctest.testfile("README.txt", verbose=1) 
开发者ID:danvk,项目名称:oldnyc,代码行数:6,代码来源:shapefile.py

示例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 
开发者ID:terrapower,项目名称:armi,代码行数:17,代码来源:test_docs.py

示例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)

""" 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:31,代码来源:test_doctest.py

示例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) 
开发者ID:serge-sans-paille,项目名称:beniget,代码行数:5,代码来源:doc.py

示例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) 
开发者ID:proofit404,项目名称:stories,代码行数:9,代码来源:mddoctest.py


注:本文中的doctest.testfile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。