summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_dict.py
diff options
context:
space:
mode:
authorINADA Naoki <songofacandy@gmail.com>2016-11-02 09:45:16 (GMT)
committerINADA Naoki <songofacandy@gmail.com>2016-11-02 09:45:16 (GMT)
commit93f26f794d2a6661780c74089c77fd841fc9920f (patch)
treeff401180c42b58ca7394b6d53b24b956f3522264 /Lib/test/test_dict.py
parent8567e58ae3bdf346e46a100d398da8bbb05b8656 (diff)
downloadcpython-93f26f794d2a6661780c74089c77fd841fc9920f.zip
cpython-93f26f794d2a6661780c74089c77fd841fc9920f.tar.gz
cpython-93f26f794d2a6661780c74089c77fd841fc9920f.tar.bz2
Issue #28583: PyDict_SetDefault didn't combine split table when needed.
Patch by Xiang Zhang.
Diffstat (limited to 'Lib/test/test_dict.py')
-rw-r--r--Lib/test/test_dict.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/Lib/test/test_dict.py b/Lib/test/test_dict.py
index ed66ddb..20547df 100644
--- a/Lib/test/test_dict.py
+++ b/Lib/test/test_dict.py
@@ -852,6 +852,23 @@ class DictTest(unittest.TestCase):
return dicts
@support.cpython_only
+ def test_splittable_setdefault(self):
+ """split table must be combined when setdefault()
+ breaks insertion order"""
+ a, b = self.make_shared_key_dict(2)
+
+ a['a'] = 1
+ size_a = sys.getsizeof(a)
+ a['b'] = 2
+ b.setdefault('b', 2)
+ size_b = sys.getsizeof(b)
+ b['a'] = 1
+
+ self.assertGreater(size_b, size_a)
+ self.assertEqual(list(a), ['x', 'y', 'z', 'a', 'b'])
+ self.assertEqual(list(b), ['x', 'y', 'z', 'b', 'a'])
+
+ @support.cpython_only
def test_splittable_del(self):
"""split table must be combined when del d[k]"""
a, b = self.make_shared_key_dict(2)