本文整理汇总了Python中test.test_support.vereq函数的典型用法代码示例。如果您正苦于以下问题:Python vereq函数的具体用法?Python vereq怎么用?Python vereq使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了vereq函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_2
def test_2():
d = globals().copy()
def testfunc():
global x
x = 1
d['testfunc'] = testfunc
profile.runctx("testfunc()", d, d, TESTFN)
vereq (x, 1)
os.unlink (TESTFN)
示例2: test_anon
def test_anon():
print " anonymous mmap.mmap(-1, PAGESIZE)..."
m = mmap.mmap(-1, PAGESIZE)
for x in xrange(PAGESIZE):
verify(m[x] == '\0', "anonymously mmap'ed contents should be zero")
for x in xrange(PAGESIZE):
m[x] = ch = chr(x & 255)
vereq(m[x], ch)
示例3: test_3
def test_3():
result = []
def testfunc1():
try: len(None)
except: pass
try: len(None)
except: pass
result.append(True)
def testfunc2():
testfunc1()
testfunc1()
profile.runctx("testfunc2()", locals(), locals(), TESTFN)
vereq(result, [True, True])
os.unlink(TESTFN)
示例4: test_pack_into
def test_pack_into():
test_string = 'Reykjavik rocks, eow!'
writable_buf = array.array('c', ' '*100)
fmt = '21s'
s = struct.Struct(fmt)
# Test without offset
s.pack_into(writable_buf, 0, test_string)
from_buf = writable_buf.tostring()[:len(test_string)]
vereq(from_buf, test_string)
# Test with offset.
s.pack_into(writable_buf, 10, test_string)
from_buf = writable_buf.tostring()[:len(test_string)+10]
vereq(from_buf, test_string[:10] + test_string)
# Go beyond boundaries.
small_buf = array.array('c', ' '*10)
assertRaises(struct.error, s.pack_into, small_buf, 0, test_string)
assertRaises(struct.error, s.pack_into, small_buf, 2, test_string)
示例5: test_pack_into_fn
def test_pack_into_fn():
test_string = 'Reykjavik rocks, eow!'
writable_buf = array.array('c', ' '*100)
fmt = '21s'
pack_into = lambda *args: struct.pack_into(fmt, *args)
# Test without offset.
pack_into(writable_buf, 0, test_string)
from_buf = writable_buf.tostring()[:len(test_string)]
vereq(from_buf, test_string)
# Test with offset.
pack_into(writable_buf, 10, test_string)
from_buf = writable_buf.tostring()[:len(test_string)+10]
vereq(from_buf, test_string[:10] + test_string)
# Go beyond boundaries.
small_buf = array.array('c', ' '*10)
assertRaises((struct.error, ValueError), pack_into, small_buf, 0, test_string)
assertRaises((struct.error, ValueError), pack_into, small_buf, 2, test_string)
示例6: test_saveall
def test_saveall():
# Verify that cyclic garbage like lists show up in gc.garbage if the
# SAVEALL option is enabled.
# First make sure we don't save away other stuff that just happens to
# be waiting for collection.
gc.collect()
vereq(gc.garbage, []) # if this fails, someone else created immortal trash
L = []
L.append(L)
id_L = id(L)
debug = gc.get_debug()
gc.set_debug(debug | gc.DEBUG_SAVEALL)
del L
gc.collect()
gc.set_debug(debug)
vereq(len(gc.garbage), 1)
obj = gc.garbage.pop()
vereq(id(obj), id_L)
示例7: make_adder
warnings.filterwarnings("ignore", r"import \*", SyntaxWarning, "<string>")
print "1. simple nesting"
def make_adder(x):
def adder(y):
return x + y
return adder
inc = make_adder(1)
plus10 = make_adder(10)
vereq(inc(1), 2)
vereq(plus10(-2), 8)
print "2. extra nesting"
def make_adder2(x):
def extra(): # check freevars passing through non-use scopes
def adder(y):
return x + y
return adder
return extra()
示例8: checkfilename
def checkfilename(brokencode):
try:
_symtable.symtable(brokencode, "spam", "exec")
except SyntaxError, e:
vereq(e.filename, "spam")
示例9: test_unpack_from
def test_unpack_from():
test_string = 'abcd01234'
fmt = '4s'
s = struct.Struct(fmt)
for cls in (str, buffer):
data = cls(test_string)
vereq(s.unpack_from(data), ('abcd',))
vereq(s.unpack_from(data, 2), ('cd01',))
vereq(s.unpack_from(data, 4), ('0123',))
for i in xrange(6):
vereq(s.unpack_from(data, i), (data[i:i+4],))
for i in xrange(6, len(test_string) + 1):
simple_err(s.unpack_from, data, i)
for cls in (str, buffer):
data = cls(test_string)
vereq(struct.unpack_from(fmt, data), ('abcd',))
vereq(struct.unpack_from(fmt, data, 2), ('cd01',))
vereq(struct.unpack_from(fmt, data, 4), ('0123',))
for i in xrange(6):
vereq(struct.unpack_from(fmt, data, i), (data[i:i+4],))
for i in xrange(6, len(test_string) + 1):
simple_err(struct.unpack_from, fmt, data, i)
示例10: __str__
from test import test_support
import StringIO
# SF bug 480215: softspace confused in nested print
f = StringIO.StringIO()
class C:
def __str__(self):
print >> f, 'a'
return 'b'
print >> f, C(), 'c ', 'd\t', 'e'
print >> f, 'f', 'g'
# In 2.2 & earlier, this printed ' a\nbc d\te\nf g\n'
test_support.vereq(f.getvalue(), 'a\nb c d\te\nf g\n')
示例11: f
from test.test_support import vereq, TestFailed
import _symtable
symbols = _symtable.symtable("def f(x): return x", "?", "exec")
vereq(symbols[0].name, "global")
vereq(len([ste for ste in symbols.values() if ste.name == "f"]), 1)
# Bug tickler: SyntaxError file name correct whether error raised
# while parsing or building symbol table.
def checkfilename(brokencode):
try:
_symtable.symtable(brokencode, "spam", "exec")
except SyntaxError, e:
vereq(e.filename, "spam")
else:
raise TestFailed("no SyntaxError for %r" % (brokencode,))
checkfilename("def f(x): foo)(") # parse-time
checkfilename("def f(x): global x") # symtable-build-time
示例12: f3
pass
def f3(two, arguments):
pass
def f4(two, (compound, (argument, list))):
pass
def f5((compound, first), two):
pass
vereq(f2.func_code.co_varnames, ("one_argument",))
vereq(f3.func_code.co_varnames, ("two", "arguments"))
if check_impl_detail(jython=True):
vereq(f4.func_code.co_varnames, ("two", "(compound, (argument, list))", "compound", "argument", "list"))
vereq(f5.func_code.co_varnames, ("(compound, first)", "two", "compound", "first"))
elif check_impl_detail(pypy=True):
vereq(f4.func_code.co_varnames, ("two", ".2", "compound", "argument", "list"))
vereq(f5.func_code.co_varnames, (".0", "two", "compound", "first"))
elif check_impl_detail(cpython=True):
vereq(f4.func_code.co_varnames, ("two", ".1", "compound", "argument", "list"))
vereq(f5.func_code.co_varnames, (".0", "two", "compound", "first"))
def a1(one_arg,):
pass
示例13: fpdef
### varargslist: (fpdef ['=' test] ',')* ('*' NAME [',' ('**'|'*' '*') NAME]
### | ('**'|'*' '*') NAME)
### | fpdef ['=' test] (',' fpdef ['=' test])* [',']
### fpdef: NAME | '(' fplist ')'
### fplist: fpdef (',' fpdef)* [',']
### arglist: (argument ',')* (argument | *' test [',' '**' test] | '**' test)
### argument: [test '='] test # Really [keyword '='] test
def f1(): pass
f1()
f1(*())
f1(*(), **{})
def f2(one_argument): pass
def f3(two, arguments): pass
def f4(two, (compound, (argument, list))): pass
def f5((compound, first), two): pass
vereq(f2.func_code.co_varnames, ('one_argument',))
vereq(f3.func_code.co_varnames, ('two', 'arguments'))
if sys.platform.startswith('java'):
vereq(f4.func_code.co_varnames,
('two', '(compound, (argument, list))', 'compound', 'argument',
'list',))
vereq(f5.func_code.co_varnames,
('(compound, first)', 'two', 'compound', 'first'))
else:
vereq(f4.func_code.co_varnames,
('two', '.1', 'compound', 'argument', 'list'))
vereq(f5.func_code.co_varnames,
('.0', 'two', 'compound', 'first'))
def a1(one_arg,): pass
def a2(two, args,): pass
def v0(*rest): pass
示例14: file
atexit.register(handler1)
atexit.register(handler2)
atexit.register(handler2, 7, kw="abc")
"""
fname = TESTFN + ".py"
f = file(fname, "w")
f.write(input)
f.close()
p = popen('"%s" %s' % (executable, fname))
output = p.read()
p.close()
vereq(output, """\
handler2 (7,) {'kw': 'abc'}
handler2 () {}
handler1
""")
input = """\
def direct():
print "direct exit"
import sys
sys.exitfunc = direct
# Make sure atexit doesn't drop
def indirect():
print "indirect exit"
import atexit
示例15: test_unpack_with_buffer
def test_unpack_with_buffer():
# SF bug 1563759: struct.unpack doens't support buffer protocol objects
data = array.array('B', '\x12\x34\x56\x78')
value, = struct.unpack('>I', data)
vereq(value, 0x12345678)