当前位置: 首页>>代码示例>>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;未经允许,请勿转载。