[pypy-commit] pypy py3.5: fixes in tests (running them with -A) and corresponding fixes in the code
arigo
pypy.commits at gmail.com
Tue Dec 13 08:48:03 EST 2016
Author: Armin Rigo <arigo at tunes.org>
Branch: py3.5
Changeset: r89043:dfa609c0bc20
Date: 2016-12-13 14:47 +0100
http://bitbucket.org/pypy/pypy/changeset/dfa609c0bc20/
Log: fixes in tests (running them with -A) and corresponding fixes in the
code
diff --git a/pypy/module/array/interp_array.py b/pypy/module/array/interp_array.py
--- a/pypy/module/array/interp_array.py
+++ b/pypy/module/array/interp_array.py
@@ -292,7 +292,7 @@
def _frombytes(self, space, s):
if len(s) % self.itemsize != 0:
raise oefmt(space.w_ValueError,
- "string length not a multiple of item size")
+ "bytes length not a multiple of item size")
oldlen = self.len
new = len(s) / self.itemsize
if not new:
@@ -316,14 +316,9 @@
raise MemoryError
w_item = space.call_method(w_f, 'read', space.wrap(size))
item = space.bytes_w(w_item)
+ self._frombytes(space, item)
if len(item) < size:
- n = len(item) % self.itemsize
- elems = max(0, len(item) - (len(item) % self.itemsize))
- if n != 0:
- item = item[0:elems]
- self._frombytes(space, item)
raise oefmt(space.w_EOFError, "not enough items in file")
- self._frombytes(space, item)
def descr_tofile(self, space, w_f):
""" tofile(f)
@@ -339,7 +334,7 @@
Extends this array with data from the unicode string ustr.
The array must be a type 'u' array; otherwise a ValueError
- is raised. Use array.fromstring(ustr.decode(...)) to
+ is raised. Use array.frombytes(ustr.encode(...)) to
append Unicode data to an array of some other type.
"""
# XXX the following probable bug is not emulated:
@@ -358,7 +353,7 @@
Convert the array to a unicode string. The array must be
a type 'u' array; otherwise a ValueError is raised. Use
- array.tostring().decode() to obtain a unicode string from
+ array.tobytes().decode() to obtain a unicode string from
an array of some other type.
"""
if self.typecode == 'u':
@@ -908,6 +903,11 @@
item = rffi.cast(lltype.Signed, item)
elif mytype.typecode == 'f':
item = float(item)
+ elif mytype.typecode == 'u':
+ if ord(item) >= 0x110000:
+ raise oefmt(space.w_ValueError,
+ "array contains a unicode character out of "
+ "range(0x110000)")
return space.wrap(item)
# interface
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
@@ -222,10 +222,14 @@
a.fromfile(myfile(b'\x01', 20), 2)
assert len(a) == 2 and a[0] == 257 and a[1] == 257
- for i in (0, 1):
- a = self.array('h')
- raises(EOFError, a.fromfile, myfile(b'\x01', 2 + i), 2)
- assert len(a) == 1 and a[0] == 257
+ a = self.array('h')
+ raises(EOFError, a.fromfile, myfile(b'\x01', 2), 2)
+ assert len(a) == 1 and a[0] == 257
+
+ a = self.array('h')
+ raises(ValueError, a.fromfile, myfile(b'\x01', 3), 2)
+ # ValueError: bytes length not a multiple of item size
+ assert len(a) == 0
def test_fromfile_no_warning(self):
import warnings
@@ -454,6 +458,9 @@
assert a.tostring() == b'helLo'
def test_buffer_keepalive(self):
+ import sys
+ if '__pypy__' not in sys.builtin_module_names:
+ skip("CPython: cannot resize an array that is exporting buffers")
buf = memoryview(self.array('b', b'text'))
assert buf[2] == ord('x')
#
@@ -866,7 +873,7 @@
a = self.array('u', u'\x01\u263a\x00\ufeff')
b = self.array('u', u'\x01\u263a\x00\ufeff')
b.byteswap()
- assert a != b
+ raises(ValueError, "a != b")
def test_unicode_ord_positive(self):
import sys
@@ -874,11 +881,7 @@
skip("test for 32-bit unicodes")
a = self.array('u', b'\xff\xff\xff\xff')
assert len(a) == 1
- assert repr(a[0]) == r"'\Uffffffff'"
- if sys.maxsize == 2147483647:
- assert ord(a[0]) == -1
- else:
- assert ord(a[0]) == 4294967295
+ raises(ValueError, "a[0]")
def test_weakref(self):
import weakref
More information about the pypy-commit
mailing list