本文整理匯總了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)