Commits

Philip Jenvey committed 051596e

adapt memoryview related tests to py3

  • Participants
  • Parent commits 9b567d9
  • Branches py3k

Comments (0)

Files changed (8)

File pypy/module/__builtin__/test/test_builtin.py

     def test_compile(self):
         co = compile('1+2', '?', 'eval')
         assert eval(co) == 3
-        co = compile(buffer('1+2'), '?', 'eval')
+        co = compile(memoryview(b'1+2'), '?', 'eval')
         assert eval(co) == 3
         exc = raises(TypeError, compile, chr(0), '?', 'eval')
         assert str(exc.value) == "compile() expected string without null bytes"
-        exc = raises(TypeError, compile, unichr(0), '?', 'eval')
-        assert str(exc.value) == "compile() expected string without null bytes"
-        exc = raises(TypeError, compile, memoryview('1+2'), '?', 'eval')
+        exc = raises(TypeError, compile, memoryview(b'1+2'), '?', 'eval')
         assert str(exc.value) == "expected a readable buffer object"
         compile("from __future__ import with_statement", "<test>", "exec")
         raises(SyntaxError, compile, '-', '?', 'eval')

File pypy/module/__pypy__/test/test_bytebuffer.py

         assert b[-1] == b'*'
         assert b[-2] == b'-'
         assert b[-3] == b'+'
-        exc = raises(TypeError, "b[3] = b'abc'")
-        assert str(exc.value) == "right operand must be a single byte"
-        exc = raises(TypeError, "b[3:5] = b'abc'")
-        assert str(exc.value) == "right operand length must match slice length"
-        exc = raises(TypeError, "b[3:7:2] = b'abc'")
-        assert str(exc.value) == "right operand length must match slice length"
+        exc = raises(ValueError, "b[3] = b'abc'")
+        assert str(exc.value) == "cannot modify size of memoryview object"
+        exc = raises(ValueError, "b[3:5] = b'abc'")
+        assert str(exc.value) == "cannot modify size of memoryview object"
+        raises(NotImplementedError, "b[3:7:2] = b'abc'")
 
         b = bytebuffer(10)
         b[1:3] = b'xy'
         assert bytes(b) == b"\x00xy" + b"\x00" * 7
-        b[4:8:2] = b'zw'
-        assert bytes(b) == b"\x00xy\x00z\x00w" + b"\x00" * 3
-        r = str(buffer(u'#'))
-        b[6:6+len(r)] = u'#'
-        assert str(b[:6+len(r)]) == "\x00xy\x00z\x00" + r
+        # XXX: supported in 3.3
+        raises(NotImplementedError, "b[4:8:2] = b'zw'")
+        #b[4:8:2] = b'zw'
+        #assert bytes(b) == b"\x00xy\x00z\x00w" + b"\x00" * 3

File pypy/module/_io/test/test_bufferedio.py

         raw = _io.FileIO(self.tmpfile)
         f = _io.BufferedReader(raw)
         assert f.readinto(a) == 5
+        f.seek(0)
+        m = memoryview(bytearray(b"hello"))
+        assert f.readinto(m) == 5
         exc = raises(TypeError, f.readinto, u"hello")
-        assert str(exc.value) == "cannot use unicode as modifiable buffer"
-        exc = raises(TypeError, f.readinto, buffer(b"hello"))
-        assert str(exc.value) == "must be read-write buffer, not buffer"
-        exc = raises(TypeError, f.readinto, buffer(bytearray("hello")))
-        assert str(exc.value) == "must be read-write buffer, not buffer"
+        assert str(exc.value) == "must be read-write buffer, not str"
         exc = raises(TypeError, f.readinto, memoryview(b"hello"))
         assert str(exc.value) == "must be read-write buffer, not memoryview"
         f.close()

File pypy/module/_io/test/test_bytesio.py

         assert f.write(b"") == 0
         assert f.write(b"hello") == 5
         exc = raises(TypeError, f.write, u"lo")
