[Python-checkins] r69401 - in python/branches/py3k/Lib/importlib: NOTES test/extension/test_case_sensitivity.py test/extension/test_finder.py test/extension/test_loader.py test/extension/test_path_hook.py test/util.py

brett.cannon python-checkins at python.org
Sat Feb 7 03:06:43 CET 2009


Author: brett.cannon
Date: Sat Feb 7 03:06:43 2009
New Revision: 69401
Log:
Factor out helper code from importlib.test.extension.test_path_hook.
Modified:
 python/branches/py3k/Lib/importlib/NOTES
 python/branches/py3k/Lib/importlib/test/extension/test_case_sensitivity.py
 python/branches/py3k/Lib/importlib/test/extension/test_finder.py
 python/branches/py3k/Lib/importlib/test/extension/test_loader.py
 python/branches/py3k/Lib/importlib/test/extension/test_path_hook.py
 python/branches/py3k/Lib/importlib/test/util.py
Modified: python/branches/py3k/Lib/importlib/NOTES
==============================================================================
--- python/branches/py3k/Lib/importlib/NOTES	(original)
+++ python/branches/py3k/Lib/importlib/NOTES	Sat Feb 7 03:06:43 2009
@@ -1,8 +1,6 @@
 to do
 /////
 
-* Extract test_path_hooks constants into a util module for extension testing.
-
 * Backport a poor-man's functools.wraps.
 
 * Implement PEP 302 protocol for loaders (should just be a matter of testing).
Modified: python/branches/py3k/Lib/importlib/test/extension/test_case_sensitivity.py
==============================================================================
--- python/branches/py3k/Lib/importlib/test/extension/test_case_sensitivity.py	(original)
+++ python/branches/py3k/Lib/importlib/test/extension/test_case_sensitivity.py	Sat Feb 7 03:06:43 2009
@@ -3,17 +3,17 @@
 import unittest
 import importlib
 from .. import util
-from . import test_path_hook
+from . import util as ext_util
 
 
 @util.case_insensitive_tests
 class ExtensionModuleCaseSensitivityTest(unittest.TestCase):
 
 def find_module(self):
- good_name = test_path_hook.NAME
+ good_name = ext_util.NAME
 bad_name = good_name.upper()
 assert good_name != bad_name
- finder = importlib.ExtensionFileImporter(test_path_hook.PATH)
+ finder = importlib.ExtensionFileImporter(ext_util.PATH)
 return finder.find_module(bad_name)
 
 def test_case_sensitive(self):
Modified: python/branches/py3k/Lib/importlib/test/extension/test_finder.py
==============================================================================
--- python/branches/py3k/Lib/importlib/test/extension/test_finder.py	(original)
+++ python/branches/py3k/Lib/importlib/test/extension/test_finder.py	Sat Feb 7 03:06:43 2009
@@ -1,6 +1,6 @@
 import importlib
 from .. import abc
-from . import test_path_hook
+from . import util
 
 import unittest
 
@@ -9,11 +9,11 @@
 """Test the finder for extension modules."""
 
 def find_module(self, fullname):
- importer = importlib.ExtensionFileImporter(test_path_hook.PATH)
+ importer = importlib.ExtensionFileImporter(util.PATH)
 return importer.find_module(fullname)
 
 def test_module(self):
- self.assert_(self.find_module(test_path_hook.NAME))
+ self.assert_(self.find_module(util.NAME))
 
 def test_package(self):
 # Extension modules cannot be an __init__ for a package.
Modified: python/branches/py3k/Lib/importlib/test/extension/test_loader.py
==============================================================================
--- python/branches/py3k/Lib/importlib/test/extension/test_loader.py	(original)
+++ python/branches/py3k/Lib/importlib/test/extension/test_loader.py	Sat Feb 7 03:06:43 2009
@@ -1,5 +1,5 @@
 import importlib
-from . import test_path_hook
+from . import util as ext_util
 from .. import abc
 from .. import util
 
@@ -12,19 +12,18 @@
 """Test load_module() for extension modules."""
 
 def load_module(self, fullname):
- loader = importlib._ExtensionFileLoader(test_path_hook.NAME,
- test_path_hook.FILEPATH,
- False)
+ loader = importlib._ExtensionFileLoader(ext_util.NAME,
+ ext_util.FILEPATH, False)
 return loader.load_module(fullname)
 
 def test_module(self):
- 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),
+ with util.uncache(ext_util.NAME):
+ module = self.load_module(ext_util.NAME)
+ for attr, value in [('__name__', ext_util.NAME),
+ ('__file__', ext_util.FILEPATH),
 ('__package__', '')]:
 self.assertEqual(getattr(module, attr), value)
- self.assert_(test_path_hook.NAME in sys.modules)
+ self.assert_(ext_util.NAME in sys.modules)
 
 def test_package(self):
 # Extensions are not found in packages.
@@ -35,9 +34,9 @@
 pass
 
 def test_module_reuse(self):
- with util.uncache(test_path_hook.NAME):
- module1 = self.load_module(test_path_hook.NAME)
- module2 = self.load_module(test_path_hook.NAME)
+ with util.uncache(ext_util.NAME):
+ module1 = self.load_module(ext_util.NAME)
+ module2 = self.load_module(ext_util.NAME)
 self.assert_(module1 is module2)
 
 def test_state_after_failure(self):
Modified: python/branches/py3k/Lib/importlib/test/extension/test_path_hook.py
==============================================================================
--- python/branches/py3k/Lib/importlib/test/extension/test_path_hook.py	(original)
+++ python/branches/py3k/Lib/importlib/test/extension/test_path_hook.py	Sat Feb 7 03:06:43 2009
@@ -1,31 +1,12 @@
 import importlib
+from . import util
 
 import collections
 import imp
-from os import path
 import sys
 import unittest
 
 
-PATH = None
-EXT = None
-FILENAME = None
-NAME = '_testcapi'
-_file_exts = [x[0] for x in imp.get_suffixes() if x[2] == imp.C_EXTENSION]
-try:
- for PATH in sys.path:
- for EXT in _file_exts:
- FILENAME = NAME + EXT
- FILEPATH = path.join(PATH, FILENAME)
- if path.exists(path.join(PATH, FILENAME)):
- raise StopIteration
- else:
- PATH = EXT = FILENAME = FILEPATH = None
-except StopIteration:
- pass
-del _file_exts
-
-
 class PathHookTests(unittest.TestCase):
 
 """Test the path hook for extension modules."""
@@ -38,7 +19,7 @@
 def test_success(self):
 # Path hook should handle a directory where a known extension module
 # exists.
- self.assert_(hasattr(self.hook(PATH), 'find_module'))
+ self.assert_(hasattr(self.hook(util.PATH), 'find_module'))
 
 
 def test_main():
Modified: python/branches/py3k/Lib/importlib/test/util.py
==============================================================================
--- python/branches/py3k/Lib/importlib/test/util.py	(original)
+++ python/branches/py3k/Lib/importlib/test/util.py	Sat Feb 7 03:06:43 2009
@@ -2,6 +2,7 @@
 import imp
 import os.path
 from test.support import unlink
+import unittest
 import sys
 
 
@@ -9,7 +10,7 @@
 """Class decorator that nullifies tests that require a case-insensitive
 file system."""
 if sys.platform not in ('win32', 'darwin', 'cygwin'):
- return object()
+ return unittest.TestCase
 else:
 return class_
 


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /