本文整理汇总了Python中test.test_support.verify函数的典型用法代码示例。如果您正苦于以下问题:Python verify函数的具体用法?Python verify怎么用?Python verify使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了verify函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_logs
def test_logs():
import math
if verbose:
print "log and log10"
LOG10E = math.log10(math.e)
for exp in range(10) + [100, 1000, 10000]:
value = 10 ** exp
log10 = math.log10(value)
verify(fcmp(log10, exp) == 0)
# log10(value) == exp, so log(value) == log10(value)/log10(e) ==
# exp/LOG10E
expected = exp / LOG10E
log = math.log(value)
verify(fcmp(log, expected) == 0)
for bad in -(1L << 10000), -2L, 0L:
try:
math.log(bad)
raise TestFailed("expected ValueError from log(<= 0)")
except ValueError:
pass
try:
math.log10(bad)
raise TestFailed("expected ValueError from log10(<= 0)")
except ValueError:
pass
示例2: test_im_class
def test_im_class():
class C:
def foo(self): pass
verify(C.foo.im_class is C)
verify(C().foo.im_class is C)
cantset(C.foo, "im_class", C)
cantset(C().foo, "im_class", C)
示例3: test_float_overflow
def test_float_overflow():
import math
if verbose:
print "long->float overflow"
for x in -2.0, -1.0, 0.0, 1.0, 2.0:
verify(float(long(x)) == x)
shuge = '12345' * 120
huge = 1L << 30000
mhuge = -huge
namespace = {'huge': huge, 'mhuge': mhuge, 'shuge': shuge, 'math': math}
for test in ["float(huge)", "float(mhuge)",
"complex(huge)", "complex(mhuge)",
"complex(huge, 1)", "complex(mhuge, 1)",
"complex(1, huge)", "complex(1, mhuge)",
"1. + huge", "huge + 1.", "1. + mhuge", "mhuge + 1.",
"1. - huge", "huge - 1.", "1. - mhuge", "mhuge - 1.",
"1. * huge", "huge * 1.", "1. * mhuge", "mhuge * 1.",
"1. // huge", "huge // 1.", "1. // mhuge", "mhuge // 1.",
"1. / huge", "huge / 1.", "1. / mhuge", "mhuge / 1.",
"1. ** huge", "huge ** 1.", "1. ** mhuge", "mhuge ** 1.",
"math.sin(huge)", "math.sin(mhuge)",
"math.sqrt(huge)", "math.sqrt(mhuge)", # should do better
"math.floor(huge)", "math.floor(mhuge)",]:
#XXX: not working
#"float(shuge) == int(shuge)"]:
try:
eval(test, namespace)
except OverflowError:
pass
else:
raise TestFailed("expected OverflowError from %s" % test)
示例4: check_all
def check_all(self, modname):
names = {}
original_sys_modules = sys.modules.copy()
try:
exec "import %s" % modname in names
except ImportError:
# Silent fail here seems the best route since some modules
# may not be available in all environments.
# We restore sys.modules to avoid leaving broken modules behind,
# but we must not remove built-in modules from sys.modules
# (because they can't be re-imported, typically)
for name in sys.modules.keys():
if name in original_sys_modules:
continue
# XXX hackish
mod = sys.modules[name]
if not hasattr(mod, '__file__'):
continue
if (mod.__file__.lower().endswith('.py') or
mod.__file__.lower().endswith('.pyc') or
mod.__file__.lower().endswith('.pyo')):
del sys.modules[name]
return
verify(hasattr(sys.modules[modname], "__all__"),
"%s has no __all__ attribute" % modname)
names = {}
exec "from %s import *" % modname in names
if names.has_key("__builtins__"):
del names["__builtins__"]
keys = set(names)
all = set(sys.modules[modname].__all__)
verify(keys==all, "%s != %s" % (keys, all))
示例5: test_im_doc
def test_im_doc():
class C:
def foo(self): "hello"
verify(C.foo.__doc__ == "hello")
verify(C().foo.__doc__ == "hello")
cantset(C.foo, "__doc__", "hello")
cantset(C().foo, "__doc__", "hello")
示例6: check_all
def check_all(self, modname):
names = {}
try:
exec "import %s" % modname in names
except ImportError:
# Silent fail here seems the best route since some modules
# may not be available in all environments.
# Since an ImportError may leave a partial module object in
# sys.modules, get rid of that first. Here's what happens if
# you don't: importing pty fails on Windows because pty tries to
# import FCNTL, which doesn't exist. That raises an ImportError,
# caught here. It also leaves a partial pty module in sys.modules.
# So when test_pty is called later, the import of pty succeeds,
# but shouldn't. As a result, test_pty crashes with an
# AttributeError instead of an ImportError, and regrtest interprets
# the latter as a test failure (ImportError is treated as "test
# skipped" -- which is what test_pty should say on Windows).
try:
del sys.modules[modname]
except KeyError:
pass
return
verify(hasattr(sys.modules[modname], "__all__"),
"%s has no __all__ attribute" % modname)
names = {}
exec "from %s import *" % modname in names
if names.has_key("__builtins__"):
del names["__builtins__"]
keys = Set(names)
all = Set(sys.modules[modname].__all__)
verify(keys==all, "%s != %s" % (keys, all))
示例7: test_im_name
def test_im_name():
class C:
def foo(self): pass
verify(C.foo.__name__ == "foo")
verify(C().foo.__name__ == "foo")
cantset(C.foo, "__name__", "foo")
cantset(C().foo, "__name__", "foo")
示例8: test_func_code
def test_func_code():
a = b = 24
def f():
pass
def g():
print 12
def f1():
print a
def g1():
print b
def f2():
print a, b
verify(type(f.func_code) is types.CodeType)
f.func_code = g.func_code
cantset(f, "func_code", None)
# can't change the number of free vars
cantset(f, "func_code", f1.func_code, exception=ValueError)
cantset(f1, "func_code", f.func_code, exception=ValueError)
cantset(f1, "func_code", f2.func_code, exception=ValueError)
f1.func_code = g1.func_code
示例9: test
def test():
if not hasattr(gc, 'get_debug'):
if verbose:
print "skipping test_gc: too many GC differences with CPython"
return
if verbose:
print "disabling automatic collection"
enabled = gc.isenabled()
gc.disable()
verify(not gc.isenabled())
debug = gc.get_debug()
gc.set_debug(debug & ~gc.DEBUG_LEAK) # this test is supposed to leak
try:
test_all()
finally:
gc.set_debug(debug)
# test gc.enable() even if GC is disabled by default
if verbose:
print "restoring automatic collection"
# make sure to always test gc.enable()
gc.enable()
verify(gc.isenabled())
if not enabled:
gc.disable()
示例10: drive_one
def drive_one(pattern, length):
q, r = divmod(length, len(pattern))
teststring = pattern * q + pattern[:r]
verify(len(teststring) == length)
try_one(teststring)
try_one(teststring + "x")
try_one(teststring[:-1])
示例11: test_main
def test_main(verbose=None):
from test.test_support import verify
import sys
for func in tests:
expected = tests[func]
result = list(func())
verify(result == expected, "%s: expected %s, got %s" % (
func.__name__, expected, result))
示例12: test_im_self
def test_im_self():
class C:
def foo(self): pass
verify(C.foo.im_self is None)
c = C()
verify(c.foo.im_self is c)
cantset(C.foo, "im_self", None)
cantset(c.foo, "im_self", c)
示例13: test_im_dict
def test_im_dict():
class C:
def foo(self): pass
foo.bar = 42
verify(C.foo.__dict__ == {'bar': 42})
verify(C().foo.__dict__ == {'bar': 42})
cantset(C.foo, "__dict__", C.foo.__dict__)
cantset(C().foo, "__dict__", C.foo.__dict__)
示例14: 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)
示例15: testdgram
def testdgram(proto, addr):
s = socket.socket(proto, socket.SOCK_DGRAM)
s.sendto(teststring, addr)
buf = data = receive(s, 100)
while data and '\n' not in buf:
data = receive(s, 100)
buf += data
verify(buf == teststring)
s.close()