Author: Philip Jenvey <[email protected]>
Branch: py3k
Changeset: r71244:051596edf5c1
Date: 2014-05-03 15:01 -0700
http://bitbucket.org/pypy/pypy/changeset/051596edf5c1/

Log:    adapt memoryview related tests to py3

diff --git a/pypy/module/__builtin__/test/test_builtin.py 
b/pypy/module/__builtin__/test/test_builtin.py
--- a/pypy/module/__builtin__/test/test_builtin.py
+++ b/pypy/module/__builtin__/test/test_builtin.py
@@ -487,13 +487,11 @@
     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')
diff --git a/pypy/module/__pypy__/test/test_bytebuffer.py 
b/pypy/module/__pypy__/test/test_bytebuffer.py
--- a/pypy/module/__pypy__/test/test_bytebuffer.py
+++ b/pypy/module/__pypy__/test/test_bytebuffer.py
@@ -12,18 +12,16 @@
         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
diff --git a/pypy/module/_io/test/test_bufferedio.py 
b/pypy/module/_io/test/test_bufferedio.py
--- a/pypy/module/_io/test/test_bufferedio.py
+++ b/pypy/module/_io/test/test_bufferedio.py
@@ -139,12 +139,11 @@
         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()
diff --git a/pypy/module/_io/test/test_bytesio.py 
b/pypy/module/_io/test/test_bytesio.py
--- a/pypy/module/_io/test/test_bytesio.py
+++ b/pypy/module/_io/test/test_bytesio.py
@@ -44,7 +44,7 @@
         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()
@@ -104,12 +104,11 @@
         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()
diff --git a/pypy/module/_io/test/test_fileio.py 
b/pypy/module/_io/test/test_fileio.py
--- a/pypy/module/_io/test/test_fileio.py
+++ b/pypy/module/_io/test/test_fileio.py
@@ -135,12 +135,11 @@
         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()
diff --git a/pypy/module/_socket/test/test_sock_app.py 
b/pypy/module/_socket/test/test_sock_app.py
--- a/pypy/module/_socket/test/test_sock_app.py
+++ b/pypy/module/_socket/test/test_sock_app.py
@@ -540,7 +540,7 @@
         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, '')
diff --git a/pypy/module/array/test/test_array.py 
b/pypy/module/array/test/test_array.py
--- a/pypy/module/array/test/test_array.py
+++ b/pypy/module/array/test/test_array.py
@@ -133,11 +133,12 @@
     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)
diff --git a/pypy/module/marshal/test/test_marshalimpl.py 
b/pypy/module/marshal/test/test_marshalimpl.py
--- a/pypy/module/marshal/test/test_marshalimpl.py
+++ b/pypy/module/marshal/test/test_marshalimpl.py
@@ -25,8 +25,10 @@
         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
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to