| Index: Lib/test/test_sys.py |
| =================================================================== |
| --- Lib/test/test_sys.py (revision 64518) |
| +++ Lib/test/test_sys.py (working copy) |
| @@ -408,6 +408,8 @@ |
| class SizeofTest(unittest.TestCase): |
| + TPFLAGS_HAVE_GC = 1<<14 |
| + |
| def setUp(self): |
| self.c = len(struct.pack('c', ' ')) |
| self.H = len(struct.pack('H', 0)) |
| @@ -428,6 +430,11 @@ |
| def check_sizeof(self, o, size, size2=None): |
| """Check size of o. Possible are size and optionally size2).""" |
| result = sys.getsizeof(o) |
| + # add GC header size |
| + if type(o).__flags__ & SizeofTest.TPFLAGS_HAVE_GC: |
| + size += 32 |
| + if size2 != None: |
| + size2 += 32 |
| msg = 'wrong size for %s: got %d, expected ' % (type(o), result) |
| if (size2 != None) and (result != size): |
| self.assertEqual(result, size2, msg + str(size2)) |
| @@ -443,6 +450,16 @@ |
| """ |
| return struct.calcsize(fmt + '0P') |
| + def test_gc_head_size(self): |
| + # Check that the gc header size is added to objects tracked by the gc. |
| + h = self.header |
| + size = self.calcsize |
| + gc_header_size = 32#struct.calcsize('PPP' + '0P0P') |
| + # bool objects are not gc tracked |
| + self.assertEqual(sys.getsizeof(True), size(h + 'l')) |
| + # but lists are |
| + self.assertEqual(sys.getsizeof([]), size(h + 'lPP') + gc_header_size) |
| + |
| def test_standardtypes(self): |
| h = self.header |
| size = self.calcsize |