diff options
| author | Barry Warsaw <barry@python.org> | 2012-07-29 20:40:04 (GMT) |
|---|---|---|
| committer | Barry Warsaw <barry@python.org> | 2012-07-29 20:40:04 (GMT) |
| commit | dee609c09fb9a09d5e341e2f5975150016f85f00 (patch) | |
| tree | d2bed8f6bc932a2b4a6787827cb38cadbe92deba /Lib/test/support.py | |
| parent | dde56f4aa321edb293f64f0dfc519ef48b3dfece (diff) | |
| parent | a264384fe6de357680ca0cf02cd6024bbba0ba45 (diff) | |
| download | cpython-dee609c09fb9a09d5e341e2f5975150016f85f00.zip cpython-dee609c09fb9a09d5e341e2f5975150016f85f00.tar.gz cpython-dee609c09fb9a09d5e341e2f5975150016f85f00.tar.bz2 | |
merged
Diffstat (limited to 'Lib/test/support.py')
| -rw-r--r-- | Lib/test/support.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/Lib/test/support.py b/Lib/test/support.py index 2d7f70d..f5f574e 100644 --- a/Lib/test/support.py +++ b/Lib/test/support.py @@ -25,6 +25,7 @@ import fnmatch import logging.handlers import struct import tempfile +import _testcapi try: import _thread, threading @@ -1082,6 +1083,33 @@ def python_is_optimized(): return final_opt != '' and final_opt != '-O0' +_header = 'nP' +_align = '0n' +if hasattr(sys, "gettotalrefcount"): + _header = '2P' + _header + _align = '0P' +_vheader = _header + 'n' + +def calcobjsize(fmt): + return struct.calcsize(_header + fmt + _align) + +def calcvobjsize(fmt): + return struct.calcsize(_vheader + fmt + _align) + + +_TPFLAGS_HAVE_GC = 1<<14 +_TPFLAGS_HEAPTYPE = 1<<9 + +def check_sizeof(test, o, size): + result = sys.getsizeof(o) + # add GC header size + if ((type(o) == type) and (o.__flags__ & _TPFLAGS_HEAPTYPE) or\ + ((type(o) != type) and (type(o).__flags__ & _TPFLAGS_HAVE_GC))): + size += _testcapi.SIZEOF_PYGC_HEAD + msg = 'wrong size for %s: got %d, expected %d' \ + % (type(o), result, size) + test.assertEqual(result, size, msg) + #======================================================================= # Decorator for running a function in a different locale, correctly resetting # it afterwards. |
