]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Barry's patch to test the new setdefault() method.
authorGuido van Rossum <guido@python.org>
Tue, 8 Aug 2000 16:13:23 +0000 (16:13 +0000)
committerGuido van Rossum <guido@python.org>
Tue, 8 Aug 2000 16:13:23 +0000 (16:13 +0000)
Lib/test/test_types.py

index e22b0e2356e1bdd43b9f1c1e65f56c35a43b139d..e3a51f090abccd447c842d55687725d493957cb3 100644 (file)
@@ -253,3 +253,15 @@ if d.get('c') != None: raise TestFailed, 'missing dict get, no 2nd arg'
 if d.get('c', 3) != 3: raise TestFailed, 'missing dict get, w/ 2nd arg'
 if d.get('a') != 1: raise TestFailed, 'present dict get, no 2nd arg'
 if d.get('a', 3) != 1: raise TestFailed, 'present dict get, w/ 2nd arg'
+# dict.setdefault()
+d = {}
+if d.setdefault('key0') <> None:
+       raise TestFailed, 'missing {} setdefault, no 2nd arg'
+if d.setdefault('key0') <> None:
+       raise TestFailed, 'present {} setdefault, no 2nd arg'
+d.setdefault('key', []).append(3)
+if d['key'][0] <> 3:
+       raise TestFailed, 'missing {} setdefault, w/ 2nd arg'
+d.setdefault('key', []).append(4)
+if len(d['key']) <> 2:
+       raise TestFailed, 'present {} setdefault, w/ 2nd arg'