]> granicus.if.org Git - python/commitdiff
Rename importlib.test.support to importlib.test.util.
authorBrett Cannon <bcannon@gmail.com>
Sun, 1 Feb 2009 04:00:05 +0000 (04:00 +0000)
committerBrett Cannon <bcannon@gmail.com>
Sun, 1 Feb 2009 04:00:05 +0000 (04:00 +0000)
22 files changed:
Lib/importlib/NOTES
Lib/importlib/test/builtin/test_finder.py
Lib/importlib/test/builtin/test_loader.py
Lib/importlib/test/extension/test_case_sensitivity.py
Lib/importlib/test/extension/test_loader.py
Lib/importlib/test/frozen/support.py [deleted file]
Lib/importlib/test/frozen/test_loader.py
Lib/importlib/test/import_/test___package__.py
Lib/importlib/test/import_/test_caching.py
Lib/importlib/test/import_/test_fromlist.py
Lib/importlib/test/import_/test_meta_path.py
Lib/importlib/test/import_/test_packages.py
Lib/importlib/test/import_/test_path.py
Lib/importlib/test/import_/test_relative_imports.py
Lib/importlib/test/source/test_case_sensitivity.py
Lib/importlib/test/source/test_finder.py
Lib/importlib/test/source/test_loader.py
Lib/importlib/test/source/test_path_hook.py
Lib/importlib/test/source/test_source_encoding.py
Lib/importlib/test/source/util.py
Lib/importlib/test/test_api.py
Lib/importlib/test/util.py [moved from Lib/importlib/test/support.py with 100% similarity]

index 8351f1e22d1f6ae4f2242773995dd0b15b888c96..fd3e0e3de592c0aae15e2cfb33b8dfd58f167be1 100644 (file)
@@ -3,6 +3,10 @@ to do
 
 * Reorganize support code.
 
+    + Separate out support code for extensions out of test_support_hook.
+    + Move util.import_ and utill.mock_modules to import_, importlib_only,
+      mock_path_hook?
+
     + Add a file loader mock that returns monotonically increasing mtime.
         - Use in source/test_reload.
         - Use in source/test_load_module_mixed.
index 70aed9774e0a0ca444b10d3efb674b9af1ea44e3..eacc36c27a5ac5d192bdcd2322f3131595ad8991 100644 (file)
@@ -1,6 +1,6 @@
 from importlib import machinery
 from .. import abc
-from .. import support
+from .. import util
 
 import sys
 import unittest
@@ -14,7 +14,7 @@ class FinderTests(abc.FinderTests):
 
     def test_module(self):
         # Common case.
-        with support.uncache(self.name):
+        with util.uncache(self.name):
             self.assert_(machinery.BuiltinImporter.find_module(self.name))
 
     def test_package(self):
@@ -40,7 +40,7 @@ class FinderTests(abc.FinderTests):
 
     def test_ignore_path(self):
         # The value for 'path' should always trigger a failed import.
-        with support.uncache(self.name):
+        with util.uncache(self.name):
             loader = machinery.BuiltinImporter.find_module(self.name, ['pkg'])
             self.assert_(loader is None)
 
index 3de05263ec2a1a57d95f6f8655ee38d63e9fdb9b..940529e68892c841bfab2dc2e56edfad31b4d1a7 100644 (file)
@@ -1,7 +1,7 @@
 import importlib
 from importlib import machinery
 from .. import abc
-from .. import support
+from .. import util
 
 import sys
 import types
@@ -29,7 +29,7 @@ class LoaderTests(abc.LoaderTests):
 
     def test_module(self):
         # Common case.
-        with support.uncache(self.name):
+        with util.uncache(self.name):
             module = self.load_module(self.name)
             self.verify(module)
 
@@ -47,7 +47,7 @@ class LoaderTests(abc.LoaderTests):
 
     def test_module_reuse(self):
         # Test that the same module is used in a reload.
-        with support.uncache(self.name):
+        with util.uncache(self.name):
             module1 = self.load_module(self.name)
             module2 = self.load_module(self.name)
             self.assert_(module1 is module2)
index 575bf69f6058e3c0cf94caa50445b89ab4de9e49..c328af239a17f3a0d8c2428c4ac9ad57fa37a077 100644 (file)
@@ -1,12 +1,12 @@
 import sys
-from test import support as test_support
+from test import support
 import unittest
 import importlib
-from .. import support
+from .. import util
 from . import test_path_hook
 
 
-@support.case_insensitive_tests
+@util.case_insensitive_tests
 class ExtensionModuleCaseSensitivityTest(unittest.TestCase):
 
     def find_module(self):
@@ -17,13 +17,13 @@ class ExtensionModuleCaseSensitivityTest(unittest.TestCase):
         return finder.find_module(bad_name)
 
     def test_case_sensitive(self):
-        with test_support.EnvironmentVarGuard() as env:
+        with support.EnvironmentVarGuard() as env:
             env.unset('PYTHONCASEOK')
             loader = self.find_module()
             self.assert_(loader is None)
 
     def test_case_insensitivity(self):
-        with test_support.EnvironmentVarGuard() as env:
+        with support.EnvironmentVarGuard() as env:
             env.set('PYTHONCASEOK', '1')
             loader = self.find_module()
             self.assert_(hasattr(loader, 'load_module'))
