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


Python OutputChecker.check_output方法代码示例

本文整理汇总了Python中doctest.OutputChecker.check_output方法的典型用法代码示例。如果您正苦于以下问题:Python OutputChecker.check_output方法的具体用法?Python OutputChecker.check_output怎么用?Python OutputChecker.check_output使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在doctest.OutputChecker的用法示例。


在下文中一共展示了OutputChecker.check_output方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _check_output

# 需要导入模块: from doctest import OutputChecker [as 别名]
# 或者: from doctest.OutputChecker import check_output [as 别名]
def _check_output(result, expected):
    checker = OutputChecker()
    actual = str(result)

    # FIXME!  The following is a TOTAL hack.  For some reason the
    # __str__ result for pkg_resources.Requirement gets downcased on
    # Windows.  Since INITools is the only package we're installing
    # in this file with funky case requirements, I'm forcibly
    # upcasing it.  You can also normalize everything to lowercase,
    # but then you have to remember to upcase <BLANKLINE>.  The right
    # thing to do in the end is probably to find out how to report
    # the proper fully-cased package name in our error message.
    if sys.platform == 'win32':
        actual = actual.replace('initools', 'INITools')

    # This allows our existing tests to work when run in a context
    # with distribute installed.
    actual = distribute_re.sub('', actual)

    def banner(msg):
        return '\n========== %s ==========\n' % msg

    assert checker.check_output(expected, actual, ELLIPSIS), (
        banner('EXPECTED') + expected + banner('ACTUAL') + actual +
        banner(6 * '=')
    )
开发者ID:alquerci,项目名称:pip,代码行数:28,代码来源:test_freeze.py

示例2: test_sample_files

# 需要导入模块: from doctest import OutputChecker [as 别名]
# 或者: from doctest.OutputChecker import check_output [as 别名]
    def test_sample_files(self):
        import os
        import traceback
        path = os.path.join(os.path.dirname(__file__), "inputs")
        for filename in os.listdir(path):
            if not filename.endswith('.xml'):
                continue
            f = open(os.path.join(path, filename), 'rb')
            source = f.read()
            f.close()

            from ..utils import read_encoded
            try:
                want = read_encoded(source)
            except UnicodeDecodeError:
                exc = sys.exc_info()[1]
                self.fail("%s - %s" % (exc, filename))

            from ..tokenize import iter_xml
            try:
                tokens = iter_xml(want)
                got = "".join(tokens)
            except:
                self.fail(traceback.format_exc())

            from doctest import OutputChecker
            checker = OutputChecker()

            if checker.check_output(want, got, 0) is False:
                from doctest import Example
                example = Example(f.name, want)
                diff = checker.output_difference(
                    example, got, 0)
                self.fail("(%s) - \n%s" % (f.name, diff))
开发者ID:Kleptine,项目名称:Craft,代码行数:36,代码来源:test_tokenizer.py

示例3: check_output

# 需要导入模块: from doctest import OutputChecker [as 别名]
# 或者: from doctest.OutputChecker import check_output [as 别名]
 def check_output(self, want, got, optionflags):
     want = UNICODE_LITERALS.sub('\\1', want)
     want = want.replace('FieldNotLoaded: ',
                         'workfront.meta.FieldNotLoaded: ')
     return OutputChecker.check_output(
         self, want, got, optionflags
         )
开发者ID:cjw296,项目名称:python-workfront,代码行数:9,代码来源:test_docs.py

示例4: check_output

# 需要导入模块: from doctest import OutputChecker [as 别名]
# 或者: from doctest.OutputChecker import check_output [as 别名]
    def check_output(self, want, got, optionflags):
        if got == want:
            return True

        for pattern, repl in self.patterns:
            want = re.sub(pattern, repl, want)
            got = re.sub(pattern, repl, got)

        return OutputChecker.check_output(self, want, got, optionflags)
开发者ID:dockeroo,项目名称:dockeroo,代码行数:11,代码来源:__init__.py

示例5: _check_output

# 需要导入模块: from doctest import OutputChecker [as 别名]
# 或者: from doctest.OutputChecker import check_output [as 别名]
def _check_output(result, expected):
    checker = OutputChecker()
    actual = str(result)

    ## FIXME!  The following is a TOTAL hack.  For some reason the
    ## __str__ result for pkg_resources.Requirement gets downcased on
    ## Windows.  Since INITools is the only package we're installing
    ## in this file with funky case requirements, I'm forcibly
    ## upcasing it.  You can also normalize everything to lowercase,
    ## but then you have to remember to upcase <BLANKLINE>.  The right
    ## thing to do in the end is probably to find out how to report
    ## the proper fully-cased package name in our error message.
    if sys.platform == "win32":
        actual = actual.replace("initools", "INITools")

    def banner(msg):
        return "\n========== %s ==========\n" % msg

    assert checker.check_output(expected, actual, ELLIPSIS), (
        banner("EXPECTED") + expected + banner("ACTUAL") + actual + banner(6 * "=")
    )
