summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2000-12-12 22:02:59 (GMT)
committerGuido van Rossum <guido@python.org>2000-12-12 22:02:59 (GMT)
commitb822c6138ec1e9c9f76e0320f03df54e4fef2e64 (patch)
tree9ebe38334c60b392e4a6b46dae049b441deea611 /Lib
parentba6ab84e73bd5808cc9a4ed1ab58c752af6eef04 (diff)
downloadcpython-b822c6138ec1e9c9f76e0320f03df54e4fef2e64.zip
cpython-b822c6138ec1e9c9f76e0320f03df54e4fef2e64.tar.gz
cpython-b822c6138ec1e9c9f76e0320f03df54e4fef2e64.tar.bz2
Added test for {}.popitem().
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_types.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_types.py b/Lib/test/test_types.py
index eec9e2d..cf4f6b4 100644
--- a/Lib/test/test_types.py
+++ b/Lib/test/test_types.py
@@ -265,3 +265,27 @@ if d['key'][0] <> 3:
d.setdefault('key', []).append(4)
if len(d['key']) <> 2:
raise TestFailed, 'present {} setdefault, w/ 2nd arg'
+# dict.popitem()
+for copymode in -1, +1:
+ # -1: b has same structure as a
+ # +1: b is a.copy()
+ for log2size in range(12):
+ size = 2**log2size
+ a = {}
+ b = {}
+ for i in range(size):
+ a[`i`] = i
+ if copymode < 0:
+ b[`i`] = i
+ if copymode > 0:
+ b = a.copy()
+ for i in range(size):
+ ka, va = ta = a.popitem()
+ if va != int(ka): raise TestFailed, "a.popitem: %s" % str(ta)
+ kb, vb = tb = b.popitem()
+ if vb != int(kb): raise TestFailed, "b.popitem: %s" % str(tb)
+ if copymode < 0 and ta != tb:
+ raise TestFailed, "a.popitem != b.popitem: %s, %s" % (
+ str(ta), str(tb))
+ if a: raise TestFailed, 'a not empty after popitems: %s' % str(a)
+ if b: raise TestFailed, 'b not empty after popitems: %s' % str(b)