@@ -32,7 +32,7 @@ class ExtensionModuleCaseSensitivityTest(unittest.TestCase):
 
 
 def test_main():
-    test_support.run_unittest(ExtensionModuleCaseSensitivityTest)
+    support.run_unittest(ExtensionModuleCaseSensitivityTest)
 
 
 if __name__ == '__main__':
index 51d6161eff0c251431b9fb63af95e1f71bccabe5..1e43fdd4a21a683d5455dc4cffa36bbaf2ef2c41 100644 (file)
@@ -1,7 +1,7 @@
 import importlib
 from . import test_path_hook
 from .. import abc
-from .. import support
+from .. import util
 
 import sys
 import unittest
@@ -18,7 +18,7 @@ class LoaderTests(abc.LoaderTests):
         return loader.load_module(fullname)
 
     def test_module(self):
-        with support.uncache(test_path_hook.NAME):
+        with util.uncache(test_path_hook.NAME):
             module = self.load_module(test_path_hook.NAME)
             for attr, value in [('__name__', test_path_hook.NAME),
                                 ('__file__', test_path_hook.FILEPATH)]:
@@ -34,7 +34,7 @@ class LoaderTests(abc.LoaderTests):
         pass
 
     def test_module_reuse(self):
-        with support.uncache(test_path_hook.NAME):
+        with util.uncache(test_path_hook.NAME):
             module1 = self.load_module(test_path_hook.NAME)
             module2 = self.load_module(test_path_hook.NAME)
             self.assert_(module1 is module2)
diff --git a/Lib/importlib/test/frozen/support.py b/Lib/importlib/test/frozen/support.py
deleted file mode 100644 (file)
index e08b89e..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-import sys
-
-
-class Null:
-
-    """Just absorb what is given."""
-
-    def __getattr__(self):
-        return lambda *args, **kwargs: None
-
-
-class SilenceStdout:
-
-    """Silence sys.stdout."""
-
-    def setUp(self):
-        """Substitute sys.stdout with something that does not print to the
-        screen thanks to what bytecode is frozen."""
-        sys.stdout = Null()
-        super().setUp()
-
-    def tearDown(self):
-        sys.stdout = sys.__stdout__
-        super().tearDown()
index 63a9742ad436e397c87c3801e42dd6d29791b75f..c6f44633232dcbaa1af07389ed5a14ca83c16f5d 100644 (file)
@@ -1,12 +1,12 @@
 from importlib import machinery
 from .. import abc
-from .. import support
+from .. import util
 
 
 class LoaderTests(abc.LoaderTests):
 
     def test_module(self):
-        with support.uncache('__hello__'):
+        with util.uncache('__hello__'):
             module = machinery.FrozenImporter.load_module('__hello__')
             check = {'__name__': '__hello__', '__file__': '<frozen>',
                         '__package__': None}
@@ -14,7 +14,7 @@ class LoaderTests(abc.LoaderTests):
                 self.assertEqual(getattr(module, attr), value)
 
     def test_package(self):
-        with support.uncache('__phello__'):
+        with util.uncache('__phello__'):
             module = machinery.FrozenImporter.load_module('__phello__')
             check = {'__name__': '__phello__', '__file__': '<frozen>',
                      '__package__': '__phello__', '__path__': ['__phello__']}
@@ -25,7 +25,7 @@ class LoaderTests(abc.LoaderTests):
                                  (attr, attr_value, value))
 
     def test_lacking_parent(self):
-        with support.uncache('__phello__', '__phello__.spam'):
+        with util.uncache('__phello__', '__phello__.spam'):
             module = machinery.FrozenImporter.load_module('__phello__.spam')
             check = {'__name__': '__phello__.spam', '__file__': '<frozen>',
                      '__package__': '__phello__'}
@@ -36,7 +36,7 @@ class LoaderTests(abc.LoaderTests):
                                  (attr, attr_value, value))
 
     def test_module_reuse(self):
-        with support.uncache('__hello__'):
+        with util.uncache('__hello__'):
             module1 = machinery.FrozenImporter.load_module('__hello__')
             module2 = machinery.FrozenImporter.load_module('__hello__')
             self.assert_(module1 is module2)