开发者ID:francescog,项目名称:pip,代码行数:23,代码来源:test_freeze.py

示例6: execute

# 需要导入模块: from doctest import OutputChecker [as 别名]
# 或者: from doctest.OutputChecker import check_output [as 别名]
    def execute(self, ext, factory, **kwargs):
        def translate(msgid, domain=None, mapping=None, context=None, target_language=None, default=None):
            if default is None:
                default = str(msgid)

            if isinstance(msgid, Message):
                default = "Message"

            if mapping:
                default = re.sub(r"\${([a-z_]+)}", r"%(\1)s", default) % mapping

            if target_language is None:
                return default

            if domain is None:
                with_domain = ""
            else:
                with_domain = " with domain '%s'" % domain

            stripped = default.rstrip("\n ")
            return "%s ('%s' translation into '%s'%s)%s" % (
                stripped,
                msgid,
                target_language,
                with_domain,
                default[len(stripped) :],
            )

        for input_path, output_path, language in self.find_files(ext):
            # Make friendly title so we can locate the generated
            # source when debugging
            self.shortDescription = lambda: input_path

            # Very implicitly enable implicit translation based on
            # a string included in the input path:
            implicit_i18n = "implicit-i18n" in input_path
            implicit_i18n_attrs = ("alt", "title") if implicit_i18n else ()

            template = factory(
                input_path,
                keep_source=True,
                strict=False,
                implicit_i18n_translate=implicit_i18n,
                implicit_i18n_attributes=implicit_i18n_attrs,
            )

            params = kwargs.copy()
            params.update({"translate": translate, "target_language": language})

            template.cook_check()

            try:
                got = template.render(**params)
            except:
                import traceback

                e = traceback.format_exc()
                self.fail(
                    "%s\n\n    Example source:\n\n%s"
                    % (
                        e,
                        "\n".join(
                            [
                                "%#03.d%s" % (lineno + 1, line and " " + line or "")
                                for (lineno, line) in enumerate(template.source.split("\n"))
                            ]
                        ),
                    )
                )

            if isinstance(got, byte_string):
                got = got.decode("utf-8")

            from doctest import OutputChecker

            checker = OutputChecker()

            if not os.path.exists(output_path):
                output = template.body
            else:
                with open(output_path, "rb") as f:
                    output = f.read()

            from chameleon.utils import read_xml_encoding
            from chameleon.utils import detect_encoding

            if template.content_type == "text/xml":
                encoding = read_xml_encoding(output) or template.default_encoding
            else:
                content_type, encoding = detect_encoding(output, template.default_encoding)

            want = output.decode(encoding)

            if checker.check_output(want, got, 0) is False:
                from doctest import Example

                example = Example(input_path, want)
                diff = checker.output_difference(example, got, 0)
                self.fail("(%s) - \n%s\n\nCode:\n%s" % (input_path, diff.rstrip("\n"), template.source.encode("utf-8")))
开发者ID:pitchum,项目名称:chameleon,代码行数:101,代码来源:test_templates.py

示例7: execute

