[Python-checkins] r53037 - sandbox/trunk/import_in_py/importer.py sandbox/trunk/import_in_py/test_importer.py
brett.cannon
python-checkins at python.org
Fri Dec 15 01:49:36 CET 2006
Author: brett.cannon
Date: Fri Dec 15 01:49:35 2006
New Revision: 53037
Modified:
sandbox/trunk/import_in_py/importer.py
sandbox/trunk/import_in_py/test_importer.py
Log:
Some doc cleanup.
Modified: sandbox/trunk/import_in_py/importer.py
==============================================================================
--- sandbox/trunk/import_in_py/importer.py (original)
+++ sandbox/trunk/import_in_py/importer.py Fri Dec 15 01:49:35 2006
@@ -26,9 +26,9 @@
* runpy ('-m' command-line option for Python) does not work.
+ Requires get_code to be implemented for loaders.
+ Uses pkgutil.get_loader which fakes a loader if __loader__ is not defined.
- + New loaders do define __loader__ but not get_code, and thus dies on and
+ + New loaders do define __loader__ but not get_code, and thus dies on an
AttributeError.
- + Fix
+ + Possible fix
- Implement optional interface for loaders.
* warnings and stack level.
+ Affected tests
@@ -39,7 +39,7 @@
+ Because import now in Python, import does show up in the call stack.
+ Trick of specifying that going back two levels will cause the warning
to be raised in the caller for an import statement no longer holds true.
- + Fixes
+ + Possible fixes
- Special module deprecation function.
- Code in warnings.warn to handle import case.
- Flag on warnings.warn that warning is for an import and ignore stack
@@ -48,6 +48,7 @@
* test_pkg
+ Old-style test that compares output.
+ Setting of __loader__ leads to different output.
+* PEP 235 not implemented.
"""
from __future__ import with_statement
@@ -105,9 +106,8 @@
"""Base class for meta_path importers for built-in and frozen modules.
- Subclasses must provide the _find and _load methods. Both expect only the
- name of the modules to import. The methods are expected to be defined on
- the subclass itself and not on an instance.
+ Subclasses must provide the _find and _load methods. The methods are
+ expected to be defined on the subclass itself and not on an instance.
"""
@@ -378,6 +378,7 @@
is the idea of opaque code objects which are not directly touched by
the handler but are passed back to the loader so as to allow for a way
to keep state for the loader:
+
* split_path(path)
Take in an opaque path object and split it into a base path and a
string representing the type of the path (which should be in the
@@ -404,7 +405,7 @@
module = self.new_module(mod_name)
sys.modules[mod_name] = module
# __file__, __path__, and __loader__ *must* be set on the module before
- # any code is executed by the import.
+ # any code is executed by the import. __name__ is set by new_module.
module.__loader__ = loader
module.__file__ = path
if package is not None:
Modified: sandbox/trunk/import_in_py/test_importer.py
==============================================================================
--- sandbox/trunk/import_in_py/test_importer.py (original)
+++ sandbox/trunk/import_in_py/test_importer.py Fri Dec 15 01:49:35 2006
@@ -1,4 +1,3 @@
-from __future__ import with_statement
import importer
import unittest
@@ -610,7 +609,28 @@
class PyPycHandlerHandleCodeTests(unittest.TestCase):
- """Test PyPycHandler.handle_code()."""
+ """Test PyPycHandler.handle_code().
+
+ Various situations that must be handled (and thus tested):
+ * Valid .pyc
+ + .py exists [test_good_pyc_w_py]
+ + No .py .
+ * Invalid .pyc
+ + Reasons it is invalid
+ - Bad magic number.
+ * With .py [test_bad_magic_w_py]
+ * Without .py [test_bad_magic_no_py]
+ - .pyc stale based on timestamp.
+ * Requires .py [test_bad_timestamp_w_py]
+ - Bytecode is malformed.
+ * With .py [test_bad_bytecode_w_py]
+ * Without .py [test_bad_bytecode_no_py]
+ * No .pyc
+ + Valid .py
+ - Regenerate .pyc [test_py_w_pyc]
+ - Do not create .pyc [test_py_no_pyc]
+
+ """
def test_good_pyc_w_py(self):
# Test using a .pyc file that is valid and a .py file exists.
@@ -1223,6 +1243,19 @@
* The proper module was returned.
* All expected modules were added to sys.modules.
* All modules imported by the call have the proper attributes.
+
+ There are currently no tests for the import lock.
+
+ Need to test (both relative and absolute imports as needed):
+ * import module
+ * import package
+ * import package.module
+ * from module import attribute
+ * from package import module
+ * from package import attribute
+ * from package.module import attribute
+ * from package import *
+ + With __all__
"""
More information about the Python-checkins
mailing list