diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-11-04 22:33:07 +0200 |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-11-04 22:33:07 +0200 |
commit | 710cd34bdbaddda5c5f03033c068e44a1bac7f21 (patch) | |
tree | 3d46562db71c1e242fd2fdf498715b79ba4925e9 /Lib | |
parent | b45b7b213742261c95324766027d44e30656b8e7 (diff) | |
download | cpython-git-710cd34bdbaddda5c5f03033c068e44a1bac7f21.tar.gz |
Issue #25449: Fixed a crash and leaking NULL in repr() of OrderedDict that
was mutated by direct calls of dict methods.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_collections.py | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py index 3f5304b517..b9fdf79463 100644 --- a/Lib/test/test_collections.py +++ b/Lib/test/test_collections.py @@ -2145,6 +2145,60 @@ class OrderedDictTests: key = c0 + c1 od[key] = key + # Direct use of dict methods + + def test_dict_setitem(self): + OrderedDict = self.OrderedDict + od = OrderedDict() + dict.__setitem__(od, 'spam', 1) + self.assertNotIn('NULL', repr(od)) + + def test_dict_delitem(self): + OrderedDict = self.OrderedDict + od = OrderedDict() + od['spam'] = 1 + od['ham'] = 2 + dict.__delitem__(od, 'spam') + with self.assertRaises(KeyError): + repr(od) + + def test_dict_clear(self): + OrderedDict = self.OrderedDict + od = OrderedDict() + od['spam'] = 1 + od['ham'] = 2 + dict.clear(od) + self.assertNotIn('NULL', repr(od)) + + def test_dict_pop(self): + OrderedDict = self.OrderedDict + od = OrderedDict() + od['spam'] = 1 + od['ham'] = 2 + dict.pop(od, 'spam') + with self.assertRaises(KeyError): + repr(od) + + def test_dict_popitem(self): + OrderedDict = self.OrderedDict + od = OrderedDict() + od['spam'] = 1 + od['ham'] = 2 + dict.popitem(od) + with self.assertRaises(KeyError): + repr(od) + + def test_dict_setdefault(self): + OrderedDict = self.OrderedDict + od = OrderedDict() + dict.setdefault(od, 'spam', 1) + self.assertNotIn('NULL', repr(od)) + + def test_dict_update(self): + od = OrderedDict() + dict.update(od, [('spam', 1)]) + self.assertNotIn('NULL', repr(od)) + class PurePythonOrderedDictTests(OrderedDictTests, unittest.TestCase): |