|
2 | 2 | import copy |
3 | 3 | import pickle |
4 | 4 | from random import randrange, shuffle |
| 5 | +import struct |
5 | 6 | import sys |
6 | 7 | import unittest |
7 | 8 | from collections.abc import MutableMapping |
@@ -596,6 +597,37 @@ class CPythonOrderedDictTests(OrderedDictTests, unittest.TestCase): |
596 | 597 |
|
597 | 598 | module = c_coll |
598 | 599 | OrderedDict = c_coll.OrderedDict |
| 600 | + check_sizeof = support.check_sizeof |
| 601 | + |
| 602 | + @support.cpython_only |
| 603 | + def test_sizeof_exact(self): |
| 604 | + OrderedDict = self.OrderedDict |
| 605 | + calcsize = struct.calcsize |
| 606 | + size = support.calcobjsize |
| 607 | + check = self.check_sizeof |
| 608 | + |
| 609 | + basicsize = size('n2P' + '3PnPn2P') + calcsize('2nPn') |
| 610 | + entrysize = calcsize('n2P') + calcsize('P') |
| 611 | + nodesize = calcsize('Pn2P') |
| 612 | + |
| 613 | + od = OrderedDict() |
| 614 | + check(od, basicsize + 8*entrysize) |
| 615 | + od.x = 1 |
| 616 | + check(od, basicsize + 8*entrysize) |
| 617 | + od.update([(i, i) for i in range(3)]) |
| 618 | + check(od, basicsize + 8*entrysize + 3*nodesize) |
| 619 | + od.update([(i, i) for i in range(3, 10)]) |
| 620 | + check(od, basicsize + 16*entrysize + 10*nodesize) |
| 621 | + |
| 622 | + check(od.keys(), size('P')) |
| 623 | + check(od.items(), size('P')) |
| 624 | + check(od.values(), size('P')) |
| 625 | + |
| 626 | + itersize = size('iP2n2P') |
| 627 | + check(iter(od), itersize) |
| 628 | + check(iter(od.keys()), itersize) |
| 629 | + check(iter(od.items()), itersize) |
| 630 | + check(iter(od.values()), itersize) |
599 | 631 |
|
600 | 632 | def test_key_change_during_iteration(self): |
601 | 633 | OrderedDict = self.OrderedDict |
|
0 commit comments