summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2004-03-04 08:25:44 (GMT)
committerRaymond Hettinger <python@rcn.com>2004-03-04 08:25:44 (GMT)
commit31017aed36a5c5b0e4b16ca58bea09c9ce360134 (patch)
tree766d70bb4fbb6878a71c81fc3874515cfcbc8aa8 /Lib/test
parent6c79a518e70ea8e45e3287573d99c648ae3cb21b (diff)
downloadcpython-31017aed36a5c5b0e4b16ca58bea09c9ce360134.zip
cpython-31017aed36a5c5b0e4b16ca58bea09c9ce360134.tar.gz
cpython-31017aed36a5c5b0e4b16ca58bea09c9ce360134.tar.bz2
SF #904720: dict.update should take a 2-tuple sequence like dict.__init_
(Championed by Bob Ippolito.) The update() method for mappings now accepts all the same argument forms as the dict() constructor. This includes item lists and/or keyword arguments.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_call.py18
-rw-r--r--Lib/test/test_types.py2
-rw-r--r--Lib/test/test_userdict.py6
3 files changed, 15 insertions, 11 deletions
diff --git a/Lib/test/test_call.py b/Lib/test/test_call.py
index 99554c7..f3c7c8c 100644
--- a/Lib/test/test_call.py
+++ b/Lib/test/test_call.py
@@ -86,41 +86,41 @@ class CFunctionCalls(unittest.TestCase):
self.assertRaises(TypeError, {}.keys, x=2, y=2)
def test_oldargs1_0(self):
- self.assertRaises(TypeError, {}.update)
+ self.assertRaises(TypeError, [].count)
def test_oldargs1_1(self):
- {}.update({})
+ [].count(1)
def test_oldargs1_2(self):
- self.assertRaises(TypeError, {}.update, {}, 1)
+ self.assertRaises(TypeError, [].count, 1, 2)
def test_oldargs1_0_ext(self):
try:
- {}.update(*())
+ [].count(*())
except TypeError:
pass
else:
raise RuntimeError
def test_oldargs1_1_ext(self):
- {}.update(*({},))
+ [].count(*(1,))
def test_oldargs1_2_ext(self):
try:
- {}.update(*({}, 2))
+ [].count(*(1, 2))
except TypeError:
pass
else:
raise RuntimeError
def test_oldargs1_0_kw(self):
- self.assertRaises(TypeError, {}.update, x=2)
+ self.assertRaises(TypeError, [].count, x=2)
def test_oldargs1_1_kw(self):
- self.assertRaises(TypeError, {}.update, {}, x=2)
+ self.assertRaises(TypeError, [].count, {}, x=2)
def test_oldargs1_2_kw(self):
- self.assertRaises(TypeError, {}.update, x=2, y=2)
+ self.assertRaises(TypeError, [].count, x=2, y=2)
def test_main():
diff --git a/Lib/test/test_types.py b/Lib/test/test_types.py
index aa8f854..4b4e19c 100644
--- a/Lib/test/test_types.py
+++ b/Lib/test/test_types.py
@@ -253,7 +253,7 @@ d.update({1:1, 2:2, 3:3})
if d != {1:1, 2:2, 3:3}: raise TestFailed, 'dict update'
d.clear()
try: d.update(None)
-except AttributeError: pass
+except (TypeError, AttributeError): pass
else: raise TestFailed, 'dict.update(None), AttributeError expected'
class SimpleUserDict:
def __init__(self):
diff --git a/Lib/test/test_userdict.py b/Lib/test/test_userdict.py
index 602fd90..0ed4369 100644
--- a/Lib/test/test_userdict.py
+++ b/Lib/test/test_userdict.py
@@ -93,8 +93,12 @@ class TestMappingProtocol(unittest.TestCase):
#update
p.update(self.reference)
self.assertEqual(dict(p), self.reference)
+ items = p.items()
+ p = self._empty_mapping()
+ p.update(items)
+ self.assertEqual(dict(p), self.reference)
d = self._full_mapping(self.reference)
- #setdefaullt
+ #setdefault
key, value = d.iteritems().next()
knownkey, knownvalue = self.other.iteritems().next()
self.assertEqual(d.setdefault(key, knownvalue), value)