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


Python standard_library.suspend_hooks方法代码示例

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


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

示例1: test_suspend_hooks

# 需要导入模块: from future import standard_library [as 别名]
# 或者: from future.standard_library import suspend_hooks [as 别名]
def test_suspend_hooks(self):
        """
        Code like the try/except block here appears in Pyflakes v0.6.1. This
        method tests whether suspend_hooks() works as advertised.
        """
        example_PY2_check = False
        with standard_library.suspend_hooks():
            # An example of fragile import code that we don't want to break:
            try:
                import builtins
            except ImportError:
                example_PY2_check = True
        if utils.PY2:
            self.assertTrue(example_PY2_check)
        else:
            self.assertFalse(example_PY2_check)
        # The import should succeed again now:
        import builtins 
开发者ID:hughperkins,项目名称:kgsgo-dataset-preprocessor,代码行数:20,代码来源:test_standard_library.py

示例2: test_old_urllib_import

# 需要导入模块: from future import standard_library [as 别名]
# 或者: from future.standard_library import suspend_hooks [as 别名]
def test_old_urllib_import(self):
        """
        Tests whether an imported module can import the old urllib package.
        Importing future.standard_library in a script should be possible and
        not disrupt any uses of the old Py2 standard library names in modules
        imported by that script.
        """
        code1 = '''
                from future import standard_library
                with standard_library.suspend_hooks():
                    import module_importing_old_urllib
                '''
        self._write_test_script(code1, 'runme.py')
        code2 = '''
                import urllib
                assert 'urlopen' in dir(urllib)
                print('Import succeeded!')
                '''
        self._write_test_script(code2, 'module_importing_old_urllib.py')
        output = self._run_test_script('runme.py')
        print(output)
        self.assertTrue(True) 
开发者ID:hughperkins,项目名称:kgsgo-dataset-preprocessor,代码行数:24,代码来源:test_standard_library.py

示例3: test_urllib_imports_install_aliases

# 需要导入模块: from future import standard_library [as 别名]
# 或者: from future.standard_library import suspend_hooks [as 别名]
def test_urllib_imports_install_aliases(self):
        with standard_library.suspend_hooks():
            standard_library.install_aliases()
            import urllib
            import urllib.parse
            import urllib.request
            import urllib.robotparser
            import urllib.error
            import urllib.response
            self.assertTrue(True) 
开发者ID:hughperkins,项目名称:kgsgo-dataset-preprocessor,代码行数:12,代码来源:test_standard_library.py


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