Python future.standard_library.suspend_hooks() Examples
The following are 3
code examples of future.standard_library.suspend_hooks().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
future.standard_library
, or try the search function
.
Example #1
Source File: test_standard_library.py From kgsgo-dataset-preprocessor with Mozilla Public License 2.0 | 6 votes |
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
Example #2
Source File: test_standard_library.py From kgsgo-dataset-preprocessor with Mozilla Public License 2.0 | 6 votes |
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)
Example #3
Source File: test_standard_library.py From kgsgo-dataset-preprocessor with Mozilla Public License 2.0 | 5 votes |
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)