當前位置: 首頁>>代碼示例>>Python>>正文


Python doctest.DocTestFailure方法代碼示例

本文整理匯總了Python中doctest.DocTestFailure方法的典型用法代碼示例。如果您正苦於以下問題:Python doctest.DocTestFailure方法的具體用法?Python doctest.DocTestFailure怎麽用?Python doctest.DocTestFailure使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在doctest的用法示例。


在下文中一共展示了doctest.DocTestFailure方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _check_docs

# 需要導入模塊: import doctest [as 別名]
# 或者: from doctest import DocTestFailure [as 別名]
def _check_docs(self, module):
        if self._skip:
            # Printing this directly to __stdout__ so that it doesn't get
            # captured by nose.
            print("Warning: Skipping doctests for %s because "
                  "pdbpp is installed." % module.__name__, file=sys.__stdout__)
            return
        try:
            doctest.testmod(
                module,
                verbose=True,
                raise_on_error=True,
                optionflags=self.flags,
            )
        except doctest.UnexpectedException as e:
            raise e.exc_info[1]
        except doctest.DocTestFailure as e:
            print("Got:")
            print(e.got)
            raise 
開發者ID:zhanghan1990,項目名稱:zipline-chinese,代碼行數:22,代碼來源:test_doctests.py

示例2: _init_runner_class

# 需要導入模塊: import doctest [as 別名]
# 或者: from doctest import DocTestFailure [as 別名]
def _init_runner_class():
    import doctest

    class PytestDoctestRunner(doctest.DebugRunner):
        """
        Runner to collect failures.  Note that the out variable in this case is
        a list instead of a stdout-like object
        """

        def __init__(
            self, checker=None, verbose=None, optionflags=0, continue_on_failure=True
        ):
            doctest.DebugRunner.__init__(
                self, checker=checker, verbose=verbose, optionflags=optionflags
            )
            self.continue_on_failure = continue_on_failure

        def report_failure(self, out, test, example, got):
            failure = doctest.DocTestFailure(test, example, got)
            if self.continue_on_failure:
                out.append(failure)
            else:
                raise failure

        def report_unexpected_exception(self, out, test, example, exc_info):
            if isinstance(exc_info[1], Skipped):
                raise exc_info[1]
            failure = doctest.UnexpectedException(test, example, exc_info)
            if self.continue_on_failure:
                out.append(failure)
            else:
                raise failure

    return PytestDoctestRunner 
開發者ID:sofia-netsurv,項目名稱:python-netsurv,代碼行數:36,代碼來源:doctest.py

示例3: __init__

# 需要導入模塊: import doctest [as 別名]
# 或者: from doctest import DocTestFailure [as 別名]
def __init__(self, failures: "Sequence[doctest.DocTestFailure]") -> None:
        super().__init__()
        self.failures = failures 
開發者ID:pytest-dev,項目名稱:pytest,代碼行數:5,代碼來源:doctest.py

示例4: runtest

# 需要導入模塊: import doctest [as 別名]
# 或者: from doctest import DocTestFailure [as 別名]
def runtest(self) -> None:
        assert self.dtest is not None
        assert self.runner is not None
        _check_all_skipped(self.dtest)
        self._disable_output_capturing_for_darwin()
        failures = []  # type: List[doctest.DocTestFailure]
        # Type ignored because we change the type of `out` from what
        # doctest expects.
        self.runner.run(self.dtest, out=failures)  # type: ignore[arg-type] # noqa: F821
        if failures:
            raise MultipleDoctestFailures(failures) 
開發者ID:pytest-dev,項目名稱:pytest,代碼行數:13,代碼來源:doctest.py

示例5: test_docstrings

# 需要導入模塊: import doctest [as 別名]
# 或者: from doctest import DocTestFailure [as 別名]
def test_docstrings(self, urlopen):
        pretend_html = b"<!DOCTYPE HTML ...blah blah blah"
        responses.add("GET", "http://www.salesforce.com/", body=pretend_html)
        fake_http_stream = BytesIO(pretend_html)
        fake_http_stream.url = "https://www.salesforce.com/"
        urlopen.return_value = fake_http_stream
        try:
            doctest.testmod(fileutils, raise_on_error=True, verbose=True)
        except doctest.DocTestFailure as e:
            print("Got")
            print(str(e.got))
            raise 
開發者ID:SFDO-Tooling,項目名稱:CumulusCI,代碼行數:14,代碼來源:test_fileutils.py

示例6: test_readme

