summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_struct.py
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2012-07-29 14:38:45 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2012-07-29 14:38:45 (GMT)
commit2b16844326f9a88f7c5daf16abfb04cee70f02bc (patch)
tree87c57029fd16e884bd7f1a31cb474dd0bc661925 /Lib/test/test_struct.py
parent5ee9892406c4299826f553b6b73c046229c6040c (diff)
parent33f799725cb9ae21f0fed87eea4b13d7611ceeee (diff)
downloadcpython-2b16844326f9a88f7c5daf16abfb04cee70f02bc.zip
cpython-2b16844326f9a88f7c5daf16abfb04cee70f02bc.tar.gz
cpython-2b16844326f9a88f7c5daf16abfb04cee70f02bc.tar.bz2
Issue #15467: Merge 3.2
Diffstat (limited to 'Lib/test/test_struct.py')
-rw-r--r--Lib/test/test_struct.py40
1 files changed, 10 insertions, 30 deletions
diff --git a/Lib/test/test_struct.py b/Lib/test/test_struct.py
index 919cd63..22374d2 100644
--- a/Lib/test/test_struct.py
+++ b/Lib/test/test_struct.py
@@ -3,7 +3,7 @@ import unittest
import struct
import sys
-from test.support import run_unittest, cpython_only
+from test import support
ISBIGENDIAN = sys.byteorder == "big"
IS32BIT = sys.maxsize == 0x7fffffff
@@ -40,33 +40,6 @@ def bigendian_to_native(value):
return string_reverse(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 test_isbigendian(self):
self.assertEqual((struct.pack('=i', 1)[0] == 0), ISBIGENDIAN)
@@ -599,7 +572,14 @@ class StructTest(unittest.TestCase):
s = struct.Struct('i')
s.__init__('ii')
- @cpython_only
+ def check_sizeof(self, format_str, number_of_codes):
+ # The size of 'PyStructObject'
+ totalsize = support.calcobjsize('2n3P')
+ # The size taken up by the 'formatcode' dynamic array
+ totalsize += struct.calcsize('P2n0P') * (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)
@@ -614,7 +594,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()