cpython: efade142ef01 (original) (raw)

--- a/Lib/test/support.py +++ b/Lib/test/support.py @@ -23,6 +23,9 @@ import time import sysconfig import fnmatch import logging.handlers +import struct +import tempfile +import _testcapi try: import _thread, threading @@ -984,6 +987,31 @@ def python_is_optimized(): return final_opt and final_opt != '-O0' +_header = '2P' +if hasattr(sys, "gettotalrefcount"):

+_vheader = _header + 'P' + +def calcobjsize(fmt):

+ +def calcvobjsize(fmt):

+ + +_TPFLAGS_HAVE_GC = 1<<14 +_TPFLAGS_HEAPTYPE = 1<<9 + +def check_sizeof(test, o, size):

+ #=======================================================================

Decorator for running a function in a different locale, correctly resetting

it afterwards.

--- 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 @@ -30,32 +30,6 @@ def bigendian_to_native(value): return string_reverse(value) class StructTest(unittest.TestCase):

-

-

-

def test_isbigendian(self): self.assertEqual((struct.pack('=i', 1)[0] == 0), ISBIGENDIAN) @@ -583,7 +557,14 @@ class StructTest(unittest.TestCase): s = struct.Struct('i') s.init('ii')

+

@@ -598,7 +579,7 @@ class StructTest(unittest.TestCase): self.check_sizeof('0c', 0) def test_main():

if name == 'main': test_main()

--- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -570,22 +570,8 @@ class SysModuleTest(unittest.TestCase): class SizeofTest(unittest.TestCase):

- def setUp(self):

@@ -595,123 +581,102 @@ class SizeofTest(unittest.TestCase): self.file.close() test.support.unlink(test.support.TESTFN)

-

-

def test_gc_head_size(self): # Check that the gc header size is added to objects tracked by the gc.

def test_default(self):

def test_objecttypes(self): # check all types defined in Objects/

-# check(UnicodeDecodeError("", "", 0, 0, ""), size(h + '5P2PP'))

@@ -720,10 +685,10 @@ class SizeofTest(unittest.TestCase): nfrees = len(x.f_code.co_freevars) extras = x.f_code.co_stacksize + x.f_code.co_nlocals +[](#l3.192) ncells + nfrees - 1

@@ -732,68 +697,68 @@ class SizeofTest(unittest.TestCase): def bar(cls): pass # staticmethod

@@ -810,18 +775,18 @@ class SizeofTest(unittest.TestCase): check(set(sample), s + newsizestruct.calcsize('lP')) check(frozenset(sample), s + newsizestruct.calcsize('lP')) # setiterator

@@ -832,39 +797,38 @@ class SizeofTest(unittest.TestCase): # we need to test for both sizes, because we don't know if the string # has been cached for s in samples:

def test_pythontypes(self): # check all types defined in Python/

def test_main():

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -383,6 +383,9 @@ Extension Modules Tests ----- +- Issue #15467: Move helpers for sizeof tests into test_support.