[pypy-svn] r55273 - in pypy/dist/pypy/module/zipimport: . test

fijal at codespeak.net fijal at codespeak.net
Mon May 26 20:04:26 CEST 2008


Author: fijal
Date: Mon May 26 20:04:23 2008
New Revision: 55273

Modified:
   pypy/dist/pypy/module/zipimport/interp_zipimport.py
   pypy/dist/pypy/module/zipimport/test/test_zipimport.py
Log:
The problem with TDD is that you need to know what are you testing first,
apparently get_data can receive an absolute path.


Modified: pypy/dist/pypy/module/zipimport/interp_zipimport.py
==============================================================================
--- pypy/dist/pypy/module/zipimport/interp_zipimport.py	(original)
+++ pypy/dist/pypy/module/zipimport/interp_zipimport.py	Mon May 26 20:04:23 2008
@@ -131,6 +131,15 @@
     def getprefix(space, self):
         return space.wrap(self.prefix)
 
+    def _find_relative_path(self, filename):
+        if filename.startswith(self.dir.filename):
+            filename = filename[len(self.dir.filename):]
+        if filename.startswith(os.sep):
+            filename = filename[1:]
+        if ZIPSEP != os.path.sep:
+            filename = filename.replace(os.path.sep, ZIPSEP)
+        return filename
+
     def import_py_file(self, space, modname, filename, buf, pkgpath):
         w = space.wrap
         w_mod = w(Module(space, w(modname)))
@@ -248,8 +257,7 @@
     load_module.unwrap_spec = ['self', ObjSpace, str]
 
     def get_data(self, space, filename):
-        if ZIPSEP != os.path.sep:
-            filename = filename.replace(os.path.sep, ZIPSEP)
+        filename = self._find_relative_path(filename)
         w = space.wrap
         try:
             return w(self.dir.read(filename))

Modified: pypy/dist/pypy/module/zipimport/test/test_zipimport.py
==============================================================================
--- pypy/dist/pypy/module/zipimport/test/test_zipimport.py	(original)
+++ pypy/dist/pypy/module/zipimport/test/test_zipimport.py	Mon May 26 20:04:23 2008
@@ -203,7 +203,7 @@
         self.writefile(self, "yy.py", "3")
         self.writefile(self, 'uu.pyc', self.test_pyc)
         z = zipimport.zipimporter(self.zipfile)
-        assert z.get_data("xxx") == data
+        assert z.get_data(self.zipfile + os.sep + "xxx") == data
         assert z.is_package("xx")
         assert not z.is_package("yy")
         assert z.get_source("yy") == '3'



More information about the Pypy-commit mailing list