Python test.test_support.CleanImport() Examples
The following are 30
code examples of test.test_support.CleanImport().
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
test.test_support
, or try the search function
.
Example #1
Source File: test_import.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_imp_module(self): # Verify that the imp module can correctly load and find .py files # XXX (ncoghlan): It would be nice to use test_support.CleanImport # here, but that breaks because the os module registers some # handlers in copy_reg on import. Since CleanImport doesn't # revert that registration, the module is left in a broken # state after reversion. Reinitialising the module contents # and just reverting os.environ to its previous state is an OK # workaround orig_path = os.path orig_getenv = os.getenv with EnvironmentVarGuard(): x = imp.find_module("os") new_os = imp.load_module("os", *x) self.assertIs(os, new_os) self.assertIs(orig_path, new_os.path) self.assertIsNot(orig_getenv, new_os.getenv)
Example #2
Source File: test_import.py From CTFCrackTools with GNU General Public License v3.0 | 6 votes |
def test_imp_module(self): # Verify that the imp module can correctly load and find .py files # XXX (ncoghlan): It would be nice to use test_support.CleanImport # here, but that breaks because the os module registers some # handlers in copy_reg on import. Since CleanImport doesn't # revert that registration, the module is left in a broken # state after reversion. Reinitialising the module contents # and just reverting os.environ to its previous state is an OK # workaround orig_path = os.path orig_getenv = os.getenv with EnvironmentVarGuard(): x = imp.find_module("os") new_os = imp.load_module("os", *x) self.assertIs(os, new_os) self.assertIs(orig_path, new_os.path) self.assertIsNot(orig_getenv, new_os.getenv)
Example #3
Source File: test_py3kwarn.py From CTFCrackTools with GNU General Public License v3.0 | 6 votes |
def check_removal(self, module_name, optional=False): """Make sure the specified module, when imported, raises a DeprecationWarning and specifies itself in the message.""" with CleanImport(module_name), warnings.catch_warnings(): warnings.filterwarnings("error", ".+ (module|package) .+ removed", DeprecationWarning, __name__) warnings.filterwarnings("error", ".+ removed .+ (module|package)", DeprecationWarning, __name__) try: __import__(module_name, level=0) except DeprecationWarning as exc: self.assertIn(module_name, exc.args[0], "%s warning didn't contain module name" % module_name) except ImportError: if not optional: self.fail("Non-optional module {0} raised an " "ImportError.".format(module_name)) else: # For extension modules, check the __warningregistry__. # They won't rerun their init code even with CleanImport. if not check_deprecated_module(module_name): self.fail("DeprecationWarning not raised for {0}" .format(module_name))
Example #4
Source File: test_import.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 6 votes |
def test_imp_module(self): # Verify that the imp module can correctly load and find .py files # XXX (ncoghlan): It would be nice to use test_support.CleanImport # here, but that breaks because the os module registers some # handlers in copy_reg on import. Since CleanImport doesn't # revert that registration, the module is left in a broken # state after reversion. Reinitialising the module contents # and just reverting os.environ to its previous state is an OK # workaround orig_path = os.path orig_getenv = os.getenv with EnvironmentVarGuard(): x = imp.find_module("os") new_os = imp.load_module("os", *x) self.assertIs(os, new_os) self.assertIs(orig_path, new_os.path) self.assertIsNot(orig_getenv, new_os.getenv)
Example #5
Source File: test_py3kwarn.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 6 votes |
def check_removal(self, module_name, optional=False): """Make sure the specified module, when imported, raises a DeprecationWarning and specifies itself in the message.""" with CleanImport(module_name), warnings.catch_warnings(): warnings.filterwarnings("error", ".+ (module|package) .+ removed", DeprecationWarning, __name__) warnings.filterwarnings("error", ".+ removed .+ (module|package)", DeprecationWarning, __name__) try: __import__(module_name, level=0) except DeprecationWarning as exc: self.assertIn(module_name, exc.args[0], "%s warning didn't contain module name" % module_name) except ImportError: if not optional: self.fail("Non-optional module {0} raised an " "ImportError.".format(module_name)) else: # For extension modules, check the __warningregistry__. # They won't rerun their init code even with CleanImport. if not check_deprecated_module(module_name): self.fail("DeprecationWarning not raised for {0}" .format(module_name))
Example #6
Source File: test_import.py From gcblue with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_imp_module(self): # Verify that the imp module can correctly load and find .py files # XXX (ncoghlan): It would be nice to use test_support.CleanImport # here, but that breaks because the os module registers some # handlers in copy_reg on import. Since CleanImport doesn't # revert that registration, the module is left in a broken # state after reversion. Reinitialising the module contents # and just reverting os.environ to its previous state is an OK # workaround orig_path = os.path orig_getenv = os.getenv with EnvironmentVarGuard(): x = imp.find_module("os") new_os = imp.load_module("os", *x) self.assertIs(os, new_os) self.assertIs(orig_path, new_os.path) self.assertIsNot(orig_getenv, new_os.getenv)
Example #7
Source File: test_py3kwarn.py From gcblue with BSD 3-Clause "New" or "Revised" License | 6 votes |
def check_removal(self, module_name, optional=False): """Make sure the specified module, when imported, raises a DeprecationWarning and specifies itself in the message.""" with CleanImport(module_name), warnings.catch_warnings(): warnings.filterwarnings("error", ".+ (module|package) .+ removed", DeprecationWarning, __name__) warnings.filterwarnings("error", ".+ removed .+ (module|package)", DeprecationWarning, __name__) try: __import__(module_name, level=0) except DeprecationWarning as exc: self.assertIn(module_name, exc.args[0], "%s warning didn't contain module name" % module_name) except ImportError: if not optional: self.fail("Non-optional module {0} raised an " "ImportError.".format(module_name)) else: # For extension modules, check the __warningregistry__. # They won't rerun their init code even with CleanImport. if not check_deprecated_module(module_name): self.fail("DeprecationWarning not raised for {0}" .format(module_name))
Example #8
Source File: test_import.py From oss-ftp with MIT License | 6 votes |
def test_imp_module(self): # Verify that the imp module can correctly load and find .py files # XXX (ncoghlan): It would be nice to use test_support.CleanImport # here, but that breaks because the os module registers some # handlers in copy_reg on import. Since CleanImport doesn't # revert that registration, the module is left in a broken # state after reversion. Reinitialising the module contents # and just reverting os.environ to its previous state is an OK # workaround orig_path = os.path orig_getenv = os.getenv with EnvironmentVarGuard(): x = imp.find_module("os") new_os = imp.load_module("os", *x) self.assertIs(os, new_os) self.assertIs(orig_path, new_os.path) self.assertIsNot(orig_getenv, new_os.getenv)
Example #9
Source File: test_py3kwarn.py From oss-ftp with MIT License | 6 votes |
def check_removal(self, module_name, optional=False): """Make sure the specified module, when imported, raises a DeprecationWarning and specifies itself in the message.""" with CleanImport(module_name), warnings.catch_warnings(): warnings.filterwarnings("error", ".+ (module|package) .+ removed", DeprecationWarning, __name__) warnings.filterwarnings("error", ".+ removed .+ (module|package)", DeprecationWarning, __name__) try: __import__(module_name, level=0) except DeprecationWarning as exc: self.assertIn(module_name, exc.args[0], "%s warning didn't contain module name" % module_name) except ImportError: if not optional: self.fail("Non-optional module {0} raised an " "ImportError.".format(module_name)) else: # For extension modules, check the __warningregistry__. # They won't rerun their init code even with CleanImport. if not check_deprecated_module(module_name): self.fail("DeprecationWarning not raised for {0}" .format(module_name))
Example #10
Source File: test_import.py From BinderFilter with MIT License | 6 votes |
def test_imp_module(self): # Verify that the imp module can correctly load and find .py files # XXX (ncoghlan): It would be nice to use test_support.CleanImport # here, but that breaks because the os module registers some # handlers in copy_reg on import. Since CleanImport doesn't # revert that registration, the module is left in a broken # state after reversion. Reinitialising the module contents # and just reverting os.environ to its previous state is an OK # workaround orig_path = os.path orig_getenv = os.getenv with EnvironmentVarGuard(): x = imp.find_module("os") new_os = imp.load_module("os", *x) self.assertIs(os, new_os) self.assertIs(orig_path, new_os.path) self.assertIsNot(orig_getenv, new_os.getenv)
Example #11
Source File: test_py3kwarn.py From BinderFilter with MIT License | 6 votes |
def check_removal(self, module_name, optional=False): """Make sure the specified module, when imported, raises a DeprecationWarning and specifies itself in the message.""" with CleanImport(module_name), warnings.catch_warnings(): warnings.filterwarnings("error", ".+ (module|package) .+ removed", DeprecationWarning, __name__) warnings.filterwarnings("error", ".+ removed .+ (module|package)", DeprecationWarning, __name__) try: __import__(module_name, level=0) except DeprecationWarning as exc: self.assertIn(module_name, exc.args[0], "%s warning didn't contain module name" % module_name) except ImportError: if not optional: self.fail("Non-optional module {0} raised an " "ImportError.".format(module_name)) else: # For extension modules, check the __warningregistry__. # They won't rerun their init code even with CleanImport. if not check_deprecated_module(module_name): self.fail("DeprecationWarning not raised for {0}" .format(module_name))
Example #12
Source File: test_imp.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_builtin(self): with test_support.CleanImport('marshal'): import marshal imp.reload(marshal)
Example #13
Source File: test_imp.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_builtin(self): with test_support.CleanImport('marshal'): import marshal imp.reload(marshal)
Example #14
Source File: test_imp.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_extension(self): with test_support.CleanImport('time'): import time imp.reload(time)
Example #15
Source File: test_imp.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_source(self): # XXX (ncoghlan): It would be nice to use test_support.CleanImport # here, but that breaks because the os module registers some # handlers in copy_reg on import. Since CleanImport doesn't # revert that registration, the module is left in a broken # state after reversion. Reinitialising the module contents # and just reverting os.environ to its previous state is an OK # workaround with test_support.EnvironmentVarGuard(): import os imp.reload(os)
Example #16
Source File: test_py3kwarn.py From ironpython2 with Apache License 2.0 | 5 votes |
def check_removal(self, module_name, optional=False): """Make sure the specified module, when imported, raises a DeprecationWarning and specifies itself in the message.""" if module_name in sys.modules: mod = sys.modules[module_name] filename = getattr(mod, '__file__', '') mod = None # the module is not implemented in C? if not filename.endswith(('.py', '.pyc', '.pyo')): # Issue #23375: If the module was already loaded, reimporting # the module will not emit again the warning. The warning is # emited when the module is loaded, but C modules cannot # unloaded. if test_support.verbose: print("Cannot test the Python 3 DeprecationWarning of the " "%s module, the C module is already loaded" % module_name) return with CleanImport(module_name), warnings.catch_warnings(): warnings.filterwarnings("error", ".+ (module|package) .+ removed", DeprecationWarning, __name__) warnings.filterwarnings("error", ".+ removed .+ (module|package)", DeprecationWarning, __name__) try: __import__(module_name, level=0) except DeprecationWarning as exc: self.assertIn(module_name, exc.args[0], "%s warning didn't contain module name" % module_name) except ImportError: if not optional: self.fail("Non-optional module {0} raised an " "ImportError.".format(module_name)) else: # For extension modules, check the __warningregistry__. # They won't rerun their init code even with CleanImport. if not check_deprecated_module(module_name): self.fail("DeprecationWarning not raised for {0}" .format(module_name))
Example #17
Source File: test_imp.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_source(self): # XXX (ncoghlan): It would be nice to use test_support.CleanImport # here, but that breaks because the os module registers some # handlers in copy_reg on import. Since CleanImport doesn't # revert that registration, the module is left in a broken # state after reversion. Reinitialising the module contents # and just reverting os.environ to its previous state is an OK # workaround with test_support.EnvironmentVarGuard(): import os imp.reload(os)
Example #18
Source File: test_imp.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_builtin(self): with test_support.CleanImport('marshal'): import marshal imp.reload(marshal)
Example #19
Source File: test_imp.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_extension(self): with test_support.CleanImport('time'): import time imp.reload(time)
Example #20
Source File: test_imp.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_source(self): # XXX (ncoghlan): It would be nice to use test_support.CleanImport # here, but that breaks because the os module registers some # handlers in copy_reg on import. Since CleanImport doesn't # revert that registration, the module is left in a broken # state after reversion. Reinitialising the module contents # and just reverting os.environ to its previous state is an OK # workaround with test_support.EnvironmentVarGuard(): import os imp.reload(os)
Example #21
Source File: test_imp.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_extension(self): with test_support.CleanImport('time'): import time imp.reload(time)
Example #22
Source File: test_imp.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_builtin(self): with test_support.CleanImport('marshal'): import marshal imp.reload(marshal)
Example #23
Source File: test_imp.py From BinderFilter with MIT License | 5 votes |
def test_builtin(self): with test_support.CleanImport('marshal'): import marshal imp.reload(marshal)
Example #24
Source File: test_imp.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_extension(self): with test_support.CleanImport('time'): import time imp.reload(time)
Example #25
Source File: test_imp.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_source(self): # XXX (ncoghlan): It would be nice to use test_support.CleanImport # here, but that breaks because the os module registers some # handlers in copy_reg on import. Since CleanImport doesn't # revert that registration, the module is left in a broken # state after reversion. Reinitialising the module contents # and just reverting os.environ to its previous state is an OK # workaround with test_support.EnvironmentVarGuard(): import os imp.reload(os)
Example #26
Source File: test_imp.py From oss-ftp with MIT License | 5 votes |
def test_builtin(self): with test_support.CleanImport('marshal'): import marshal imp.reload(marshal)
Example #27
Source File: test_imp.py From oss-ftp with MIT License | 5 votes |
def test_extension(self): with test_support.CleanImport('time'): import time imp.reload(time)
Example #28
Source File: test_imp.py From oss-ftp with MIT License | 5 votes |
def test_source(self): # XXX (ncoghlan): It would be nice to use test_support.CleanImport # here, but that breaks because the os module registers some # handlers in copy_reg on import. Since CleanImport doesn't # revert that registration, the module is left in a broken # state after reversion. Reinitialising the module contents # and just reverting os.environ to its previous state is an OK # workaround with test_support.EnvironmentVarGuard(): import os imp.reload(os)
Example #29
Source File: test_imp.py From BinderFilter with MIT License | 5 votes |
def test_source(self): # XXX (ncoghlan): It would be nice to use test_support.CleanImport # here, but that breaks because the os module registers some # handlers in copy_reg on import. Since CleanImport doesn't # revert that registration, the module is left in a broken # state after reversion. Reinitialising the module contents # and just reverting os.environ to its previous state is an OK # workaround with test_support.EnvironmentVarGuard(): import os imp.reload(os)
Example #30
Source File: test_imp.py From BinderFilter with MIT License | 5 votes |
def test_extension(self): with test_support.CleanImport('time'): import time imp.reload(time)