當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。