[pypy-svn] r76601 - in pypy/trunk: lib-python/modified-2.5.2/test pypy/module/array pypy/module/array/test
hakanardo at codespeak.net
hakanardo at codespeak.net
Thu Aug 12 11:31:57 CEST 2010
Author: hakanardo
Date: Thu Aug 12 11:31:54 2010
New Revision: 76601
Modified:
pypy/trunk/lib-python/modified-2.5.2/test/test_array.py
pypy/trunk/pypy/module/array/interp_array.py
pypy/trunk/pypy/module/array/test/test_array.py
Log:
better add and mul
Modified: pypy/trunk/lib-python/modified-2.5.2/test/test_array.py
==============================================================================
--- pypy/trunk/lib-python/modified-2.5.2/test/test_array.py (original)
+++ pypy/trunk/lib-python/modified-2.5.2/test/test_array.py Thu Aug 12 11:31:54 2010
@@ -269,9 +269,11 @@
)
b = array.array(self.badtypecode())
- self.assertRaises(TypeError, a.__add__, b)
+ #self.assertRaises(TypeError, a.__add__, b)
+ #self.assertRaises(TypeError, a.__add__, "bad")
+ self.assertRaises(TypeError, lambda i, j: i + j, a, b)
+ self.assertRaises(TypeError, lambda i, j: i + j, a, "bad")
- self.assertRaises(TypeError, a.__add__, "bad")
def test_iadd(self):
a = array.array(self.typecode, self.example[::-1])
@@ -284,9 +286,12 @@
)
b = array.array(self.badtypecode())
- self.assertRaises(TypeError, a.__add__, b)
-
- self.assertRaises(TypeError, a.__iadd__, "bad")
+ #self.assertRaises(TypeError, a.__add__, b)
+ #self.assertRaises(TypeError, a.__iadd__, "bad")
+ def f(i, j):
+ i += j
+ self.assertRaises(TypeError, f, a, b)
+ self.assertRaises(TypeError, f, a, "bad")
def test_mul(self):
a = 5*array.array(self.typecode, self.example)
@@ -313,7 +318,8 @@
array.array(self.typecode)
)
- self.assertRaises(TypeError, a.__mul__, "bad")
+ #self.assertRaises(TypeError, a.__mul__, "bad")
+ self.assertRaises(TypeError, lambda i, j: i * j, a, "bad")
def test_imul(self):
a = array.array(self.typecode, self.example)
@@ -342,7 +348,10 @@
a *= -1
self.assertEqual(a, array.array(self.typecode))
- self.assertRaises(TypeError, a.__imul__, "bad")
+ #self.assertRaises(TypeError, a.__imul__, "bad")
+ def f(i, j):
+ i *= j
+ self.assertRaises(TypeError, f, a, "bad")
def test_getitem(self):
a = array.array(self.typecode, self.example)
Modified: pypy/trunk/pypy/module/array/interp_array.py
==============================================================================
--- pypy/trunk/pypy/module/array/interp_array.py (original)
+++ pypy/trunk/pypy/module/array/interp_array.py Thu Aug 12 11:31:54 2010
@@ -475,7 +475,10 @@
return self
def mul__Array_ANY(space, self, w_repeat):
- repeat = space.int_w(w_repeat)
+ try:
+ repeat = space.int_w(w_repeat)
+ except OperationError:
+ return space.w_NotImplemented
a = mytype.w_class(space)
repeat = max(repeat, 0)
a.setlen(self.len * repeat)
@@ -488,7 +491,10 @@
return mul__Array_ANY(space, self, w_repeat)
def inplace_mul__Array_ANY(space, self, w_repeat):
- repeat = space.int_w(w_repeat)
+ try:
+ repeat = space.int_w(w_repeat)
+ except OperationError:
+ return space.w_NotImplemented
oldlen = self.len
repeat = max(repeat, 0)
self.setlen(self.len * repeat)
Modified: pypy/trunk/pypy/module/array/test/test_array.py
==============================================================================
--- pypy/trunk/pypy/module/array/test/test_array.py (original)
+++ pypy/trunk/pypy/module/array/test/test_array.py Thu Aug 12 11:31:54 2010
@@ -593,13 +593,16 @@
raises(TypeError, "a = self.array('i') + 2")
raises(TypeError, "self.array('i') + self.array('b')")
+ a = self.array('i')
+ raises(TypeError, "a += 7")
# Calling __add__ directly raises TypeError in cpython but
# returns NotImplemented in pypy if placed within a
# try: except TypeError: construction.
#
- # raises(TypeError, self.array('i').__add__, (2,))
- # raises(TypeError, self.array('i').__add__, self.array('b'))
+ #raises(TypeError, self.array('i').__add__, (2,))
+ #raises(TypeError, self.array('i').__iadd__, (2,))
+ #raises(TypeError, self.array('i').__add__, self.array('b'))
class addable(object):
def __add__(self, other):
@@ -611,6 +614,10 @@
assert addable() + self.array('i') == 'add'
assert self.array('i') + addable() == 'radd'
+ a = self.array('i')
+ a += addable()
+ assert a == 'radd'
+
a = self.array('i', [1, 2])
assert a * -1 == self.array('i')
b = a
@@ -618,6 +625,24 @@
assert a == self.array('i')
assert b == self.array('i')
+ a = self.array('i')
+ raises(TypeError, "a * 'hi'")
+ raises(TypeError, "'hi' * a")
+
+ class mulable(object):
+ def __mul__(self, other):
+ return "mul"
+
+ def __rmul__(self, other):
+ return "rmul"
+
+ assert mulable() * self.array('i') == 'mul'
+ assert self.array('i') * mulable() == 'rmul'
+
+ a = self.array('i')
+ a *= mulable()
+ assert a == 'rmul'
+
def test_delitem(self):
a = self.array('i', [1, 2, 3])
del a[1]
More information about the Pypy-commit
mailing list