# 需要导入模块: from doctest import OutputChecker [as 别名]
# 或者: from doctest.OutputChecker import check_output [as 别名]
    def execute(self, ext, factory, **kwargs):
        def translate(msgid, domain=None, mapping=None, context=None,
                      target_language=None, default=None):
            if default is None:
                default = str(msgid)

            if isinstance(msgid, Message):
                default = "Message"

            if mapping:
                default = re.sub(r'\${([a-z_]+)}', r'%(\1)s', default) % \
                          mapping

            if target_language is None:
                return default

            if domain is None:
                with_domain = ""
            else:
                with_domain = " with domain '%s'" % domain

            if context is None:
                with_context = ""
            else:
                with_context = ", context '%s'" % context

            stripped = default.rstrip('\n ')
            return "%s ('%s' translation into '%s'%s%s)%s" % (
                stripped, msgid, target_language, with_domain, with_context,
                default[len(stripped):]
                )

        for input_path, output_path, language in self.find_files(ext):
            # Make friendly title so we can locate the generated
            # source when debugging
            self.shortDescription = lambda: input_path

            # When input path contains the string 'implicit-i18n', we
            # enable "implicit translation".
            implicit_i18n = 'implicit-i18n' in input_path
            implicit_i18n_attrs = ("alt", "title") if implicit_i18n else ()

            enable_data_attributes = 'data-attributes' in input_path

            template = factory(
                input_path,
                keep_source=True,
                strict=False,
                implicit_i18n_translate=implicit_i18n,
                implicit_i18n_attributes=implicit_i18n_attrs,
                enable_data_attributes=enable_data_attributes,
                )

            params = kwargs.copy()
            params.update({
                'translate': translate,
                'target_language': language,
                })

            template.cook_check()

            try:
                got = template.render(**params)
            except:
                import traceback
                e = traceback.format_exc()
                self.fail("%s\n\n    Example source:\n\n%s" % (e, "\n".join(
                    ["%#03.d%s" % (lineno + 1, line and " " + line or "")
                     for (lineno, line) in
                     enumerate(template.source.split(
                         '\n'))])))

            if isinstance(got, byte_string):
                got = got.decode('utf-8')

            from doctest import OutputChecker
            checker = OutputChecker()

            if not os.path.exists(output_path):
                output = template.body
            else:
                with open(output_path, 'rb') as f:
                    output = f.read()

            from chameleon.utils import read_xml_encoding
            from chameleon.utils import detect_encoding

            if template.content_type == 'text/xml':
                encoding = read_xml_encoding(output) or \
                           template.default_encoding
            else:
                content_type, encoding = detect_encoding(
                    output, template.default_encoding)

            # Newline normalization across platforms
            want = '\n'.join(output.decode(encoding).splitlines())
            got = '\n'.join(got.splitlines())

            if checker.check_output(want, got, 0) is False:
                from doctest import Example
#.........这里部分代码省略.........
开发者ID:malthe,项目名称:chameleon,代码行数:103,代码来源:test_templates.py

示例8: execute

# 需要导入模块: from doctest import OutputChecker [as 别名]
# 或者: from doctest.OutputChecker import check_output [as 别名]
    def execute(self, ext, factory, **kwargs):
        from chameleon.utils import DebuggingOutputStream

        def translate(msgid, domain=None, mapping=None, context=None,
                      target_language=None, default=None):
            if default is None:
                default = str(msgid)

            if isinstance(msgid, Message):
                default = "Message"

            if mapping:
                default = re.sub(r'\${([a-z_]+)}', r'%(\1)s', default) % \
                          mapping

            if target_language is None:
                return default

            if domain is None:
                with_domain = ""
            else:
                with_domain = " with domain '%s'" % domain

            stripped = default.rstrip('\n ')
            return "%s ('%s' translation into '%s'%s)%s" % (
                stripped, msgid, target_language, with_domain,
                default[len(stripped):]
                )

        for name, source, want, language in self.find_files(ext):
            if language is not None:
                name += '-' + language

            # Make friendly title so we can locate the generated
            # source when debugging
            title = os.path.basename(name).\
                    replace('-', '_').\
                    replace('.', '_')

            self.shortDescription = lambda: name
            template = factory(
                source,
                keep_source=True,
                output_stream_factory=DebuggingOutputStream,

                # The ``_digest_`` method is internal to the template
                # class; we provide a custom function that lets us
                # choose the filename for the generated Python module
                _digest = lambda body, title=title: title,
                )

            params = kwargs.copy()
            params.update({
                'translate': translate,
                'target_language': language,
                })

            try:
                got = template.render(**params)
            except:
                import traceback
                e = traceback.format_exc()
                self.fail("%s\n\n    Example source:\n\n%s" % (e, "\n".join(
                    ["%#03.d%s" % (lineno + 1, line and " " + line or "")
                     for (lineno, line) in
                     enumerate(template.source.split(
                         '\n'))])))

            from doctest import OutputChecker
            checker = OutputChecker()
            if checker.check_output(want, got, 0) is False:
                from doctest import Example
                example = Example(name, want)
                diff = checker.output_difference(
                    example, got, 0)
                self.fail("(%s) - \n%s\n\nCode:\n%s" % (
                    name, diff.rstrip('\n'), template.source.encode('utf-8')))
开发者ID:nak,项目名称:Penumbra,代码行数:79,代码来源:test_templates.py

示例9: test_sample_files

