summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_userdict.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2002-11-27 08:29:11 (GMT)
committerRaymond Hettinger <python@rcn.com>2002-11-27 08:29:11 (GMT)
commite4827eb2a2c9eed8911a6874866a224972ff40ab (patch)
tree5195b5c1ede95d2a8251247a4a52598aaa7ec510 /Lib/test/test_userdict.py
parente33d3df03079d704edbe159be079dc387058f044 (diff)
downloadcpython-e4827eb2a2c9eed8911a6874866a224972ff40ab.zip
cpython-e4827eb2a2c9eed8911a6874866a224972ff40ab.tar.gz
cpython-e4827eb2a2c9eed8911a6874866a224972ff40ab.tar.bz2
Bring UserDict in-sync with changes to dict.
Constructor accepts optional keyword arguments after a optional items list. Add fromkeys() as an alternate constructor from an iterable over keys. Expand related unittests.
Diffstat (limited to 'Lib/test/test_userdict.py')
-rw-r--r--Lib/test/test_userdict.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/Lib/test/test_userdict.py b/Lib/test/test_userdict.py
index b561ac1..e61238f 100644
--- a/Lib/test/test_userdict.py
+++ b/Lib/test/test_userdict.py
@@ -6,6 +6,9 @@ from UserDict import UserDict, IterableUserDict
d0 = {}
d1 = {"one": 1}
d2 = {"one": 1, "two": 2}
+d3 = {"one": 1, "two": 3, "three": 5}
+d4 = {"one": None, "two": None}
+d5 = {"one": 1, "two": 1}
# Test constructors
@@ -21,6 +24,16 @@ uu2 = UserDict(u2)
verify(UserDict(one=1, two=2) == d2) # keyword arg constructor
verify(UserDict([('one',1), ('two',2)]) == d2) # item sequence constructor
+verify(UserDict(dict=[('one',1), ('two',2)]) == d2)
+verify(UserDict([('one',1), ('two',2)], two=3, three=5) == d3) # both together
+
+verify(UserDict.fromkeys('one two'.split()) == d4) # alternate constructor
+verify(UserDict().fromkeys('one two'.split()) == d4)
+verify(UserDict.fromkeys('one two'.split(), 1) == d5)
+verify(UserDict().fromkeys('one two'.split(), 1) == d5)
+verify(u1.fromkeys('one two'.split()) is not u1)
+verify(isinstance(u1.fromkeys('one two'.split()), UserDict))
+verify(isinstance(u2.fromkeys('one two'.split()), IterableUserDict))
# Test __repr__