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

arigo at codespeak.net arigo at codespeak.net
Wed Aug 24 15:35:45 CEST 2005


Author: arigo
Date: Wed Aug 24 15:35:44 2005
New Revision: 16383

Modified:
   pypy/dist/pypy/module/__builtin__/importing.py
   pypy/dist/pypy/module/__builtin__/test/test_import.py
Log:
* don't crash when there are empty .pyc files around.  Added test.

* re-enabled the .pyc file tests -- pyc file support was re-enabled some time
  ago already.


Modified: pypy/dist/pypy/module/__builtin__/importing.py
==============================================================================
--- pypy/dist/pypy/module/__builtin__/importing.py	(original)
+++ pypy/dist/pypy/module/__builtin__/importing.py	Wed Aug 24 15:35:44 2005
@@ -378,10 +378,13 @@
 # difficulties of using it though applevel.
 _r_correction = intmask(1L<<32)    # == 0 on 32-bit machines
 def _r_long(osfile):
-    a = ord(osfile.read(1))
-    b = ord(osfile.read(1))
-    c = ord(osfile.read(1))
-    d = ord(osfile.read(1))
+    s = osfile.read(4)
+    if len(s) < 4:
+        return -1   # good enough for our purposes
+    a = ord(s[0])
+    b = ord(s[1])
+    c = ord(s[2])
+    d = ord(s[3])
     x = a | (b<<8) | (c<<16) | (d<<24)
     if _r_correction and d & 0x80 and x > 0:
         x -= _r_correction

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	Wed Aug 24 15:35:44 2005
@@ -196,7 +196,6 @@
     # ___________________ .pyc related stuff _________________
 
     def test_check_compiled_module(self):
-        py.test.skip('pyc file support disabled for now')
         space = self.space
         pathname = "whatever"
         mtime = 12345
@@ -222,10 +221,18 @@
                                               mtime,
                                               cpathname)
         assert ret == -1
+
+        # check for empty .pyc file
+        f = open(cpathname, 'wb')
+        f.close()
+        ret = importing.check_compiled_module(space,
+                                              pathname,
+                                              mtime,
+                                              cpathname)
+        assert ret == -1
         os.remove(cpathname)
 
     def test_read_compiled_module(self):
-        py.test.skip('pyc file support disabled for now')
         space = self.space
         pathname = "whatever"
         mtime = 12345
@@ -244,7 +251,6 @@
         assert ret == 42
 
     def test_load_compiled_module(self):
-        py.test.skip('pyc file support disabled for now')
         space = self.space
         pathname = "whatever"
         mtime = 12345
@@ -316,7 +322,6 @@
         #XXX Note tested while no writing
 
     def test_write_compiled_module(self):
-        py.test.skip('pyc file support disabled for now')
         space = self.space
         pathname = _testfilesource()
         fd = os.open(pathname, importing.BIN_READMASK, 0777)



More information about the Pypy-commit mailing list