[Python-checkins] r52554 - sandbox/trunk/import_in_py/mock_importer.py

brett.cannon python-checkins at python.org
Mon Oct 30 03:41:40 CET 2006


Author: brett.cannon
Date: Mon Oct 30 03:41:39 2006
New Revision: 52554

Modified:
   sandbox/trunk/import_in_py/mock_importer.py
Log:
Add asserts for __name__, __file__, and __loader__ when verifying that a module
is correct.


Modified: sandbox/trunk/import_in_py/mock_importer.py
==============================================================================
--- sandbox/trunk/import_in_py/mock_importer.py	(original)
+++ sandbox/trunk/import_in_py/mock_importer.py	Mon Oct 30 03:41:39 2006
@@ -65,11 +65,18 @@
         return handler.handle_code(self, self.module_name,
                                     (self.base_path, self.pyc_ext))
         
-    def _verify_module(self, module):
+    def _verify_module(self, module, test_metadata=True):
         if not hasattr(module, 'test_attr'):
             raise test_support.TestFailed("test_attr attribute missing")
         if not module.test_attr is None:
             raise test_support.TestFailed("test_attr not set to None")
+        if test_metadata:
+            assert module.__name__ == self.module_name
+            assert module.__loader__ == self
+            assert self.base_path in module.__file__
+            assert (self.pyc_ext in module.__file__ or
+                    self.py_ext in module.__file__)
+
         return True
             
     def load_module(self, fullname, path=None):
@@ -128,7 +135,7 @@
         module = imp.new_module(self.module_name)
         code = marshal.loads(data[8:])
         exec code in module.__dict__
-        assert self._verify_module(module)
+        assert self._verify_module(module, False)
         
         return None
 
@@ -190,4 +197,4 @@
         sys.path.append(succeed_entry)
         ins = cls()
         sys.path_importer_cache[succeed_entry] = ins
-        return ins
\ No newline at end of file
+        return ins


More information about the Python-checkins mailing list