-        assert str(exc.value) == "'unicode' does not have the buffer interface"
+        assert str(exc.value) == "'str' does not have the buffer interface"
         import gc; gc.collect()
         assert f.getvalue() == b"hello"
         f.close()
         a2 = bytearray(b'testing')
         assert b.readinto(a1) == 1
         assert b.readinto(a2) == 4
+        b.seek(0)
+        m = memoryview(bytearray(b"world"))
+        assert b.readinto(m) == 5
         exc = raises(TypeError, b.readinto, u"hello")
-        assert str(exc.value) == "cannot use unicode as modifiable buffer"
-        exc = raises(TypeError, b.readinto, buffer(b"hello"))
-        assert str(exc.value) == "must be read-write buffer, not buffer"
-        exc = raises(TypeError, b.readinto, buffer(bytearray("hello")))
-        assert str(exc.value) == "must be read-write buffer, not buffer"
+        assert str(exc.value) == "must be read-write buffer, not str"
         exc = raises(TypeError, b.readinto, memoryview(b"hello"))
         assert str(exc.value) == "must be read-write buffer, not memoryview"
         b.close()

File pypy/module/_io/test/test_fileio.py

         a = bytearray(b'x' * 10)
         f = _io.FileIO(self.tmpfile, 'r+')
         assert f.readinto(a) == 10
+        f.seek(0)
+        m = memoryview(bytearray(b"helloworld"))
+        assert f.readinto(m) == 10
         exc = raises(TypeError, f.readinto, u"hello")
-        assert str(exc.value) == "cannot use unicode as modifiable buffer"
-        exc = raises(TypeError, f.readinto, buffer(b"hello"))
-        assert str(exc.value) == "must be read-write buffer, not buffer"
-        exc = raises(TypeError, f.readinto, buffer(bytearray("hello")))
-        assert str(exc.value) == "must be read-write buffer, not buffer"
+        assert str(exc.value) == "must be read-write buffer, not str"
         exc = raises(TypeError, f.readinto, memoryview(b"hello"))
         assert str(exc.value) == "must be read-write buffer, not memoryview"
         f.close()

File pypy/module/_socket/test/test_sock_app.py

         except _socket.gaierror as ex:
             skip("GAIError - probably no connection: %s" % str(ex.args))
         exc = raises(TypeError, s.send, None)
-        assert str(exc.value) == "must be string or buffer, not None"
+        assert str(exc.value) == "'NoneType' does not support the buffer interface"
         assert s.send(memoryview(b'')) == 0
         assert s.sendall(memoryview(b'')) is None
         exc = raises(TypeError, s.send, '')

File pypy/module/array/test/test_array.py

     def test_fromstring(self):
         a = self.array('b')
         a.fromstring('Hi!')
-        assert a[0] == b'H' and a[1] == b'i' and a[2] == b'!' and len(a) == 3
+        assert len(a) == 3
+        assert a[0] == ord(b'H') and a[1] == ord(b'i') and a[2] == ord(b'!')
         a = self.array('b')
-        exc = raises(TypeError, a.fromstring, memoryview(b'xyz'))
-        assert str(exc.value) == "must be string or read-only buffer, not memoryview"
-        assert a[0] == b'x' and a[1] == b'y' and a[2] == b'z' and len(a) == 3
+        a.fromstring(memoryview(b'xyz'))
+        assert len(a) == 3
+        assert a[0] == ord(b'x') and a[1] == ord(b'y') and a[2] == ord(b'z')
         a = self.array('b')
         a.fromstring('')
         assert not len(a)

File pypy/module/marshal/test/test_marshalimpl.py

         s = marshal.dumps(array.array('b', b'asd'))
         t = marshal.loads(s)
         assert type(t) is bytes and t == b'asd'
-        exc = raises(ValueError, marshal.dumps, memoryview(b'asd'))
-        assert str(exc.value) == "unmarshallable object"
+
+        s = marshal.dumps(memoryview(b'asd'))
+        t = marshal.loads(s)
+        assert type(t) is bytes and t == b'asd'
 
     def test_unmarshal_evil_long(self):
         import marshal