mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
Issue #15402: Add a __sizeof__ method to struct.Struct.
Initial patch by Serhiy Storchaka.
This commit is contained in:
parent
0c472c3271
commit
87c5b94c39
3 changed files with 31 additions and 0 deletions
|
@ -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)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue