[pypy-svn] r57513 - in pypy/dist/pypy/module/itertools: . test

arigo at codespeak.net arigo at codespeak.net
Wed Aug 20 16:21:04 CEST 2008


Author: arigo
Date: Wed Aug 20 16:21:04 2008
New Revision: 57513

Modified:
   pypy/dist/pypy/module/itertools/interp_itertools.py
   pypy/dist/pypy/module/itertools/test/errors.txt
   pypy/dist/pypy/module/itertools/test/test_itertools.py
Log:
Test and fix: imap() with no iterables should raise TypeError.


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	Wed Aug 20 16:21:04 2008
@@ -443,6 +443,10 @@
         self.identity_fun = (self.space.is_w(w_fun, space.w_None))
         self.w_fun = w_fun
 
+        if len(args_w) == 0:
+            raise OperationError(space.w_TypeError,
+                      space.wrap("imap() must have at least two arguments"))
+
         iterators_w = []
         i = 0
         for iterable_w in args_w:
@@ -464,16 +468,7 @@
         return self.space.wrap(self)
 
     def next_w(self):
-        if not self.iterators_w:
-            raise OperationError(self.space.w_StopIteration, self.space.w_None)
-
-        try:
-            w_objects = self.space.newtuple([self.space.next(w_it) for w_it in self.iterators_w])
-        except OperationError, e:
-            if e.match(self.space, self.space.w_StopIteration):
-                self.iterators_w = None
-            raise
-
+        w_objects = self.space.newtuple([self.space.next(w_it) for w_it in self.iterators_w])
         if self.identity_fun:
             return w_objects
         else:

Modified: pypy/dist/pypy/module/itertools/test/errors.txt
==============================================================================
--- pypy/dist/pypy/module/itertools/test/errors.txt	(original)
+++ pypy/dist/pypy/module/itertools/test/errors.txt	Wed Aug 20 16:21:04 2008
@@ -38,14 +38,6 @@
 AssertionError: '<count object at 0x08fcdcac>' != 'count(3)'
 
 ======================================================================
-FAIL: test_imap (__main__.TestBasicOps)
-----------------------------------------------------------------------
-Traceback (most recent call last):
-  File "itest25.py", line 231, in test_imap
-    self.assertRaises(TypeError, imap, operator.neg)
-AssertionError: TypeError not raised
-
-======================================================================
 FAIL: test_izip (__main__.TestBasicOps)
 ----------------------------------------------------------------------
 Traceback (most recent call last):

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	Wed Aug 20 16:21:04 2008
@@ -267,10 +267,6 @@
     def test_imap(self):
         import itertools
 
-        #---does not work in CPython 2.5
-        #it = itertools.imap(None)
-        #raises(StopIteration, it.next)
-
         obj_list = [object(), object(), object()]
         it = itertools.imap(None, obj_list)
         for x in obj_list:
@@ -305,6 +301,10 @@
         raises(TypeError, it.next)
         raises(TypeError, itertools.imap, None, 0)
 
+        raises(TypeError, itertools.imap, None)
+        raises(TypeError, itertools.imap, bool)
+        raises(TypeError, itertools.imap, 42)
+
     def test_izip(self):
         import itertools
 



More information about the Pypy-commit mailing list