summaryrefslogtreecommitdiff
path: root/Lib/test/test_iter.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2006-08-24 19:48:10 +0000
committerGuido van Rossum <guido@python.org>2006-08-24 19:48:10 +0000
commit801f0d78b5582a325d489831b991adb873067e80 (patch)
tree4a5bde7b1386ea73ca0161ffb205911459fff63c /Lib/test/test_iter.py
parentd38abe94841194e3c92bfa2cfb89df36c82607a1 (diff)
downloadcpython-git-801f0d78b5582a325d489831b991adb873067e80.tar.gz
Make built-in zip() equal to itertools.izip().
I mea, *really* equal -- for now, the implementation just imports itertools. :-) The only other changes necessary were various unit tests that were assuming zip() returns a real list. No "real" code made this assumption.
Diffstat (limited to 'Lib/test/test_iter.py')
-rw-r--r--Lib/test/test_iter.py29
1 files changed, 16 insertions, 13 deletions
diff --git a/Lib/test/test_iter.py b/Lib/test/test_iter.py
index 81be7e1699..0ac34c8220 100644
--- a/Lib/test/test_iter.py
+++ b/Lib/test/test_iter.py
@@ -423,21 +423,21 @@ class TestCase(unittest.TestCase):
# Test zip()'s use of iterators.
def test_builtin_zip(self):
- self.assertEqual(zip(), [])
- self.assertEqual(zip(*[]), [])
- self.assertEqual(zip(*[(1, 2), 'ab']), [(1, 'a'), (2, 'b')])
+ self.assertEqual(list(zip()), [])
+ self.assertEqual(list(zip(*[])), [])
+ self.assertEqual(list(zip(*[(1, 2), 'ab'])), [(1, 'a'), (2, 'b')])
self.assertRaises(TypeError, zip, None)
self.assertRaises(TypeError, zip, range(10), 42)
self.assertRaises(TypeError, zip, range(10), zip)
- self.assertEqual(zip(IteratingSequenceClass(3)),
+ self.assertEqual(list(zip(IteratingSequenceClass(3))),
[(0,), (1,), (2,)])
- self.assertEqual(zip(SequenceClass(3)),
+ self.assertEqual(list(zip(SequenceClass(3))),
[(0,), (1,), (2,)])
d = {"one": 1, "two": 2, "three": 3}
- self.assertEqual(d.items(), zip(d, d.itervalues()))
+ self.assertEqual(d.items(), list(zip(d, d.itervalues())))
# Generate all ints starting at constructor arg.
class IntsFrom:
@@ -459,7 +459,7 @@ class TestCase(unittest.TestCase):
f.close()
f = open(TESTFN, "r")
try:
- self.assertEqual(zip(IntsFrom(0), f, IntsFrom(-100)),
+ self.assertEqual(list(zip(IntsFrom(0), f, IntsFrom(-100))),
[(0, "a\n", -100),
(1, "bbb\n", -99),
(2, "cc\n", -98)])
@@ -470,7 +470,7 @@ class TestCase(unittest.TestCase):
except OSError:
pass
- self.assertEqual(zip(xrange(5)), [(i,) for i in range(5)])
+ self.assertEqual(list(zip(xrange(5))), [(i,) for i in range(5)])
# Classes that lie about their lengths.
class NoGuessLen5:
@@ -487,16 +487,19 @@ class TestCase(unittest.TestCase):
def __len__(self):
return 30
+ def lzip(*args):
+ return list(zip(*args))
+
self.assertEqual(len(Guess3Len5()), 3)
self.assertEqual(len(Guess30Len5()), 30)
- self.assertEqual(zip(NoGuessLen5()), zip(range(5)))
- self.assertEqual(zip(Guess3Len5()), zip(range(5)))
- self.assertEqual(zip(Guess30Len5()), zip(range(5)))
+ self.assertEqual(lzip(NoGuessLen5()), lzip(range(5)))
+ self.assertEqual(lzip(Guess3Len5()), lzip(range(5)))
+ self.assertEqual(lzip(Guess30Len5()), lzip(range(5)))
expected = [(i, i) for i in range(5)]
for x in NoGuessLen5(), Guess3Len5(), Guess30Len5():
for y in NoGuessLen5(), Guess3Len5(), Guess30Len5():
- self.assertEqual(zip(x, y), expected)
+ self.assertEqual(lzip(x, y), expected)
# This test case will be removed if we don't have Unicode
def test_unicode_join_endcase(self):
@@ -861,7 +864,7 @@ class TestCase(unittest.TestCase):
a = range(5)
e = enumerate(a)
b = iter(e)
- self.assertEqual(list(b), zip(range(5), range(5)))
+ self.assertEqual(list(b), list(zip(range(5), range(5))))
self.assertEqual(list(b), [])