[Python-checkins] r57080 - sandbox/trunk/import_in_py/tests/test_fs_importer.py
brett.cannon
python-checkins at python.org
Thu Aug 16 04:25:39 CEST 2007
Author: brett.cannon
Date: Thu Aug 16 04:25:39 2007
New Revision: 57080
Modified:
sandbox/trunk/import_in_py/tests/test_fs_importer.py
Log:
Add test for ExtensionFileImporter.
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 Thu Aug 16 04:25:39 2007
@@ -5,6 +5,7 @@
from tests import mock_importlib
from tests.py_help import TestPyPycPackages
+import imp
import os
import os.path
import py_compile
@@ -172,12 +173,34 @@
self.failUnless(self.importer.find_module(self.pkg_name))
-
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.
- raise NotImplementedError
+ search_for = 'datetime'
+ extension_dir = self.find_extension_dir(search_for)
+ importer = importlib.ExtensionFileImporter(extension_dir)
+ importer._loader = lambda x: x
+ found = importer.find_module(search_for)
+ self.assert_(found is not None)
+ self.assert_(search_for in found)
+
More information about the Python-checkins
mailing list