# 需要导入模块: from doctest import OutputChecker [as 别名]
# 或者: from doctest.OutputChecker import check_output [as 别名]
    def test_sample_files(self):
        import os
        import traceback
        path = os.path.join(os.path.dirname(__file__), "inputs")
        for filename in os.listdir(path):
            if not filename.endswith('.html'):
                continue

            with open(os.path.join(path, filename), 'rb') as f:
                source = f.read()

            from ..utils import read_encoded
            try:
                want = read_encoded(source)
            except UnicodeDecodeError:
                exc = sys.exc_info()[1]
                self.fail("%s - %s" % (exc, filename))

            from ..tokenize import iter_xml
            from ..parser import ElementParser
            try:
                tokens = iter_xml(want)
                parser = ElementParser(tokens, {
                    'xmlns': XMLNS_NS,
                    'xml': XML_NS,
                    'py': PY_NS,
                    })
                elements = tuple(parser)
            except:
                self.fail(traceback.format_exc())

            output = []

            def render(kind, args):
                if kind == 'element':
                    # start tag
                    tag, end, children = args
                    output.append("%(prefix)s%(name)s" % tag)

                    for attr in tag['attrs']:
                        output.append(
                            "%(space)s%(name)s%(eq)s%(quote)s%(value)s%(quote)s" % \
                            attr
                            )

                    output.append("%(suffix)s" % tag)

                    # children
                    for item in children:
                        render(*item)

                    # end tag
                    output.append(
                        "%(prefix)s%(name)s%(space)s%(suffix)s" % end
                        )
                elif kind == 'text':
                    text = args[0]
                    output.append(text)
                elif kind == 'start_tag':
                    node = args[0]
                    output.append(
                        "%(prefix)s%(name)s%(space)s%(suffix)s" % node
                        )
                else:
                    raise RuntimeError("Not implemented: %s." % kind)

            for kind, args in elements:
                render(kind, args)

            got = "".join(output)

            from doctest import OutputChecker
            checker = OutputChecker()

            if checker.check_output(want, got, 0) is False:
                from doctest import Example
                example = Example(f.name, want)
                diff = checker.output_difference(
                    example, got, 0)
                self.fail("(%s) - \n%s" % (f.name, diff))
开发者ID:bshanks,项目名称:chameleon,代码行数:82,代码来源:test_parser.py

示例10: check_output

# 需要导入模块: from doctest import OutputChecker [as 别名]
# 或者: from doctest.OutputChecker import check_output [as 别名]
 def check_output(self, want, got, optionflags):
     if optionflags & IGNORE_RESULT:
         return True
     return OutputChecker.check_output(self, want, got, optionflags)
开发者ID:happyspace,项目名称:aa-fullstack-catalog,代码行数:6,代码来源:outputcheckerig.py

示例11: run_tests

# 需要导入模块: from doctest import OutputChecker [as 别名]
# 或者: from doctest.OutputChecker import check_output [as 别名]
    def run_tests(self, ext, factory, **kwargs):
        from chameleon.utils import DebuggingOutputStream

        def translate(msgid, domain=None, mapping=None, context=None,
                      target_language=None, default=None):
            if default is None:
                default = str(msgid)

            if isinstance(msgid, Message):
                default = "Message"

            if mapping:
                default = re.sub(r'\${([a-z_]+)}', r'%(\1)s', default) % \
                          mapping

            if target_language is None:
                return default

            if domain is None:
                with_domain = ""
            else:
                with_domain = " with domain '%s'" % domain

            stripped = default.rstrip('\n ')
            return "%s ('%s' translation into '%s'%s)%s" % (
                stripped, msgid, target_language, with_domain,
                default[len(stripped):]
                )

        for name, source, want, language in self.find_files(ext):
            if language is not None:
                name += '-' + language

            self.shortDescription = lambda: name
            template = factory(
                source,
                keep_source=True,
                output_stream_factory=DebuggingOutputStream,
                )

            params = kwargs.copy()
            params.update({
                'translate': translate,
                'target_language': language,
                })

            try:
                got = template.render(**params)
            except:
                import traceback
                e = traceback.format_exc()
                self.fail("%s\n\n    Example source:\n\n%s" % (e, "\n".join(
                    ["%#03.d%s" % (lineno + 1, line and " " + line or "")
                     for (lineno, line) in
                     enumerate(template.source.split(
                         '\n'))])))

            from doctest import OutputChecker
            checker = OutputChecker()
            if checker.check_output(want, got, 0) is False:
                from doctest import Example
                example = Example(name, want)
                diff = checker.output_difference(
                    example, got, 0)
                self.fail("(%s) - \n%s\n\nCode:\n%s" % (
                    name, diff.rstrip('\n'), template.source.encode('utf-8')))
开发者ID:bshanks,项目名称:chameleon,代码行数:68,代码来源:test_templates.py

示例12: check_output

# 需要导入模块: from doctest import OutputChecker [as 别名]
# 或者: from doctest.OutputChecker import check_output [as 别名]
 def check_output(self, want, got, optionflags):
     if got:
         got = re.sub("u'(.*?)'", "'\\1'", got)
         got = re.sub('u"(.*?)"', '"\\1"', got)
     return OutputChecker.check_output(self, want, got, optionflags)
开发者ID:Danisan,项目名称:odoorpc,代码行数:7,代码来源:doctest_custom.py


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