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


Python doctest.OutputChecker方法代碼示例

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


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

示例1: _get_runner

# 需要導入模塊: import doctest [as 別名]
# 或者: from doctest import OutputChecker [as 別名]
def _get_runner(
    checker: Optional["doctest.OutputChecker"] = None,
    verbose: Optional[bool] = None,
    optionflags: int = 0,
    continue_on_failure: bool = True,
) -> "doctest.DocTestRunner":
    # We need this in order to do a lazy import on doctest
    global RUNNER_CLASS
    if RUNNER_CLASS is None:
        RUNNER_CLASS = _init_runner_class()
    # Type ignored because the continue_on_failure argument is only defined on
    # PytestDoctestRunner, which is lazily defined so can't be used as a type.
    return RUNNER_CLASS(  # type: ignore
        checker=checker,
        verbose=verbose,
        optionflags=optionflags,
        continue_on_failure=continue_on_failure,
    ) 
開發者ID:pytest-dev,項目名稱:pytest,代碼行數:20,代碼來源:doctest.py

示例2: _get_checker

# 需要導入模塊: import doctest [as 別名]
# 或者: from doctest import OutputChecker [as 別名]
def _get_checker() -> "doctest.OutputChecker":
    """
    Returns a doctest.OutputChecker subclass that supports some
    additional options:

    * ALLOW_UNICODE and ALLOW_BYTES options to ignore u'' and b''
      prefixes (respectively) in string literals. Useful when the same
      doctest should run in Python 2 and Python 3.

    * NUMBER to ignore floating-point differences smaller than the
      precision of the literal number in the doctest.

    An inner class is used to avoid importing "doctest" at the module
    level.
    """
    global CHECKER_CLASS
    if CHECKER_CLASS is None:
        CHECKER_CLASS = _init_checker_class()
    return CHECKER_CLASS() 
開發者ID:pytest-dev,項目名稱:pytest,代碼行數:21,代碼來源:doctest.py

示例3: check_output

# 需要導入模塊: import doctest [as 別名]
# 或者: from doctest import OutputChecker [as 別名]
def check_output(self, want, got, optionflags):
        alt_self = getattr(self, '_temp_override_self', None)
        if alt_self is not None:
            super_method = self._temp_call_super_check_output
            self = alt_self
        else:
            super_method = OutputChecker.check_output
        parser = self.get_parser(want, got, optionflags)
        if not parser:
            return super_method(
                self, want, got, optionflags)
        try:
            want_doc = parser(want)
        except etree.XMLSyntaxError:
            return False
        try:
            got_doc = parser(got)
        except etree.XMLSyntaxError:
            return False
        return self.compare_docs(want_doc, got_doc) 
開發者ID:JFox,項目名稱:aws-lambda-lxml,代碼行數:22,代碼來源:doctestcompare.py

示例4: check_output

# 需要導入模塊: import doctest [as 別名]
# 或者: from doctest import OutputChecker [as 別名]
def check_output(self, want, got, optionflags):
        res = doctest.OutputChecker.check_output(self, want, got, optionflags)
        if res:
            return True
        if not (optionflags & ALLOW_UNICODE):
            return False

        # ALLOW_UNICODE is active and want != got
        cleaned_want = self._remove_u_prefixes(want)
        cleaned_got = self._remove_u_prefixes(got)
        res = doctest.OutputChecker.check_output(self, cleaned_want, cleaned_got, optionflags)
        return res 
開發者ID:rafasashi,項目名稱:razzy-spinner,代碼行數:14,代碼來源:doctest_nose_plugin.py

示例5: check_output

# 需要導入模塊: import doctest [as 別名]
# 或者: from doctest import OutputChecker [as 別名]
def check_output(self, want, got, optionflags):
        ret = doctest.OutputChecker.check_output(self, want, got,
                                                 optionflags)
        if not ret:
            if "#random" in want:
                return True

            # it would be useful to normalize endianness so that
            # bigendian machines don't fail all the tests (and there are
            # actually some bigendian examples in the doctests). Let's try
            # making them all little endian
            got = got.replace("'>", "'<")
            want = want.replace("'>", "'<")

            # try to normalize out 32 and 64 bit default int sizes
            for sz in [4, 8]:
                got = got.replace("'<i%d'" % sz, "int")
                want = want.replace("'<i%d'" % sz, "int")

            ret = doctest.OutputChecker.check_output(self, want,
                    got, optionflags)

        return ret


# Subclass nose.plugins.doctests.DocTestCase to work around a bug in
# its constructor that blocks non-default arguments from being passed
# down into doctest.DocTestCase 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:30,代碼來源:noseclasses.py

示例6: check_output

# 需要導入模塊: import doctest [as 別名]
# 或者: from doctest import OutputChecker [as 別名]
def check_output(self, want, got, optionflags):
        ret = doctest.OutputChecker.check_output(self, want, got,
                                                 optionflags)
        if not ret:
            if "#random" in want:
                return True

            # it would be useful to normalize endianness so that
            # bigendian machines don't fail all the tests (and there are
            # actually some bigendian examples in the doctests). Let's try
            # making them all little endian
            got = got.replace("'>", "'<")
            want= want.replace("'>", "'<")

            # try to normalize out 32 and 64 bit default int sizes
            for sz in [4, 8]:
                got = got.replace("'<i%d'"%sz, "int")
                want= want.replace("'<i%d'"%sz, "int")

            ret = doctest.OutputChecker.check_output(self, want,
                    got, optionflags)

        return ret


