python类print_function()的实例源码

test_tools.py 文件源码 项目:Repobot 作者: Desgard 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def test_exception_path2(self):
        """Test exception path in exception_validate, expecting windows line endings.
        """
        self.mktmp("from __future__ import print_function\n"
                   "import sys\n"
                   "print('A')\n"
                   "print('B')\n"
                   "print('C', file=sys.stderr)\n"
                   "print('D', file=sys.stderr)\n"
                   )
        out = "A\r\nB"
        tt.ipexec_validate(self.fname, expected_out=out, expected_err="C\r\nD")
doctest_nose_plugin.py 文件源码 项目:neighborhood_mood_aws 作者: jarrellmark 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def _patchTestCase(self, case):
        if case:
            case._dt_test.globs['print_function'] = print_function
            case._dt_checker = _checker
        return case
doctest_nose_plugin.py 文件源码 项目:hate-to-hugs 作者: sdoran35 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def _patchTestCase(self, case):
        if case:
            case._dt_test.globs['print_function'] = print_function
            case._dt_checker = _checker
        return case
summary_test.py 文件源码 项目:tensorboard 作者: tensorflow 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def test_all_exports_correspond_to_plugins(self):
    exports = [name for name in dir(tb.summary) if not name.startswith('_')]
    futures = frozenset(('absolute_import', 'division', 'print_function'))
    bad_exports = [
        name for name in exports
        if name not in futures and not any(
            name == plugin or name.startswith('%s_' % plugin)
            for plugin in STANDARD_PLUGINS)
    ]
    if bad_exports:
      self.fail(
          'The following exports do not correspond to known standard '
          'plugins: %r. Please mark these as private by prepending an '
          'underscore to their names, or, if they correspond to a new '
          'plugin that you are certain should be part of the public API '
          'forever, add that plugin to the STANDARD_PLUGINS set in this '
          'module.' % bad_exports)
fix_add_all__future__imports.py 文件源码 项目:UMOG 作者: hsab 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def transform(self, node, results):
        future_import(u"unicode_literals", node)
        future_import(u"print_function", node)
        future_import(u"division", node)
        future_import(u"absolute_import", node)
fix_add__future__imports_except_unicode_literals.py 文件源码 项目:UMOG 作者: hsab 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def transform(self, node, results):
        # Reverse order:
        future_import(u"print_function", node)
        future_import(u"division", node)
        future_import(u"absolute_import", node)
fix_print_with_import.py 文件源码 项目:UMOG 作者: hsab 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def transform(self, node, results):
        # Add the __future__ import first. (Otherwise any shebang or encoding
        # comment line attached as a prefix to the print statement will be
        # copied twice and appear twice.)
        future_import(u'print_function', node)
        n_stmt = super(FixPrintWithImport, self).transform(node, results)
        return n_stmt
base.py 文件源码 项目:UMOG 作者: hsab 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def strip_future_imports(self, code):
        """
        Strips any of these import lines:

            from __future__ import <anything>
            from future <anything>
            from future.<anything>
            from builtins <anything>

        or any line containing:
            install_hooks()
        or:
            install_aliases()

        Limitation: doesn't handle imports split across multiple lines like
        this:

            from __future__ import (absolute_import, division, print_function,
                                    unicode_literals)
        """
        output = []
        # We need .splitlines(keepends=True), which doesn't exist on Py2,
        # so we use this instead:
        for line in code.split('\n'):
            if not (line.startswith('from __future__ import ')
                    or line.startswith('from future ')
                    or line.startswith('from builtins ')
                    or 'install_hooks()' in line
                    or 'install_aliases()' in line
                    # but don't match "from future_builtins" :)
                    or line.startswith('from future.')):
                output.append(line)
        return '\n'.join(output)
doctest_nose_plugin.py 文件源码 项目:FancyWord 作者: EastonLee 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def _patchTestCase(self, case):
        if case:
            case._dt_test.globs['print_function'] = print_function
            case._dt_checker = _checker
        return case
fix_add_all__future__imports.py 文件源码 项目:blackmamba 作者: zrzka 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def transform(self, node, results):
        future_import(u"unicode_literals", node)
        future_import(u"print_function", node)
        future_import(u"division", node)
        future_import(u"absolute_import", node)
