[Python-checkins] r57117 - sandbox/trunk/import_in_py/tests/ext_help.py sandbox/trunk/import_in_py/tests/test_fs_importer.py
brett.cannon
python-checkins at python.org
Fri Aug 17 04:46:14 CEST 2007
Author: brett.cannon
Date: Fri Aug 17 04:46:12 2007
New Revision: 57117
Added:
sandbox/trunk/import_in_py/tests/ext_help.py (contents, props changed)
Modified:
sandbox/trunk/import_in_py/tests/test_fs_importer.py
Log:
Move code out to own module for find an extension module on sys.path.
Added: sandbox/trunk/import_in_py/tests/ext_help.py
==============================================================================
--- (empty file)
+++ sandbox/trunk/import_in_py/tests/ext_help.py Fri Aug 17 04:46:12 2007
@@ -0,0 +1,21 @@
+import imp
+import os
+import sys
+
+
+def find_ext_location(name):
+ possible_suffixes = [suffix[0] for suffix in imp.get_suffixes()
+ if suffix[2] == imp.C_EXTENSION]
+ path_entry = None
+ filename = None
+ try:
+ for path in sys.path:
+ for suffix in possible_suffixes:
+ filename = name + suffix
+ if os.path.exists(os.path.join(path, name + suffix)):
+ path_entry = path
+ raise StopIteration
+ except StopIteration:
+ return (path_entry, filename)
+ else:
+ raise ValueError('%s could not be found on sys.path' % name)
Modified: sandbox/trunk/import_in_py/tests/test_fs_importer.py
==============================================================================
--- sandbox/trunk/import_in_py/tests/test_fs_importer.py (original)
+++ sandbox/trunk/import_in_py/tests/test_fs_importer.py Fri Aug 17 04:46:12 2007
@@ -3,6 +3,7 @@
import importlib
from tests import mock_importlib
+from tests.ext_help import find_ext_location
from tests.py_help import TestPyPycPackages
import imp
@@ -175,26 +176,10 @@
class ExtensionFileImporterTests(unittest.TestCase):
- def find_extension_dir(self, name):
- possible_suffixes = [suffix[0] for suffix in imp.get_suffixes()
- if suffix[2] == imp.C_EXTENSION]
- path_entry = None
- try:
- for path in sys.path:
- for suffix in possible_suffixes:
- if os.path.exists(os.path.join(path, name + suffix)):
- path_entry = path
- raise StopIteration
- except StopIteration:
- return path_entry
- else:
- self.fail("datetime not found")
-
-
def test_basic(self):
# Finding an extension module should work.
search_for = 'datetime'
- extension_dir = self.find_extension_dir(search_for)
+ extension_dir, filename = find_ext_location(search_for)
importer = importlib.ExtensionFileImporter(extension_dir)
importer._loader = lambda x: x
found = importer.find_module(search_for)
More information about the Python-checkins
mailing list