[Python-checkins] r56981 - sandbox/trunk/import_in_py/tests/test_fs_importer.py
brett.cannon
python-checkins at python.org
Mon Aug 13 10:01:15 CEST 2007
Author: brett.cannon
Date: Mon Aug 13 10:01:15 2007
New Revision: 56981
Modified:
sandbox/trunk/import_in_py/tests/test_fs_importer.py
Log:
Begin to write tests for PyFileImporter. Using as testing for FileImporter.
Two tests not implemented (and thus currently raise NotImplementedError).
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 Mon Aug 13 10:01:15 2007
@@ -7,6 +7,7 @@
import os
import os.path
+import py_compile
import sys
import tempfile
from test import test_support
@@ -14,6 +15,80 @@
import warnings
+class MockFileImporter(importlib.FileImporter):
+
+ # Identity function.
+ _loader = lambda x: x
+
+ def __init__(self, ext=['.test'], pkg=False, path_entry=os.getcwd()):
+ self._file_types = ext
+ self._possible_package = pkg
+ super(self.__class__, self).__init__(path_entry)
+
+
+class PyFileImporterTests(TestPyPycPackages):
+
+ """Test the PyFileImporterTests.
+
+ No need to check for searching any deeper than a package (e.g., don't need
+ to look for a sub-module or sub-package) since the import machinery will
+ always have an importer for the containing package directory.
+
+ """
+
+ def setUp(self):
+ TestPyPycPackages.setUp(self, faked_names=False)
+ self.importer = importlib.PyFileImporter(self.directory)
+ self.importer._loader = lambda x: x
+
+ def tearDown(self):
+ TestPyPycPackages.tearDown(self)
+
+ def test_py_top_level(self):
+ # A top-level source module should work.
+ test_support.unlink(self.pyc_path)
+ found = self.importer.find_module(self.module_name)
+ self.assertEqual(found, self.py_path)
+
+ def test_pyc_top_level(self):
+ # A top-level bytecode module should work.
+ test_support.unlink(self.py_path)
+ found = self.importer.find_module(self.module_name)
+ self.assertEqual(found, self.pyc_path)
+
+ def test_py_package(self):
+ # A Python source package should be found.
+ # TestPyPycPackages, by default, does not compile the __init__ file.
+ if self.pkg_init_path[-1] not in ('c', 'o'):
+ assert not os.path.exists(self.pkg_init_path + 'c')
+ assert not os.path.exists(self.pkg_init_path + 'o')
+ else:
+ assert False
+ found = self.importer.find_module(self.pkg_name)
+ self.assertEqual(found, self.pkg_init_path)
+
+ def test_pyc_package(self):
+ # A bytecode package should be found.
+ py_compile.compile(self.pkg_init_path)
+ test_support.unlink(self.pkg_init_path)
+ expected = self.pkg_init_path + ('c' if __debug__ else 'o')
+ found = self.importer.find_module(self.pkg_name)
+ self.assertEqual(found, expected)
+
+ def test_file_type_order(self):
+ # The order of the search should be preserved.
+ raise NotImplementedError
+
+ def test_missing__init__warning(self):
+ # An ImportWarning should be raised if a directory matches a module
+ # name but no __init__ file exists.
+ raise NotImplementedError
+
+
+
+
+
+
class FileSystemFactoryTests(unittest.TestCase):
"""Test the filesystem path_hooks factory function."""
@@ -304,9 +379,9 @@
def test_main():
- test_support.run_unittest(FileSystemFactoryTests, FileSystemImporterTests,
- FileSystemLoaderBlackBoxTests, FileSystemLoaderWhiteBoxTests)
-
+ test_support.run_unittest(PyFileImporterTests)
+ #test_support.run_unittest(FileSystemFactoryTests, FileSystemImporterTests,
+ # FileSystemLoaderBlackBoxTests, FileSystemLoaderWhiteBoxTests)
if __name__ == '__main__':
More information about the Python-checkins
mailing list