# Subclass nose.plugins.doctests.DocTestCase to work around a bug in
# its constructor that blocks non-default arguments from being passed
# down into doctest.DocTestCase 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:30,代碼來源:noseclasses.py

示例7: check_output

# 需要導入模塊: import doctest [as 別名]
# 或者: from doctest import OutputChecker [as 別名]
def check_output(self, want, got, optionflags):
        """Check output, accepting special markers embedded in the output.

        If the output didn't pass the default validation but the special string
        '#random' is included, we accept it."""

        # Let the original tester verify first, in case people have valid tests
        # that happen to have a comment saying '#random' embedded in.
        ret = doctest.OutputChecker.check_output(self, want, got,
                                                 optionflags)
        if not ret and self.random_re.search(want):
            #print >> sys.stderr, 'RANDOM OK:',want  # dbg
            return True

        return ret 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:17,代碼來源:ipdoctest.py

示例8: check_output

# 需要導入模塊: import doctest [as 別名]
# 或者: from doctest import OutputChecker [as 別名]
def check_output(self, want, got, optionflags):
        if not PY2:
            #Differences between unicode strings representations : u"foo" -> "foo"
            want = re.sub("u'(.*?)'", "'\\1'", want) 
            want = re.sub('u"(.*?)"', '"\\1"', want)

            #NameError message has changed
            want = want.replace('NameError: global name', 'NameError: name')
        else:
            want = re.sub("^b'(.*?)'", "'\\1'", want) 
            want = re.sub('^b"(.*?)"', '"\\1"', want)
        return doctest.OutputChecker.check_output(self, want, got, optionflags) 
開發者ID:Naayouu,項目名稱:Hatkey,代碼行數:14,代碼來源:test.py

示例9: output_difference

# 需要導入模塊: import doctest [as 別名]
# 或者: from doctest import OutputChecker [as 別名]
def output_difference(self, example, got, optionflags):
        want = example.want
        parser = self.get_parser(want, got, optionflags)
        errors = []
        if parser is not None:
            try:
                want_doc = parser(want)
            except etree.XMLSyntaxError:
                e = sys.exc_info()[1]
                errors.append('In example: %s' % e)
            try:
                got_doc = parser(got)
            except etree.XMLSyntaxError:
                e = sys.exc_info()[1]
                errors.append('In actual output: %s' % e)
        if parser is None or errors:
            value = OutputChecker.output_difference(
                self, example, got, optionflags)
            if errors:
                errors.append(value)
                return '\n'.join(errors)
            else:
                return value
        html = parser is html_fromstring
        diff_parts = []
        diff_parts.append('Expected:')
        diff_parts.append(self.format_doc(want_doc, html, 2))
        diff_parts.append('Got:')
        diff_parts.append(self.format_doc(got_doc, html, 2))
        diff_parts.append('Diff:')
        diff_parts.append(self.collect_diff(want_doc, got_doc, html, 2))
        return '\n'.join(diff_parts) 
開發者ID:JFox,項目名稱:aws-lambda-lxml,代碼行數:34,代碼來源:doctestcompare.py

示例10: install

# 需要導入模塊: import doctest [as 別名]
# 或者: from doctest import OutputChecker [as 別名]
def install(html=False):
    """
    Install doctestcompare for all future doctests.

    If html is true, then by default the HTML parser will be used;
    otherwise the XML parser is used.
    """
    if html:
        doctest.OutputChecker = LHTMLOutputChecker
    else:
        doctest.OutputChecker = LXMLOutputChecker 
開發者ID:JFox,項目名稱:aws-lambda-lxml,代碼行數:13,代碼來源:doctestcompare.py

示例11: output_difference

# 需要導入模塊: import doctest [as 別名]
# 或者: from doctest import OutputChecker [as 別名]
def output_difference(self, example, got, optionflags):
        want = example.want
        parser = self.get_parser(want, got, optionflags)
        errors = []
        if parser is not None:
            try:
                want_doc = parser(want)
            except etree.XMLSyntaxError:
                e = sys.exc_info()[1]
                errors.append('In example: %s' % e)
            try:
                got_doc = parser(got)
            except etree.XMLSyntaxError:
                e = sys.exc_info()[1]
                errors.append('In actual output: %s' % e)
        if parser is None or errors:
            value = OutputChecker.output_difference(
                self, example, got, optionflags)
            if errors:
                errors.append(value)
                return '\n'.join(errors)
            else:
                return value
        html = parser is html_fromstring
        diff_parts = ['Expected:',
                      self.format_doc(want_doc, html, 2),
                      'Got:',
                      self.format_doc(got_doc, html, 2),
                      'Diff:',
                      self.collect_diff(want_doc, got_doc, html, 2)]
        return '\n'.join(diff_parts) 
開發者ID:wistbean,項目名稱:learn_python3_spider,代碼行數:33,代碼來源:doctestcompare.py


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