Issue #15402: Add a __sizeof__ method to struct.Struct.

Initial patch by Serhiy Storchaka.
This commit is contained in:
Meador Inge 2012-07-23 09:27:00 -05:00
parent 0c472c3271
commit 87c5b94c39
3 changed files with 31 additions and 0 deletions

View file

@ -544,6 +544,16 @@ class StructTest(unittest.TestCase):
hugecount2 = '{}b{}H'.format(sys.maxsize//2, sys.maxsize//2)
self.assertRaises(struct.error, struct.calcsize, hugecount2)
def test_sizeof(self):
self.assertGreater(sys.getsizeof(struct.Struct('BHILfdspP')),
sys.getsizeof(struct.Struct('B')))
self.assertGreaterEqual(sys.getsizeof(struct.Struct('123B')),
sys.getsizeof(struct.Struct('B')))
self.assertGreaterEqual(sys.getsizeof(struct.Struct('B' * 123)),
sys.getsizeof(struct.Struct('123B')))
self.assertGreaterEqual(sys.getsizeof(struct.Struct('123xB')),
sys.getsizeof(struct.Struct('B')))
def test_main():
run_unittest(StructTest)