index 64dab3ad6eb69d05305fded3bd1113aa3697e7b2..d29ca4416b4af2154c94bfa78e6375e05b44db8b 100644 (file)
@@ -5,7 +5,7 @@ of using the typical __path__/__name__ test).
 
 """
 import unittest
-from .. import support
+from .. import util
 
 
 class Using__package__(unittest.TestCase):
@@ -34,19 +34,19 @@ class Using__package__(unittest.TestCase):
 
     def test_using___package__(self):
         # [__package__]
-        with support.mock_modules('pkg.__init__', 'pkg.fake') as importer:
-            with support.import_state(meta_path=[importer]):
-                support.import_('pkg.fake')
-                module = support.import_('', globals={'__package__': 'pkg.fake'},
+        with util.mock_modules('pkg.__init__', 'pkg.fake') as importer:
+            with util.import_state(meta_path=[importer]):
+                util.import_('pkg.fake')
+                module = util.import_('', globals={'__package__': 'pkg.fake'},
                                  fromlist=['attr'], level=2)
         self.assertEquals(module.__name__, 'pkg')
 
     def test_using___name__(self):
         # [__name__]
-        with support.mock_modules('pkg.__init__', 'pkg.fake') as importer:
-            with support.import_state(meta_path=[importer]):
-                support.import_('pkg.fake')
-                module = support.import_('',
+        with util.mock_modules('pkg.__init__', 'pkg.fake') as importer:
+            with util.import_state(meta_path=[importer]):
+                util.import_('pkg.fake')
+                module = util.import_('',
                                  globals={'__name__': 'pkg.fake',
                                           '__path__': []},
                                  fromlist=['attr'], level=2)
@@ -54,12 +54,12 @@ class Using__package__(unittest.TestCase):
 
     def test_bad__package__(self):
         globals = {'__package__': '<not real>'}
-        self.assertRaises(SystemError, support.import_,'', globals, {},
+        self.assertRaises(SystemError, util.import_,'', globals, {},
                             ['relimport'], 1)
 
     def test_bunk__package__(self):
         globals = {'__package__': 42}
-        self.assertRaises(ValueError, support.import_, '', globals, {},
+        self.assertRaises(ValueError, util.import_, '', globals, {},
                             ['relimport'], 1)
 
 
@@ -77,26 +77,26 @@ class Setting__package__(unittest.TestCase):
 
     # [top-level]
     def test_top_level(self):
-        with support.mock_modules('top_level') as mock:
-            with support.import_state(meta_path=[mock]):
+        with util.mock_modules('top_level') as mock:
+            with util.import_state(meta_path=[mock]):
                 del mock['top_level'].__package__
-                module = support.import_('top_level')
+                module = util.import_('top_level')
                 self.assert_(module.__package__ is None)
 
     # [package]
     def test_package(self):
-        with support.mock_modules('pkg.__init__') as mock:
-            with support.import_state(meta_path=[mock]):
+        with util.mock_modules('pkg.__init__') as mock:
+            with util.import_state(meta_path=[mock]):
                 del mock['pkg'].__package__
-                module = support.import_('pkg')
+                module = util.import_('pkg')
                 self.assertEqual(module.__package__, 'pkg')
 
     # [submodule]
     def test_submodule(self):
-        with support.mock_modules('pkg.__init__', 'pkg.mod') as mock:
-            with support.import_state(meta_path=[mock]):
+        with util.mock_modules('pkg.__init__', 'pkg.mod') as mock:
+            with util.import_state(meta_path=[mock]):
                 del mock['pkg.mod'].__package__
-                pkg = support.import_('pkg.mod')
+                pkg = util.import_('pkg.mod')
                 module = getattr(pkg, 'mod')
                 self.assertEqual(module.__package__, 'pkg')
 
index 57690d432b3a13ccc958cf86589200d0a86faf2e..a4b7b46f9f252f2bde9929aace41ff1a22df0032 100644 (file)
@@ -1,6 +1,5 @@
 """Test that sys.modules is used properly by import."""
-from ..support import import_, mock_modules, importlib_only, import_state
-
+from .. import util
 import sys
 from types import MethodType
 import unittest
@@ -24,11 +23,11 @@ class UseCache(unittest.TestCase):
         # [use cache]
         module_to_use = "some module found!"
         sys.modules['some_module'] = module_to_use
-        module = import_('some_module')
+        module = util.import_('some_module')
         self.assertEqual(id(module_to_use), id(module))
 
     def create_mock(self, *names, return_=None):
-        mock = mock_modules(*names)
+        mock = util.mock_modules(*names)
         original_load = mock.load_module
         def load_module(self, fullname):
             original_load(fullname)
@@ -38,31 +37,31 @@ class UseCache(unittest.TestCase):
 
     # __import__ inconsistent between loaders and built-in import when it comes
     #   to when to use the module in sys.modules and when not to.
-    @importlib_only
+    @util.importlib_only
     def test_using_cache_after_loader(self):
         # [from cache on return]
         with self.create_mock('module') as mock:
-            with import_state(meta_path=[mock]):
-                module = import_('module')
+            with util.import_state(meta_path=[mock]):
+                module = util.import_('module')
                 self.assertEquals(id(module), id(sys.modules['module']))
 
     # See test_using_cache_after_loader() for reasoning.
-    @importlib_only
+    @util.importlib_only
     def test_using_cache_for_assigning_to_attribute(self):
         # [from cache to attribute]
         with self.create_mock('pkg.__init__', 'pkg.module') as importer:
-            with import_state(meta_path=[importer]):
-                module = import_('pkg.module')
+            with util.import_state(meta_path=[importer]):
+                module = util.import_('pkg.module')
                 self.assert_(hasattr(module, 'module'))
                 self.assert_(id(module.module), id(sys.modules['pkg.module']))
 
     # See test_using_cache_after_loader() for reasoning.
-    @importlib_only
+    @util.importlib_only
     def test_using_cache_for_fromlist(self):
         # [from cache for fromlist]
         with self.create_mock('pkg.__init__', 'pkg.module') as importer:
-            with import_state(meta_path=[importer]):
-                module = import_('pkg', fromlist=['module'])
+            with util.import_state(meta_path=[importer]):
+                module = util.import_('pkg', fromlist=['module'])
                 self.assert_(hasattr(module, 'module'))
                 self.assertEquals(id(module.module), id(sys.modules['pkg.module']))
 
index 884b516d36d84015bbf8d3176e508cd04b9fbf7b..4e0d86a78d239e5230c1842d4adefd42b29c354d 100644 (file)
@@ -1,6 +1,5 @@
 """Test that the semantics relating to the 'fromlist' argument are correct."""
-from ..support import import_, mock_modules, import_state
-
+from .. import util
 import unittest
 
 class ReturnValue(unittest.TestCase):
@@ -16,16 +15,16 @@ class ReturnValue(unittest.TestCase):
 
     def test_return_from_import(self):
         # [import return]
-        with mock_modules('pkg.__init__', 'pkg.module') as importer:
-            with import_state(meta_path=[importer]):
-                module = import_('pkg.module')
+        with util.mock_modules('pkg.__init__', 'pkg.module') as importer:
+            with util.import_state(meta_path=[importer]):
+                module = util.import_('pkg.module')
                 self.assertEquals(module.__name__, 'pkg')
 
     def test_return_from_from_import(self):
         # [from return]
-        with mock_modules('pkg.__init__', 'pkg.module')as importer:
-            with import_state(meta_path=[importer]):
-                module = import_('pkg.module', fromlist=['attr'])
+        with util.mock_modules('pkg.__init__', 'pkg.module')as importer:
+            with util.import_state(meta_path=[importer]):
+                module = util.import_('pkg.module', fromlist=['attr'])
                 self.assertEquals(module.__name__, 'pkg.module')
 
 
@@ -48,59 +47,59 @@ class HandlingFromlist(unittest.TestCase):
 
     def test_object(self):
         # [object case]
-        with mock_modules('module') as importer:
-            with import_state(meta_path=[importer]):
-                module = import_('module', fromlist=['attr'])
+        with util.mock_modules('module') as importer:
+            with util.import_state(meta_path=[importer]):
+                module = util.import_('module', fromlist=['attr'])
                 self.assertEquals(module.__name__, 'module')
 
     def test_unexistent_object(self):
         # [bad object]
-        with mock_modules('module') as importer:
-            with import_state(meta_path=[importer]):
-                module = import_('module', fromlist=['non_existent'])
+        with util.mock_modules('module') as importer:
+            with util.import_state(meta_path=[importer]):
+                module = util.import_('module', fromlist=['non_existent'])
                 self.assertEquals(module.__name__, 'module')
                 self.assert_(not hasattr(module, 'non_existent'))
 
     def test_module_from_package(self):
         # [module]
-        with mock_modules('pkg.__init__', 'pkg.module') as importer:
-            with import_state(meta_path=[importer]):
-                module = import_('pkg', fromlist=['module'])
+        with util.mock_modules('pkg.__init__', 'pkg.module') as importer:
+            with util.import_state(meta_path=[importer]):
+                module = util.import_('pkg', fromlist=['module'])
                 self.assertEquals(module.__name__, 'pkg')
                 self.assert_(hasattr(module, 'module'))
                 self.assertEquals(module.module.__name__, 'pkg.module')
 
     def test_no_module_from_package(self):
         # [no module]
-        with mock_modules('pkg.__init__') as importer:
-            with import_state(meta_path=[importer]):
-                module = import_('pkg', fromlist='non_existent')
+        with util.mock_modules('pkg.__init__') as importer:
+            with util.import_state(meta_path=[importer]):
+                module = util.import_('pkg', fromlist='non_existent')
                 self.assertEquals(module.__name__, 'pkg')
                 self.assert_(not hasattr(module, 'non_existent'))
 
     def test_empty_string(self):
-        with mock_modules('pkg.__init__', 'pkg.mod') as importer:
-            with import_state(meta_path=[importer]):
-                module = import_('pkg.mod', fromlist=[''])
+        with util.mock_modules('pkg.__init__', 'pkg.mod') as importer:
+            with util.import_state(meta_path=[importer]):
+                module = util.import_('pkg.mod', fromlist=[''])
                 self.assertEquals(module.__name__, 'pkg.mod')
 
     def test_using_star(self):
         # [using *]
-        with mock_modules('pkg.__init__', 'pkg.module') as mock:
-            with import_state(meta_path=[mock]):
+        with util.mock_modules('pkg.__init__', 'pkg.module') as mock:
+            with util.import_state(meta_path=[mock]):
                 mock['pkg'].__all__ = ['module']
-                module = import_('pkg', fromlist=['*'])
+                module = util.import_('pkg', fromlist=['*'])
                 self.assertEquals(module.__name__, 'pkg')
                 self.assert_(hasattr(module, 'module'))
                 self.assertEqual(module.module.__name__, 'pkg.module')
 
     def test_star_with_others(self):
         # [using * with others]
-        context = mock_modules('pkg.__init__', 'pkg.module1', 'pkg.module2')
+        context = util.mock_modules('pkg.__init__', 'pkg.module1', 'pkg.module2')
         with context as mock:
-            with import_state(meta_path=[mock]):
+            with util.import_state(meta_path=[mock]):
                 mock['pkg'].__all__ = ['module1']
-                module = import_('pkg', fromlist=['module2', '*'])
+                module = util.import_('pkg', fromlist=['module2', '*'])
                 self.assertEquals(module.__name__, 'pkg')
                 self.assert_(hasattr(module, 'module1'))
                 self.assert_(hasattr(module, 'module2'))
index 37f40d7e4ec6061978843f146085c01f2d208774..a7b25914dd89562953d4e27d3c0de6b55ac3aace 100644 (file)
@@ -1,5 +1,4 @@
-from ..support import import_state, mock_modules, import_
-
+from .. import util
 from contextlib import nested
 from types import MethodType
 import unittest
@@ -16,24 +15,25 @@ class CallingOrder(unittest.TestCase):
     def test_first_called(self):
         # [first called]
         mod = 'top_level'
-        first = mock_modules(mod)
-        second = mock_modules(mod)
-        with nested(mock_modules(mod), mock_modules(mod)) as (first, second):
+        first = util.mock_modules(mod)
+        second = util.mock_modules(mod)
+        context = nested(util.mock_modules(mod), util.mock_modules(mod))
+        with  context as (first, second):
             first.modules[mod] = 42
             second.modules[mod] = -13
-            with import_state(meta_path=[first, second]):
-                self.assertEquals(import_(mod), 42)
+            with util.import_state(meta_path=[first, second]):
+                self.assertEquals(util.import_(mod), 42)
 
     def test_continuing(self):
         # [continuing]
         mod_name = 'for_real'
-        first = mock_modules('nonexistent')
-        second = mock_modules(mod_name)
+        first = util.mock_modules('nonexistent')
+        second = util.mock_modules(mod_name)
         with nested(first, second):
             first.find_module = lambda self, fullname, path=None: None
             second.modules[mod_name] = 42
-            with import_state(meta_path=[first, second]):
-                self.assertEquals(import_(mod_name), 42)
+            with util.import_state(meta_path=[first, second]):
+                self.assertEquals(util.import_(mod_name), 42)
 
 
 class CallSignature(unittest.TestCase):
@@ -54,11 +54,11 @@ class CallSignature(unittest.TestCase):
         # [no path]
         mod_name = 'top_level'
         assert '.' not in mod_name
-        with mock_modules(mod_name) as importer:
+        with util.mock_modules(mod_name) as importer:
             log, wrapped_call = self.log(importer.find_module)
             importer.find_module = MethodType(wrapped_call, importer)
-            with import_state(meta_path=[importer]):
-                import_(mod_name)
+            with util.import_state(meta_path=[importer]):
+                util.import_(mod_name)
                 assert len(log) == 1
                 args = log[0][0]
                 kwargs = log[0][1]
@@ -74,12 +74,12 @@ class CallSignature(unittest.TestCase):
         mod_name = pkg_name + '.module'
         path = [42]
         assert '.' in mod_name
-        with mock_modules(pkg_name+'.__init__', mod_name) as importer:
+        with util.mock_modules(pkg_name+'.__init__', mod_name) as importer:
             importer.modules[pkg_name].__path__ = path
             log, wrapped_call = self.log(importer.find_module)
             importer.find_module = MethodType(wrapped_call, importer)
-            with import_state(meta_path=[importer]):
-                import_(mod_name)
+            with util.import_state(meta_path=[importer]):
+                util.import_(mod_name)
                 assert len(log) == 2
                 args = log[1][0]
                 kwargs = log[1][1]
index 013bbdc2df7368c7645183f4d257568737c33cc1..7f17c4bd356b5cbe49768c98b9ea1c72958faf85 100644 (file)
@@ -1,7 +1,7 @@
+from .. import util
 import sys
 import unittest
 import importlib
-from .. import support
 
 
 class ParentModuleTests(unittest.TestCase):
@@ -9,15 +9,15 @@ class ParentModuleTests(unittest.TestCase):
     """Importing a submodule should import the parent modules."""
 
     def test_import_parent(self):
-        with support.mock_modules('pkg.__init__', 'pkg.module') as mock:
-            with support.import_state(meta_path=[mock]):
-                module = support.import_('pkg.module')
+        with util.mock_modules('pkg.__init__', 'pkg.module') as mock:
+            with util.import_state(meta_path=[mock]):
+                module = util.import_('pkg.module')
                 self.assert_('pkg' in sys.modules)
 
     def test_bad_parent(self):
-        with support.mock_modules('pkg.module') as mock:
-            with support.import_state(meta_path=[mock]):
-                self.assertRaises(ImportError, support.import_, 'pkg.module')
+        with util.mock_modules('pkg.module') as mock:
+            with util.import_state(meta_path=[mock]):
+                self.assertRaises(ImportError, util.import_, 'pkg.module')
 
 
 def test_main():
index c939907af1869b8223668b0663618f9d175c7757..5935dc4ec53da884cc7b3e51d963ccfb20078977 100644 (file)
@@ -1,6 +1,4 @@
-from ..support import (mock_modules, import_state, import_, mock_path_hook,
-                        importlib_only, uncache)
-
+from .. import util
 from contextlib import nested
 from imp import new_module
 import sys
@@ -32,7 +30,7 @@ class BaseTests(unittest.TestCase):
     def order_test(self, to_import, entry, search_path, path=[]):
         # [order]
         log = []
-        class LogFindModule(mock_modules):
+        class LogFindModule(util.mock_modules):
             def find_module(self, fullname):
                 log.append(self)
                 return super().find_module(fullname)
@@ -42,12 +40,12 @@ class BaseTests(unittest.TestCase):
         hitter = LogFindModule(to_import)
         with nested(misser, hitter):
             cache = dict(zip(search_path, (misser, hitter)))
-            with import_state(path=path, path_importer_cache=cache):
-                import_(to_import)
+            with util.import_state(path=path, path_importer_cache=cache):
+                util.import_(to_import)
         self.assertEquals(log[0], misser)
         self.assertEquals(log[1], hitter)
 
-    @importlib_only  # __import__ uses PyDict_GetItem(), bypassing log.
+    @util.importlib_only  # __import__ uses PyDict_GetItem(), bypassing log.
     def cache_use_test(self, to_import, entry, path=[]):
         # [cache check], [cache use]
         log = []
@@ -56,11 +54,11 @@ class BaseTests(unittest.TestCase):
                 log.append(item)
                 return super(LoggingDict, self).__getitem__(item)
 
-        with mock_modules(to_import) as importer:
+        with util.mock_modules(to_import) as importer:
             cache = LoggingDict()
             cache[entry] = importer
-            with import_state(path=[entry], path_importer_cache=cache):
-                module = import_(to_import, fromlist=['a'])
+            with util.import_state(path=[entry], path_importer_cache=cache):
+                module = util.import_(to_import, fromlist=['a'])
             self.assert_(module is importer[to_import])
         self.assertEquals(len(cache), 1)
         self.assertEquals([entry], log)
@@ -71,11 +69,11 @@ class BaseTests(unittest.TestCase):
         def logging_hook(entry):
             log.append(entry)
             raise ImportError
-        with mock_modules(to_import) as importer:
-            hitter = mock_path_hook(entry, importer=importer)
+        with util.mock_modules(to_import) as importer:
+            hitter = util.mock_path_hook(entry, importer=importer)
             path_hooks = [logging_hook, logging_hook, hitter]
-            with import_state(path_hooks=path_hooks, path=path):
-                import_(to_import)
+            with util.import_state(path_hooks=path_hooks, path=path):
+                util.import_(to_import)
                 self.assertEquals(sys.path_importer_cache[entry], importer)
         self.assertEquals(len(log), 2)
 
@@ -90,7 +88,7 @@ class BaseTests(unittest.TestCase):
                 raise ImportError
 
         try:
-            import_(to_import)
+            util.import_(to_import)
         except ImportError:
             pass
 
@@ -113,7 +111,7 @@ class PathTests(BaseTests):
 
     def test_path_argument(self):
         name = 'total junk'
-        with uncache(name):
+        with util.uncache(name):
             self.path_argument_test(name)
 
 
@@ -122,13 +120,13 @@ class __path__Tests(BaseTests):
     """Tests for __path__."""
 
     def run_test(self, test, entry, path, *args):
-        with mock_modules('pkg.__init__') as importer:
+        with util.mock_modules('pkg.__init__') as importer:
             importer['pkg'].__path__ = path
             importer.load_module('pkg')
             test('pkg.hit', entry, *args)
 
 
-    @importlib_only  # XXX Unknown reason why this fails.
+    @util.importlib_only  # XXX Unknown reason why this fails.
     def test_order(self):
         self.run_test(self.order_test, 'second', ('first', 'second'), ['first',
             'second'])
@@ -146,7 +144,7 @@ class __path__Tests(BaseTests):
         module.__path__ = ['random __path__']
         name = 'pkg.whatever'
         sys.modules['pkg'] = module
-        with uncache('pkg', name):
+        with util.uncache('pkg', name):
             self.path_argument_test(name)
 
 
index 73ef530d4f7a090b732c88d945b58dcaadbe0736..fb543ad74cca73d114b9378d3ba4bfaa9b7c4bab 100644 (file)
@@ -1,7 +1,5 @@
 """Test relative imports (PEP 328)."""
-
-from ..support import uncache, import_, mock_modules, import_state
-
+from .. import util
 import sys
 import unittest
 
@@ -65,10 +63,10 @@ class RelativeImports(unittest.TestCase):
                 uncache_names.append(name)
             else:
                 uncache_names.append(name[:-len('.__init__')])
-        with mock_modules(*create) as importer:
-            with import_state(meta_path=[importer]):
+        with util.mock_modules(*create) as importer:
+            with util.import_state(meta_path=[importer]):
                 for global_ in globals_:
-                    with uncache(*uncache_names):
+                    with util.uncache(*uncache_names):
                         callback(global_)
 
 
@@ -77,8 +75,8 @@ class RelativeImports(unittest.TestCase):
         create = 'pkg.__init__', 'pkg.mod2'
         globals_ = {'__package__': 'pkg'}, {'__name__': 'pkg.mod1'}
         def callback(global_):
-            import_('pkg')  # For __import__().
-            module = import_('', global_, fromlist=['mod2'], level=1)
+            util.import_('pkg')  # For __import__().
+            module = util.import_('', global_, fromlist=['mod2'], level=1)
             self.assertEqual(module.__name__, 'pkg')
             self.assert_(hasattr(module, 'mod2'))
             self.assertEqual(module.mod2.attr, 'pkg.mod2')
@@ -89,8 +87,8 @@ class RelativeImports(unittest.TestCase):
         create = 'pkg.__init__', 'pkg.mod2'
         globals_ = {'__package__': 'pkg'}, {'__name__': 'pkg.mod1'}
         def callback(global_):
-            import_('pkg')  # For __import__().
-            module = import_('mod2', global_, fromlist=['attr'], level=1)
+            util.import_('pkg')  # For __import__().
+            module = util.import_('mod2', global_, fromlist=['attr'], level=1)
             self.assertEqual(module.__name__, 'pkg.mod2')
             self.assertEqual(module.attr, 'pkg.mod2')
         self.relative_import_test(create, globals_, callback)
@@ -101,8 +99,8 @@ class RelativeImports(unittest.TestCase):
         globals_ = ({'__package__': 'pkg'},
                     {'__name__': 'pkg', '__path__': ['blah']})
         def callback(global_):
-            import_('pkg')  # For __import__().
-            module = import_('', global_, fromlist=['module'],
+            util.import_('pkg')  # For __import__().
+            module = util.import_('', global_, fromlist=['module'],
                              level=1)
             self.assertEqual(module.__name__, 'pkg')
             self.assert_(hasattr(module, 'module'))
@@ -114,8 +112,8 @@ class RelativeImports(unittest.TestCase):
         create = 'pkg.__init__', 'pkg.module'
         globals_ = {'__package__': 'pkg'}, {'__name__': 'pkg.module'}
         def callback(global_):
-            import_('pkg')  # For __import__().
-            module = import_('', global_, fromlist=['attr'], level=1)
+            util.import_('pkg')  # For __import__().
+            module = util.import_('', global_, fromlist=['attr'], level=1)
             self.assertEqual(module.__name__, 'pkg')
         self.relative_import_test(create, globals_, callback)
 
@@ -126,7 +124,7 @@ class RelativeImports(unittest.TestCase):
         globals_ =  ({'__package__': 'pkg.subpkg1'},
                      {'__name__': 'pkg.subpkg1', '__path__': ['blah']})
         def callback(global_):
-            module = import_('', global_, fromlist=['subpkg2'], level=2)
+            module = util.import_('', global_, fromlist=['subpkg2'], level=2)
             self.assertEqual(module.__name__, 'pkg')
             self.assert_(hasattr(module, 'subpkg2'))
             self.assertEqual(module.subpkg2.attr, 'pkg.subpkg2.__init__')
@@ -141,8 +139,8 @@ class RelativeImports(unittest.TestCase):
                     {'__name__': 'pkg.pkg1.pkg2.pkg3.pkg4.pkg5',
                         '__path__': ['blah']})
         def callback(global_):
-            import_(globals_[0]['__package__'])
-            module = import_('', global_, fromlist=['attr'], level=6)
+            util.import_(globals_[0]['__package__'])
+            module = util.import_('', global_, fromlist=['attr'], level=6)
             self.assertEqual(module.__name__, 'pkg')
         self.relative_import_test(create, globals_, callback)
 
@@ -152,8 +150,8 @@ class RelativeImports(unittest.TestCase):
         globals_ = ({'__package__': 'pkg'},
                     {'__name__': 'pkg', '__path__': ['blah']})
         def callback(global_):
-            import_('pkg')
-            self.assertRaises(ValueError, import_, '', global_,
+            util.import_('pkg')
+            self.assertRaises(ValueError, util.import_, '', global_,
                                 fromlist=['top_level'], level=2)
         self.relative_import_test(create, globals_, callback)
 
@@ -162,14 +160,14 @@ class RelativeImports(unittest.TestCase):
         create = ['top_level', 'pkg.__init__', 'pkg.module']
         globals_ = {'__package__': 'pkg'}, {'__name__': 'pkg.module'}
         def callback(global_):
-            import_('pkg')
-            self.assertRaises(ValueError, import_, '', global_,
+            util.import_('pkg')
+            self.assertRaises(ValueError, util.import_, '', global_,
                                 fromlist=['top_level'], level=2)
         self.relative_import_test(create, globals_, callback)
 
     def test_empty_name_w_level_0(self):
         # [empty name]
-        self.assertRaises(ValueError, import_, '')
+        self.assertRaises(ValueError, util.import_, '')
 
     def test_import_from_different_package(self):
         # Test importing from a different package than the caller.
@@ -183,8 +181,9 @@ class RelativeImports(unittest.TestCase):
                     '__runpy_pkg__.uncle.cousin.nephew']
         globals_ = {'__package__': '__runpy_pkg__.__runpy_pkg__'}
         def callback(global_):
-            import_('__runpy_pkg__.__runpy_pkg__')
-            module = import_('uncle.cousin', globals_, {}, fromlist=['nephew'],
+            util.import_('__runpy_pkg__.__runpy_pkg__')
+            module = util.import_('uncle.cousin', globals_, {},
+                                    fromlist=['nephew'],
                                 level=2)
             self.assertEqual(module.__name__, '__runpy_pkg__.uncle.cousin')
         self.relative_import_test(create, globals_, callback)
index 955d6ec4e17c99ee7bb9838bc77e7039a9c98294..6bd86cfcd9c8265cbf7109ec0bc64ad851dc8448 100644 (file)
@@ -1,6 +1,6 @@
 """Test case-sensitivity (PEP 235)."""
 import importlib
-from .. import support
+from .. import util
 from . import util as source_util
 import os
 import sys
@@ -8,7 +8,7 @@ from test import support as test_support
 import unittest
 
 
-@support.case_insensitive_tests
+@util.case_insensitive_tests
 class CaseSensitivityTest(unittest.TestCase):
 
     """PEP 235 dictates that on case-preserving, case-insensitive file systems
