diff options
author | Eric Snow <ericsnowcurrently@gmail.com> | 2015-08-07 23:45:12 (GMT) |
---|---|---|
committer | Eric Snow <ericsnowcurrently@gmail.com> | 2015-08-07 23:45:12 (GMT) |
commit | 8c7f9558eb82f740d162b21fe8e01cfdd961f0d3 (patch) | |
tree | 4af615cbf0a790f0f6446893cb21cde52cb2d80b /Lib | |
parent | 31202eaa5c735044d9007f448b7f41b2c00f5f69 (diff) | |
download | cpython-8c7f9558eb82f740d162b21fe8e01cfdd961f0d3.zip cpython-8c7f9558eb82f740d162b21fe8e01cfdd961f0d3.tar.gz cpython-8c7f9558eb82f740d162b21fe8e01cfdd961f0d3.tar.bz2 |
Issue #24667: Resize odict in all cases that the underlying dict resizes.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_collections.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py index fbaf712..c2d03ee 100644 --- a/Lib/test/test_collections.py +++ b/Lib/test/test_collections.py @@ -2098,6 +2098,29 @@ class CPythonOrderedDictTests(OrderedDictTests, unittest.TestCase): # This should not crash. od.popitem() + def test_issue24667(self): + """ + dict resizes after a certain number of insertion operations, + whether or not there were deletions that freed up slots in the + hash table. During fast node lookup, OrderedDict must correctly + respond to all resizes, even if the current "size" is the same + as the old one. We verify that here by forcing a dict resize + on a sparse odict and then perform an operation that should + trigger an odict resize (e.g. popitem). One key aspect here is + that we will keep the size of the odict the same at each popitem + call. This verifies that we handled the dict resize properly. + """ + OrderedDict = self.module.OrderedDict + + od = OrderedDict() + for c0 in '0123456789ABCDEF': + for c1 in '0123456789ABCDEF': + if len(od) == 4: + # This should not raise a KeyError. + od.popitem(last=False) + key = c0 + c1 + od[key] = key + class PurePythonGeneralMappingTests(mapping_tests.BasicTestMappingProtocol): |