diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-12-22 06:22:05 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-12-22 06:22:05 (GMT) |
commit | 3987e26e7547fdd71112e70caad3e037ef8257aa (patch) | |
tree | 56b0f238b550cd659acbbc8969960d624f829a79 /Lib/test/test_ordered_dict.py | |
parent | 266514ae930495c42c99de396131feb98c64bc90 (diff) | |
parent | 0ce7a3a34cec0e625f63d46390a8c1d2e167494f (diff) | |
download | cpython-3987e26e7547fdd71112e70caad3e037ef8257aa.zip cpython-3987e26e7547fdd71112e70caad3e037ef8257aa.tar.gz cpython-3987e26e7547fdd71112e70caad3e037ef8257aa.tar.bz2 |
Issue #25914: Fixed and simplified OrderedDict.__sizeof__.
Diffstat (limited to 'Lib/test/test_ordered_dict.py')
-rw-r--r-- | Lib/test/test_ordered_dict.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/Lib/test/test_ordered_dict.py b/Lib/test/test_ordered_dict.py index e64c7e5..9f9922c 100644 --- a/Lib/test/test_ordered_dict.py +++ b/Lib/test/test_ordered_dict.py @@ -2,6 +2,7 @@ import contextlib import copy import pickle from random import randrange, shuffle +import struct import sys import unittest from collections.abc import MutableMapping @@ -604,6 +605,37 @@ class CPythonOrderedDictTests(OrderedDictTests, unittest.TestCase): module = c_coll OrderedDict = c_coll.OrderedDict + check_sizeof = support.check_sizeof + + @support.cpython_only + def test_sizeof_exact(self): + OrderedDict = self.OrderedDict + calcsize = struct.calcsize + size = support.calcobjsize + check = self.check_sizeof + + basicsize = size('n2P' + '3PnPn2P') + calcsize('2nPn') + entrysize = calcsize('n2P') + calcsize('P') + nodesize = calcsize('Pn2P') + + od = OrderedDict() + check(od, basicsize + 8*entrysize) + od.x = 1 + check(od, basicsize + 8*entrysize) + od.update([(i, i) for i in range(3)]) + check(od, basicsize + 8*entrysize + 3*nodesize) + od.update([(i, i) for i in range(3, 10)]) + check(od, basicsize + 16*entrysize + 10*nodesize) + + check(od.keys(), size('P')) + check(od.items(), size('P')) + check(od.values(), size('P')) + + itersize = size('iP2n2P') + check(iter(od), itersize) + check(iter(od.keys()), itersize) + check(iter(od.items()), itersize) + check(iter(od.values()), itersize) def test_key_change_during_iteration(self): OrderedDict = self.OrderedDict |