index a84d914071349a2662f67debfd036d7ec006e59b..0f1f549baa79378c3f50b7ae55fd4d68daa4323a 100644 (file)
@@ -1,6 +1,5 @@
 import importlib
 from .. import abc
-from .. import support
 from . import util as source_util
 import os
 import py_compile
index 67930fcb3fdaf02f93e684cb152d9daf317a0425..e333b850fe9a8a55abc28cbb5f0808ce0ed83e40 100644 (file)
@@ -1,6 +1,5 @@
 import importlib
 from .. import abc
-from .. import support
 from . import util as source_util
 
 import imp
index 5fa3fd909cc79d0cb105e20b7d32daa903bc5351..5aac42e5ff9d3c2eda5e0793d57db5781b549d28 100644 (file)
@@ -1,5 +1,5 @@
 import importlib
-from . import util
+from . import util as source_util
 import unittest
 
 
@@ -9,7 +9,7 @@ class PathHookTest(unittest.TestCase):
 
     def test_success(self):
         # XXX Only work on existing directories?
-        with util.create_modules('dummy') as mapping:
+        with source_util.create_modules('dummy') as mapping:
             self.assert_(hasattr(importlib.FileImporter(mapping['.root']),
                                  'find_module'))
 
index 7c9a57b580f5167c3d1fe0f7a4961c09d43889fb..5ffdf8f7fd6bce53a4315df528c770218e6f512b 100644 (file)
@@ -1,5 +1,4 @@
 import importlib
