summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>2000-08-03 15:48:07 (GMT)
committerBarry Warsaw <barry@python.org>2000-08-03 15:48:07 (GMT)
commit7bfc1a15070e90244eeb411db0b8e45e3430dcc6 (patch)
treec22659035eabe771e487a84258725d9a34aedf58 /Lib/test
parentfaefa2a885e83774b180da7281d287a0e2bc75b1 (diff)
downloadcpython-7bfc1a15070e90244eeb411db0b8e45e3430dcc6.zip
cpython-7bfc1a15070e90244eeb411db0b8e45e3430dcc6.tar.gz
cpython-7bfc1a15070e90244eeb411db0b8e45e3430dcc6.tar.bz2
Added testsuite for new zip() builtin.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_b2.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/Lib/test/test_b2.py b/Lib/test/test_b2.py
index 1aff837..84d3454 100644
--- a/Lib/test/test_b2.py
+++ b/Lib/test/test_b2.py
@@ -255,6 +255,42 @@ if tuple(xrange(5,10)) <> tuple(range(5,10)): raise TestFailed, 'xrange(5,10)'
if tuple(xrange(0,10,2)) <> tuple(range(0,10,2)):
raise TestFailed, 'xrange(0,10,2)'
+print 'zip'
+a = (1, 2, 3)
+b = (4, 5, 6)
+t = [(1, 4), (2, 5), (3, 6)]
+if zip(a, b) <> t: raise TestFailed, 'zip(a, b) - same size, both tuples'
+b = [4, 5, 6]
+if zip(a, b) <> t: raise TestFailed, 'zip(a, b) - same size, tuple/list'
+b = (4, 5, 6, 7)
+if zip(a, b) <> t: raise TestFailed, 'zip(a, b) - b is longer'
+class I:
+ def __getitem__(self, i):
+ if i < 0 or i > 2: raise IndexError
+ return i + 4
+if zip(a, I()) <> t: raise TestFailed, 'zip(a, b) - b is instance'
+exc = 0
+try:
+ zip()
+except TypeError:
+ exc = 1
+except:
+ e = sys.exc_info()[0]
+ raise TestFailed, 'zip() - no args, expected TypeError, got', e
+if not exc:
+ raise TestFailed, 'zip() - no args, missing expected TypeError'
+
+exc = 0
+try:
+ zip(None)
+except TypeError:
+ exc = 1
+except:
+ e = sys.exc_info()[0]
+ raise TestFailed, 'zip(None) - expected TypeError, got', e
+if not exc:
+ raise TestFailed, 'zip(None) - missing expected TypeError'
+
# Epilogue -- unlink the temp file