summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_userdict.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-09-29 20:36:06 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-09-29 20:36:06 (GMT)
commit68f5ef226e9b62b1755ee98ae3d35a4aedc56684 (patch)
treee0f85be148ced114808cd2f283452595fd080d7d /Lib/test/test_userdict.py
parente060619d4b047fdee613cafc64e3a9242a68ea54 (diff)
downloadcpython-68f5ef226e9b62b1755ee98ae3d35a4aedc56684.zip
cpython-68f5ef226e9b62b1755ee98ae3d35a4aedc56684.tar.gz
cpython-68f5ef226e9b62b1755ee98ae3d35a4aedc56684.tar.bz2
Issue #22609: Constructor of collections.UserDict now accepts the self keyword
argument.
Diffstat (limited to 'Lib/test/test_userdict.py')
-rw-r--r--Lib/test/test_userdict.py27
1 files changed, 26 insertions, 1 deletions
diff --git a/Lib/test/test_userdict.py b/Lib/test/test_userdict.py
index 2ca9929..e7fee55 100644
--- a/Lib/test/test_userdict.py
+++ b/Lib/test/test_userdict.py
@@ -29,7 +29,8 @@ class UserDictTest(mapping_tests.TestHashMappingProtocol):
self.assertEqual(collections.UserDict(one=1, two=2), d2)
# item sequence constructor
self.assertEqual(collections.UserDict([('one',1), ('two',2)]), d2)
- self.assertEqual(collections.UserDict(dict=[('one',1), ('two',2)]), d2)
+ with self.assertWarnsRegex(PendingDeprecationWarning, "'dict'"):
+ self.assertEqual(collections.UserDict(dict=[('one',1), ('two',2)]), d2)
# both together
self.assertEqual(collections.UserDict([('one',1), ('two',2)], two=3, three=5), d3)
@@ -139,6 +140,30 @@ class UserDictTest(mapping_tests.TestHashMappingProtocol):
self.assertEqual(t.popitem(), ("x", 42))
self.assertRaises(KeyError, t.popitem)
+ def test_init(self):
+ for kw in 'self', 'other', 'iterable':
+ self.assertEqual(list(collections.UserDict(**{kw: 42}).items()),
+ [(kw, 42)])
+ self.assertEqual(list(collections.UserDict({}, dict=42).items()),
+ [('dict', 42)])
+ self.assertEqual(list(collections.UserDict({}, dict=None).items()),
+ [('dict', None)])
+ with self.assertWarnsRegex(PendingDeprecationWarning, "'dict'"):
+ self.assertEqual(list(collections.UserDict(dict={'a': 42}).items()),
+ [('a', 42)])
+ self.assertRaises(TypeError, collections.UserDict, 42)
+ self.assertRaises(TypeError, collections.UserDict, (), ())
+ self.assertRaises(TypeError, collections.UserDict.__init__)
+
+ def test_update(self):
+ for kw in 'self', 'dict', 'other', 'iterable':
+ d = collections.UserDict()
+ d.update(**{kw: 42})
+ self.assertEqual(list(d.items()), [(kw, 42)])
+ self.assertRaises(TypeError, collections.UserDict().update, 42)
+ self.assertRaises(TypeError, collections.UserDict().update, {}, {})
+ self.assertRaises(TypeError, collections.UserDict.update)
+
def test_missing(self):
# Make sure UserDict doesn't have a __missing__ method
self.assertEqual(hasattr(collections.UserDict, "__missing__"), False)