diff options
author | Martin v. Löwis <martin@v.loewis.de> | 2012-07-29 14:30:50 (GMT) |
---|---|---|
committer | Martin v. Löwis <martin@v.loewis.de> | 2012-07-29 14:30:50 (GMT) |
commit | c02e1e65c45753dafc7ae1b6c0b120323b2a10b7 (patch) | |
tree | 737edd05afba7a2fe033565d60a07fe00cdd00ed /Lib/test/test_struct.py | |
parent | 6812346808fd34e61ac9d3c6a9d7b0c2e0a4454e (diff) | |
download | cpython-c02e1e65c45753dafc7ae1b6c0b120323b2a10b7.zip cpython-c02e1e65c45753dafc7ae1b6c0b120323b2a10b7.tar.gz cpython-c02e1e65c45753dafc7ae1b6c0b120323b2a10b7.tar.bz2 |
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Patch by Serhiy Storchaka.
Diffstat (limited to 'Lib/test/test_struct.py')
-rw-r--r-- | Lib/test/test_struct.py | 42 |
1 files changed, 11 insertions, 31 deletions
diff --git a/Lib/test/test_struct.py b/Lib/test/test_struct.py index 4ddb79c..c8dc6f1 100644 --- a/Lib/test/test_struct.py +++ b/Lib/test/test_struct.py @@ -3,8 +3,8 @@ import array import unittest import struct import inspect -from test.test_support import (run_unittest, check_warnings, - check_py3k_warnings, cpython_only) +from test import test_support as support +from test.test_support import (check_warnings, check_py3k_warnings) import sys ISBIGENDIAN = sys.byteorder == "big" @@ -33,33 +33,6 @@ def bigendian_to_native(value): class StructTest(unittest.TestCase): - def setUp(self): - # due to missing size_t information from struct, it is assumed that - # sizeof(Py_ssize_t) = sizeof(void*) - self.header = 'PP' - if hasattr(sys, "gettotalrefcount"): - self.header += '2P' - - def check_sizeof(self, format_str, number_of_codes): - def size(fmt): - """Wrapper around struct.calcsize which enforces the alignment - of the end of a structure to the alignment requirement of pointer. - - Note: This wrapper should only be used if a pointer member is - included and no member with a size larger than a pointer exists. - """ - return struct.calcsize(fmt + '0P') - - struct_obj = struct.Struct(format_str) - # The size of 'PyStructObject' - totalsize = size(self.header + '5P') - # The size taken up by the 'formatcode' dynamic array - totalsize += size('3P') * (number_of_codes + 1) - result = sys.getsizeof(struct_obj) - msg = 'wrong size for %s: got %d, expected %d' \ - % (type(struct_obj), result, totalsize) - self.assertEqual(result, totalsize, msg) - def check_float_coerce(self, format, number): # SF bug 1530559. struct.pack raises TypeError where it used # to convert. @@ -572,7 +545,14 @@ class StructTest(unittest.TestCase): hugecount2 = '{}b{}H'.format(sys.maxsize//2, sys.maxsize//2) self.assertRaises(struct.error, struct.calcsize, hugecount2) - @cpython_only + def check_sizeof(self, format_str, number_of_codes): + # The size of 'PyStructObject' + totalsize = support.calcobjsize('5P') + # The size taken up by the 'formatcode' dynamic array + totalsize += struct.calcsize('3P') * (number_of_codes + 1) + support.check_sizeof(self, struct.Struct(format_str), totalsize) + + @support.cpython_only def test__sizeof__(self): for code in integer_codes: self.check_sizeof(code, 1) @@ -587,7 +567,7 @@ class StructTest(unittest.TestCase): self.check_sizeof('0c', 0) def test_main(): - run_unittest(StructTest) + support.run_unittest(StructTest) if __name__ == '__main__': test_main() |