本文整理汇总了Python中test.test_support.calcobjsize方法的典型用法代码示例。如果您正苦于以下问题:Python test_support.calcobjsize方法的具体用法?Python test_support.calcobjsize怎么用?Python test_support.calcobjsize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类test.test_support
的用法示例。
在下文中一共展示了test_support.calcobjsize方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check_sizeof
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import calcobjsize [as 别名]
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)
示例2: test_sizeof
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import calcobjsize [as 别名]
def test_sizeof(self):
def XXXROUNDUP(n):
if n <= 1:
return n
if n <= 128:
return (n + 3) & ~3
return 1 << (n - 1).bit_length()
basesize = support.calcobjsize('Pii')
nodesize = struct.calcsize('hP3iP0h')
def sizeofchildren(node):
if node is None:
return 0
res = 0
hasstr = len(node) > 1 and isinstance(node[-1], str)
if hasstr:
res += len(node[-1]) + 1
children = node[1:-1] if hasstr else node[1:]
if children:
res += XXXROUNDUP(len(children)) * nodesize
for child in children:
res += sizeofchildren(child)
return res
def check_st_sizeof(st):
self.check_sizeof(st, basesize + nodesize +
sizeofchildren(st.totuple()))
check_st_sizeof(parser.expr('2 + 3'))
check_st_sizeof(parser.expr('2 + 3 + 4'))
check_st_sizeof(parser.suite('x = 2 + 3'))
check_st_sizeof(parser.suite(''))
check_st_sizeof(parser.suite('# -*- coding: utf-8 -*-'))
check_st_sizeof(parser.expr('[' + '2,' * 1000 + ']'))
# XXX tests for pickling and unpickling of ST objects should go here
示例3: test_sizeof
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import calcobjsize [as 别名]
def test_sizeof(self):
BLOCKLEN = 62
basesize = test_support.calcobjsize('2P3PlPP')
blocksize = struct.calcsize('%dP2P' % BLOCKLEN)
self.assertEqual(object.__sizeof__(deque()), basesize)
check = self.check_sizeof
check(deque(), basesize + blocksize)
check(deque('a'), basesize + blocksize)
check(deque('a' * (BLOCKLEN // 2)), basesize + blocksize)
check(deque('a' * (BLOCKLEN // 2 + 1)), basesize + 2 * blocksize)
check(deque('a' * (42 * BLOCKLEN)), basesize + 43 * blocksize)
示例4: test_sizeof
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import calcobjsize [as 别名]
def test_sizeof(self):
basesize = support.calcobjsize(b'P2PP2P')
check = self.check_sizeof
self.assertEqual(object.__sizeof__(io.BytesIO()), basesize)
check(io.BytesIO(), basesize )
check(io.BytesIO(b'a'), basesize + 1 + 1 )
check(io.BytesIO(b'a' * 1000), basesize + 1000 + 1 )
示例5: test_sizeof
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import calcobjsize [as 别名]
def test_sizeof(self):
BLOCKLEN = 62
basesize = test_support.calcobjsize('2P4PlP')
blocksize = struct.calcsize('2P%dP' % BLOCKLEN)
self.assertEqual(object.__sizeof__(deque()), basesize)
check = self.check_sizeof
check(deque(), basesize + blocksize)
check(deque('a'), basesize + blocksize)
check(deque('a' * (BLOCKLEN // 2)), basesize + blocksize)
check(deque('a' * (BLOCKLEN // 2 + 1)), basesize + 2 * blocksize)
check(deque('a' * (42 * BLOCKLEN)), basesize + 43 * blocksize)