[pypy-svn] r55497 - in pypy/branch/build-external/pypy/module/__builtin__: . test
afa at codespeak.net
afa at codespeak.net
Mon Jun 2 16:00:58 CEST 2008
Author: afa
Date: Mon Jun 2 16:00:55 2008
New Revision: 55497
Modified:
pypy/branch/build-external/pypy/module/__builtin__/importing.py
pypy/branch/build-external/pypy/module/__builtin__/test/test_import.py
Log:
Properly populate sys.path_importer_cache: when a zip file was in front of
sys.path, all remaining entries were filled with the same zipimporter...
Modified: pypy/branch/build-external/pypy/module/__builtin__/importing.py
==============================================================================
--- pypy/branch/build-external/pypy/module/__builtin__/importing.py (original)
+++ pypy/branch/build-external/pypy/module/__builtin__/importing.py Mon Jun 2 16:00:55 2008
@@ -584,8 +584,8 @@
path = sys.path
path_hooks = sys.path_hooks
importer_cache = sys.path_importer_cache
- importer = None
for p in path:
+ importer = None
if importer_cache.get(p,None):
importer = importer_cache.get(p)
else:
Modified: pypy/branch/build-external/pypy/module/__builtin__/test/test_import.py
==============================================================================
--- pypy/branch/build-external/pypy/module/__builtin__/test/test_import.py (original)
+++ pypy/branch/build-external/pypy/module/__builtin__/test/test_import.py Mon Jun 2 16:00:55 2008
@@ -533,6 +533,31 @@
sys.meta_path.append(Importer())
import datetime
assert len(tried_imports) == 1
- tried_imports[0][0] == "datetime"
+ assert tried_imports[0][0] == "datetime"
finally:
sys.meta_path.pop()
+
+ def test_importer_cache(self):
+ class FooImporter(object):
+ def __init__(self, name):
+ if not name.startswith("foo_"):
+ raise ImportError
+ def find_module(self, fullname, path=None):
+ return None
+
+ import sys
+ sys.path_hooks.append(FooImporter)
+ sys.path.insert(0, "foo_something")
+ try:
+ import datetime
+ finally:
+ sys.path_hooks.pop()
+ sys.path.pop(0)
+
+ cache = sys.path_importer_cache
+ assert isinstance(cache['foo_something'], FooImporter)
+ for path, importer in sys.path_importer_cache.items():
+ if path == 'foo_something':
+ assert isinstance(importer, FooImporter)
+ else:
+ assert importer is None
More information about the Pypy-commit
mailing list