summaryrefslogtreecommitdiff
path: root/Lib/test/test_weakref.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-09-29 23:52:09 +0300
committerSerhiy Storchaka <storchaka@gmail.com>2015-09-29 23:52:09 +0300
commitb5102e3550a589084bf33fae15bf131f47d51b0b (patch)
tree67a2d7be18a1517412cf2fc6d9e5b397fb6eccfc /Lib/test/test_weakref.py
parent68f5ef226e9b62b1755ee98ae3d35a4aedc56684 (diff)
downloadcpython-git-b5102e3550a589084bf33fae15bf131f47d51b0b.tar.gz
Issue #22958: Constructor and update method of weakref.WeakValueDictionary
now accept the self and the dict keyword arguments.
Diffstat (limited to 'Lib/test/test_weakref.py')
-rw-r--r--Lib/test/test_weakref.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/Lib/test/test_weakref.py b/Lib/test/test_weakref.py
index 3e7347cf33..212cf340f4 100644
--- a/Lib/test/test_weakref.py
+++ b/Lib/test/test_weakref.py
@@ -1408,6 +1408,18 @@ class MappingTestCase(TestBase):
dict2 = weakref.WeakValueDictionary(dict)
self.assertEqual(dict[364], o)
+ def test_make_weak_valued_dict_misc(self):
+ # errors
+ self.assertRaises(TypeError, weakref.WeakValueDictionary.__init__)
+ self.assertRaises(TypeError, weakref.WeakValueDictionary, {}, {})
+ self.assertRaises(TypeError, weakref.WeakValueDictionary, (), ())
+ # special keyword arguments
+ o = Object(3)
+ for kw in 'self', 'dict', 'other', 'iterable':
+ d = weakref.WeakValueDictionary(**{kw: o})
+ self.assertEqual(list(d.keys()), [kw])
+ self.assertEqual(d[kw], o)
+
def make_weak_valued_dict(self):
dict = weakref.WeakValueDictionary()
objects = list(map(Object, range(self.COUNT)))
@@ -1488,6 +1500,19 @@ class MappingTestCase(TestBase):
def test_weak_valued_dict_update(self):
self.check_update(weakref.WeakValueDictionary,
{1: C(), 'a': C(), C(): C()})
+ # errors
+ self.assertRaises(TypeError, weakref.WeakValueDictionary.update)
+ d = weakref.WeakValueDictionary()
+ self.assertRaises(TypeError, d.update, {}, {})
+ self.assertRaises(TypeError, d.update, (), ())
+ self.assertEqual(list(d.keys()), [])
+ # special keyword arguments
+ o = Object(3)
+ for kw in 'self', 'dict', 'other', 'iterable':
+ d = weakref.WeakValueDictionary()
+ d.update(**{kw: o})
+ self.assertEqual(list(d.keys()), [kw])
+ self.assertEqual(d[kw], o)
def test_weak_keyed_dict_update(self):
self.check_update(weakref.WeakKeyDictionary,