-from .. import support
 from . import util as source_util
 
 import codecs
index 5400c82e77ba9bff25227b898774d75c70f49a60..333647d52f32f3db5f162b89c6b4d16ca5648334 100644 (file)
@@ -1,11 +1,11 @@
-from .. import support as util
+from .. import util
 import contextlib
 import imp
 import os
 import os.path
 import sys
 import tempfile
-from test import support as support
+from test import support
 
 
 def writes_bytecode(fxn):
index 75053a074c9da6bdd39c4085000a4fd0eff56a07..2958adbe463f28203d51238a75f7dfd85974f8a5 100644 (file)
@@ -1,6 +1,6 @@
 import unittest
 import importlib
-from . import support
+from . import util
 
 
 class ImportModuleTests(unittest.TestCase):
@@ -9,8 +9,8 @@ class ImportModuleTests(unittest.TestCase):
 
     def test_module_import(self):
         # Test importing a top-level module.
-        with support.mock_modules('top_level') as mock:
-            with support.import_state(meta_path=[mock]):
+        with util.mock_modules('top_level') as mock:
+            with util.import_state(meta_path=[mock]):
                 module = importlib.import_module('top_level')
                 self.assertEqual(module.__name__, 'top_level')
 
@@ -19,8 +19,8 @@ class ImportModuleTests(unittest.TestCase):
         pkg_name = 'pkg'
         pkg_long_name = '{0}.__init__'.format(pkg_name)
         name = '{0}.mod'.format(pkg_name)
