[pypy-svn] r56449 - in pypy/dist/pypy/module/itertools: . test
adurdin at codespeak.net
adurdin at codespeak.net
Fri Jul 11 15:21:36 CEST 2008
Author: adurdin
Date: Fri Jul 11 15:21:34 2008
New Revision: 56449
Modified:
pypy/dist/pypy/module/itertools/interp_itertools.py
pypy/dist/pypy/module/itertools/test/test_itertools.py
Log:
(adurdin, jlg) Complying to CPython docs for behaviour with invalid arguments.
Modified: pypy/dist/pypy/module/itertools/interp_itertools.py
==============================================================================
--- pypy/dist/pypy/module/itertools/interp_itertools.py (original)
+++ pypy/dist/pypy/module/itertools/interp_itertools.py Fri Jul 11 15:21:34 2008
@@ -435,6 +435,7 @@
W_Chain.typedef.acceptable_as_base_class = False
class W_IMap(Wrappable):
+ _error_name = "imap"
def __init__(self, space, w_fun, args_w):
self.space = space
@@ -448,7 +449,7 @@
iterator_w = space.iter(iterable_w)
except OperationError, e:
if e.match(self.space, self.space.w_TypeError):
- raise OperationError(space.w_TypeError, space.wrap("imap argument #" + str(i + 1) + " must support iteration"))
+ raise OperationError(space.w_TypeError, space.wrap(self._error_name + " argument #" + str(i + 1) + " must support iteration"))
else:
raise
else:
@@ -511,6 +512,7 @@
class W_IZip(W_IMap):
+ _error_name = "izip"
def __init__(self, space, args_w):
super(W_IZip, self).__init__(space, space.w_None, args_w)
Modified: pypy/dist/pypy/module/itertools/test/test_itertools.py
==============================================================================
--- pypy/dist/pypy/module/itertools/test/test_itertools.py (original)
+++ pypy/dist/pypy/module/itertools/test/test_itertools.py Fri Jul 11 15:21:34 2008
@@ -278,6 +278,8 @@
itertools.chain(*args)
except TypeError, e:
assert str(e) == "chain argument #%d must support iteration" % (x + 1)
+ else:
+ fail("TypeError expected")
def test_imap(self):
import itertools
@@ -309,6 +311,18 @@
assert it.next() == x
raises(StopIteration, it.next)
+ def test_imap_wrongargs(self):
+ import itertools
+
+ # Duplicate python 2.4 behaviour for invalid arguments
+ it = itertools.imap(0)
+ raises(StopIteration, it.next)
+ it = itertools.imap(0, [])
+ raises(StopIteration, it.next)
+ it = itertools.imap(0, [0])
+ raises(TypeError, it.next)
+ raises(TypeError, itertools.imap, None, 0)
+
def test_izip(self):
import itertools
@@ -339,6 +353,21 @@
raises(StopIteration, it.next)
assert it1.next() == 5
+ def test_izip_wrongargs(self):
+ import itertools
+
+ # Duplicate python 2.4 behaviour for invalid arguments
+ raises(TypeError, itertools.izip, None, 0)
+
+ for x in range(10):
+ args = [()] * x + [None] + [()] * (9 - x)
+ try:
+ itertools.izip(*args)
+ except TypeError, e:
+ assert str(e) == "izip argument #%d must support iteration" % (x + 1)
+ else:
+ fail("TypeError expected")
+
def test_docstrings(self):
import itertools
More information about the Pypy-commit
mailing list