test_imports.py 文件源码 项目:blackmamba 作者: zrzka 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def test_importfrom_future(self):
        binding = FutureImportation('print_function', None, None)
        assert binding.source_statement == 'from __future__ import print_function'
        assert str(binding) == '__future__.print_function'
test_imports.py 文件源码 项目:blackmamba 作者: zrzka 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def test_futureImportUsed(self):
        """__future__ is special, but names are injected in the namespace."""
        self.flakes('''
        from __future__ import division
        from __future__ import print_function

        assert print_function is not division
        ''')
fix_add__future__imports_except_unicode_literals.py 文件源码 项目:blackmamba 作者: zrzka 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def transform(self, node, results):
        # Reverse order:
        future_import(u"print_function", node)
        future_import(u"division", node)
        future_import(u"absolute_import", node)
fix_print_with_import.py 文件源码 项目:blackmamba 作者: zrzka 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def transform(self, node, results):
        # Add the __future__ import first. (Otherwise any shebang or encoding
        # comment line attached as a prefix to the print statement will be
        # copied twice and appear twice.)
        future_import(u'print_function', node)
        n_stmt = super(FixPrintWithImport, self).transform(node, results)
        return n_stmt
base.py 文件源码 项目:blackmamba 作者: zrzka 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def strip_future_imports(self, code):
        """
        Strips any of these import lines:

            from __future__ import <anything>
            from future <anything>
            from future.<anything>
            from builtins <anything>

        or any line containing:
            install_hooks()
        or:
            install_aliases()

        Limitation: doesn't handle imports split across multiple lines like
        this:

            from __future__ import (absolute_import, division, print_function,
                                    unicode_literals)
        """
        output = []
        # We need .splitlines(keepends=True), which doesn't exist on Py2,
        # so we use this instead:
        for line in code.split('\n'):
            if not (line.startswith('from __future__ import ')
                    or line.startswith('from future ')
                    or line.startswith('from builtins ')
                    or 'install_hooks()' in line
                    or 'install_aliases()' in line
                    # but don't match "from future_builtins" :)
                    or line.startswith('from future.')):
                output.append(line)
        return '\n'.join(output)
fix_add_all__future__imports.py 文件源码 项目:beepboop 作者: nicolehe 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def transform(self, node, results):
        future_import(u"unicode_literals", node)
        future_import(u"print_function", node)
        future_import(u"division", node)
        future_import(u"absolute_import", node)
fix_add__future__imports_except_unicode_literals.py 文件源码 项目:beepboop 作者: nicolehe 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def transform(self, node, results):
        # Reverse order:
        future_import(u"print_function", node)
        future_import(u"division", node)
        future_import(u"absolute_import", node)
fix_print_with_import.py 文件源码 项目:beepboop 作者: nicolehe 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def transform(self, node, results):
        # Add the __future__ import first. (Otherwise any shebang or encoding
        # comment line attached as a prefix to the print statement will be
        # copied twice and appear twice.)
        future_import(u'print_function', node)
        n_stmt = super(FixPrintWithImport, self).transform(node, results)
        return n_stmt
base.py 文件源码 项目:beepboop 作者: nicolehe 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def strip_future_imports(self, code):
        """
        Strips any of these import lines:

            from __future__ import <anything>
            from future <anything>
            from future.<anything>
            from builtins <anything>

        or any line containing:
            install_hooks()
        or:
            install_aliases()

        Limitation: doesn't handle imports split across multiple lines like
        this:

            from __future__ import (absolute_import, division, print_function,
                                    unicode_literals)
        """
        output = []
        # We need .splitlines(keepends=True), which doesn't exist on Py2,
        # so we use this instead:
        for line in code.split('\n'):
            if not (line.startswith('from __future__ import ')
                    or line.startswith('from future ')
                    or line.startswith('from builtins ')
                    or 'install_hooks()' in line
                    or 'install_aliases()' in line
                    # but don't match "from future_builtins" :)
                    or line.startswith('from future.')):
                output.append(line)
        return '\n'.join(output)
doctest_nose_plugin.py 文件源码 项目:kind2anki 作者: prz3m 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def _patchTestCase(self, case):
        if case:
            case._dt_test.globs['print_function'] = print_function
            case._dt_checker = _checker
        return case


问题


面经


文章

微信
公众号

扫码关注公众号