-        with support.mock_modules(pkg_long_name, name) as mock:
-            with support.import_state(meta_path=[mock]):
+        with util.mock_modules(pkg_long_name, name) as mock:
+            with util.import_state(meta_path=[mock]):
                 module = importlib.import_module(name)
                 self.assertEqual(module.__name__, name)
 
@@ -31,8 +31,8 @@ class ImportModuleTests(unittest.TestCase):
         module_name = 'mod'
         absolute_name = '{0}.{1}'.format(pkg_name, module_name)
         relative_name = '.{0}'.format(module_name)
-        with support.mock_modules(pkg_long_name, absolute_name) as mock:
-            with support.import_state(meta_path=[mock]):
+        with util.mock_modules(pkg_long_name, absolute_name) as mock:
+            with util.import_state(meta_path=[mock]):
                 module = importlib.import_module(relative_name, pkg_name)
                 self.assertEqual(module.__name__, absolute_name)
 
@@ -42,8 +42,8 @@ class ImportModuleTests(unittest.TestCase):
         pkg_name = 'pkg'
         pkg_long_name = '{0}.__init__'.format(pkg_name)
         name = '{0}.mod'.format(pkg_name)
-        with support.mock_modules(pkg_long_name, name) as mock:
-            with support.import_state(meta_path=[mock]):
+        with util.mock_modules(pkg_long_name, name) as mock:
+            with util.import_state(meta_path=[mock]):
                 module = importlib.import_module(name, pkg_name)
                 self.assertEqual(module.__name__, name)