[pypy-svn] r48331 - in pypy/dist/pypy/module/__builtin__: . test

cfbolz at codespeak.net cfbolz at codespeak.net
Tue Nov 6 11:04:16 CET 2007


Author: cfbolz
Date: Tue Nov  6 11:04:15 2007
New Revision: 48331

Modified:
   pypy/dist/pypy/module/__builtin__/importing.py
   pypy/dist/pypy/module/__builtin__/test/test_import.py
Log:
a (passing) test for the meta_path hook. clean up indentation in one piece of
importing code.


Modified: pypy/dist/pypy/module/__builtin__/importing.py
==============================================================================
--- pypy/dist/pypy/module/__builtin__/importing.py	(original)
+++ pypy/dist/pypy/module/__builtin__/importing.py	Tue Nov  6 11:04:15 2007
@@ -606,15 +606,15 @@
     import sys
     meta_path = sys.meta_path
     for hook in meta_path:
-                loader = hook.find_module(fullname,  path)
-                if loader:
-                        return loader
+        loader = hook.find_module(fullname,  path)
+        if loader:
+            return loader
     if path != None and type(path) == str:
-       pass
-       # XXX Check for frozen modules ?
+        pass
+        # XXX Check for frozen modules ?
     if path == None:
-       # XXX Check frozen
-       path = sys.path
+        # XXX Check frozen
+        path = sys.path
     path_hooks = sys.path_hooks
     importer_cache = sys.path_importer_cache 
     importer = None

Modified: pypy/dist/pypy/module/__builtin__/test/test_import.py
==============================================================================
--- pypy/dist/pypy/module/__builtin__/test/test_import.py	(original)
+++ pypy/dist/pypy/module/__builtin__/test/test_import.py	Tue Nov  6 11:04:15 2007
@@ -520,3 +520,19 @@
     finally: 
         if old: 
             os.environ['PYTHONPATH'] = old 
+
+class AppTestImportHooks(object):
+    def test_meta_path(self):
+        tried_imports = []
+        class Importer(object):
+            def find_module(self, fullname, path=None):
+                tried_imports.append((fullname, path))
+
+        import sys
+        try:
+            sys.meta_path.append(Importer())
+            import datetime
+            assert len(tried_imports) == 1
+            tried_imports[0][0] == "datetime"
+        finally:
+            sys.meta_path.pop()



More information about the Pypy-commit mailing list