1. Pypy
  2. Untitled project
  3. pypy

Commits

Amaury Forgeot d'Arc  committed 49725b8

Fix mmap tests

  • Participants
  • Parent commits c3ca88e
  • Branches py3k

Comments (0)

Files changed (2)

File pypy/module/mmap/interp_mmap.py

View file
  • Ignore whitespace
         if step == 0:  # index only
             return space.wrap(ord(self.mmap.getitem(start)))
         elif step == 1:
-            return space.wrap(self.mmap.getslice(start, stop - start))
+            return space.wrapbytes(self.mmap.getslice(start, stop - start))
         else:
             res = "".join([self.mmap.getitem(i)
                            for i in range(start, stop, step)])

File pypy/module/mmap/test/test_mmap.py

View file
  • Ignore whitespace
 
         f.seek(0)
         m = mmap(f.fileno(), 6)
-        assert m[-3:7] == b"bar"
+        assert eval('m[-3:7]') == b"bar"
 
         f.close()
 
 
     def test_buffer_write(self):
         from mmap import mmap
-        f = open(self.tmpname + "y", "w+")
-        f.write("foobar")
+        f = open(self.tmpname + "y", "wb+")
+        f.write(b"foobar")
         f.flush()
         m = mmap(f.fileno(), 6)
-        m[5] = '?'
-        b = buffer(m)
-        try:
-            b[:3] = "FOO"
-        except TypeError:     # on CPython: "buffer is read-only" :-/
-            skip("on CPython: buffer is read-only")
+        m[5] = ord('?')
+        b = memoryview(m)
+        b[:3] = b"FOO"
+        del b  # For CPython: "cannot close exported pointers exist"
         m.close()
         f.seek(0)
         got = f.read()
-        assert got == "FOOba?"
+        assert got == b"FOOba?"
         f.close()
 
     def test_offset(self):