# 需要導入模塊: import doctest [as 別名]
# 或者: from doctest import DocTestFailure [as 別名]
def test_readme():
    failure = None

    try:
        doctest.testfile('../README.md', raise_on_error=True, globs={'P': P})
    except doctest.DocTestFailure as e:
        failure = e.example.want, e.got, e.example.source

    if failure:
        # Make pytest display it outside the "except" block, to avoid a noisy traceback
        want, got, example = failure
        assert want.strip() == got.strip(), 'DocTest failure in "{}"'.format(example.strip())
        assert False  # In case .strip() removed something useful 
開發者ID:AlexandreDecan,項目名稱:portion,代碼行數:15,代碼來源:test_doc.py

示例7: repr_failure

# 需要導入模塊: import doctest [as 別名]
# 或者: from doctest import DocTestFailure [as 別名]
def repr_failure(self, excinfo):
        import doctest

        failures = None
        if excinfo.errisinstance((doctest.DocTestFailure, doctest.UnexpectedException)):
            failures = [excinfo.value]
        elif excinfo.errisinstance(MultipleDoctestFailures):
            failures = excinfo.value.failures

        if failures is not None:
            reprlocation_lines = []
            for failure in failures:
                example = failure.example
                test = failure.test
                filename = test.filename
                if test.lineno is None:
                    lineno = None
                else:
                    lineno = test.lineno + example.lineno + 1
                message = type(failure).__name__
                reprlocation = ReprFileLocation(filename, lineno, message)
                checker = _get_checker()
                report_choice = _get_report_choice(
                    self.config.getoption("doctestreport")
                )
                if lineno is not None:
                    lines = failure.test.docstring.splitlines(False)
                    # add line numbers to the left of the error message
                    lines = [
                        "%03d %s" % (i + test.lineno + 1, x)
                        for (i, x) in enumerate(lines)
                    ]
                    # trim docstring error lines to 10
                    lines = lines[max(example.lineno - 9, 0) : example.lineno + 1]
                else:
                    lines = [
                        "EXAMPLE LOCATION UNKNOWN, not showing all tests of that example"
                    ]
                    indent = ">>>"
                    for line in example.source.splitlines():
                        lines.append("??? {} {}".format(indent, line))
                        indent = "..."
                if isinstance(failure, doctest.DocTestFailure):
                    lines += checker.output_difference(
                        example, failure.got, report_choice
                    ).split("\n")
                else:
                    inner_excinfo = ExceptionInfo(failure.exc_info)
                    lines += ["UNEXPECTED EXCEPTION: %s" % repr(inner_excinfo.value)]
                    lines += traceback.format_exception(*failure.exc_info)
                reprlocation_lines.append((reprlocation, lines))
            return ReprFailDoctest(reprlocation_lines)
        else:
            return super().repr_failure(excinfo) 
開發者ID:sofia-netsurv,項目名稱:python-netsurv,代碼行數:56,代碼來源:doctest.py

示例8: _init_runner_class

# 需要導入模塊: import doctest [as 別名]
# 或者: from doctest import DocTestFailure [as 別名]
def _init_runner_class() -> "Type[doctest.DocTestRunner]":
    import doctest

    class PytestDoctestRunner(doctest.DebugRunner):
        """
        Runner to collect failures.  Note that the out variable in this case is
        a list instead of a stdout-like object
        """

        def __init__(
            self,
            checker: Optional[doctest.OutputChecker] = None,
            verbose: Optional[bool] = None,
            optionflags: int = 0,
            continue_on_failure: bool = True,
        ) -> None:
            doctest.DebugRunner.__init__(
                self, checker=checker, verbose=verbose, optionflags=optionflags
            )
            self.continue_on_failure = continue_on_failure

        def report_failure(
            self, out, test: "doctest.DocTest", example: "doctest.Example", got: str,
        ) -> None:
            failure = doctest.DocTestFailure(test, example, got)
            if self.continue_on_failure:
                out.append(failure)
            else:
                raise failure

        def report_unexpected_exception(
            self,
            out,
            test: "doctest.DocTest",
            example: "doctest.Example",
            exc_info: "Tuple[Type[BaseException], BaseException, types.TracebackType]",
        ) -> None:
            if isinstance(exc_info[1], OutcomeException):
                raise exc_info[1]
            if isinstance(exc_info[1], bdb.BdbQuit):
                outcomes.exit("Quitting debugger")
            failure = doctest.UnexpectedException(test, example, exc_info)
            if self.continue_on_failure:
                out.append(failure)
            else:
                raise failure

    return PytestDoctestRunner 
開發者ID:pytest-dev,項目名稱:pytest,代碼行數:50,代碼來源:doctest.py


注:本文中的doctest.DocTestFailure方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。