本文整理汇总了Python中test.test_support.TestFailed方法的典型用法代码示例。如果您正苦于以下问题:Python test_support.TestFailed方法的具体用法?Python test_support.TestFailed怎么用?Python test_support.TestFailed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类test.test_support
的用法示例。
在下文中一共展示了test_support.TestFailed方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_import_hangers
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import TestFailed [as 别名]
def test_import_hangers():
import sys
if verbose:
print "testing import hangers ...",
import test.threaded_import_hangers
try:
if test.threaded_import_hangers.errors:
raise TestFailed(test.threaded_import_hangers.errors)
elif verbose:
print "OK."
finally:
# In case this test is run again, make sure the helper module
# gets loaded from scratch again.
del sys.modules['test.threaded_import_hangers']
# Tricky: When regrtest imports this module, the thread running regrtest
# grabs the import lock and won't let go of it until this module returns.
# All other threads attempting an import hang for the duration. Since
# this test spawns threads that do little *but* import, we can't do that
# successfully until after this module finishes importing and regrtest
# regains control. To make this work, a special case was added to
# regrtest to invoke a module's "test_main" function (if any) after
# importing it.
示例2: test_infinite_rec_classic_classes
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import TestFailed [as 别名]
def test_infinite_rec_classic_classes(self):
# if __coerce__() returns its arguments reversed it causes an infinite
# recursion for classic classes.
class Tester:
def __coerce__(self, other):
return other, self
exc = TestFailed("__coerce__() returning its arguments reverse "
"should raise RuntimeError")
try:
Tester() + 1
except (RuntimeError, TypeError):
return
except:
raise exc
else:
raise exc
示例3: test_main
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import TestFailed [as 别名]
def test_main():
tests = [TestImaplib]
if support.is_resource_enabled('network'):
if ssl:
global CERTFILE
CERTFILE = os.path.join(os.path.dirname(__file__) or os.curdir,
"keycert.pem")
if not os.path.exists(CERTFILE):
raise support.TestFailed("Can't read certificate files!")
tests.extend([
ThreadedNetworkedTests, ThreadedNetworkedTestsSSL,
RemoteIMAPTest, RemoteIMAP_SSLTest,
])
support.run_unittest(*tests)
示例4: test_nameprep
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import TestFailed [as 别名]
def test_nameprep(self):
from encodings.idna import nameprep
for pos, (orig, prepped) in enumerate(nameprep_tests):
if orig is None:
# Skipped
continue
# The Unicode strings are given in UTF-8
orig = unicode(orig, "utf-8")
if prepped is None:
# Input contains prohibited characters
self.assertRaises(UnicodeError, nameprep, orig)
else:
prepped = unicode(prepped, "utf-8")
try:
self.assertEqual(nameprep(orig), prepped)
except Exception,e:
raise test_support.TestFailed("Test 3.%d: %s" % (pos+1, str(e)))
示例5: try_one
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import TestFailed [as 别名]
def try_one(s):
# Since C doesn't guarantee we can write/read arbitrary bytes in text
# files, use binary mode.
f = open(TESTFN, "wb")
# write once with \n and once without
f.write(s)
f.write("\n")
f.write(s)
f.close()
f = open(TESTFN, "rb")
line = f.readline()
if line != s + "\n":
raise TestFailed("Expected %r got %r" % (s + "\n", line))
line = f.readline()
if line != s:
raise TestFailed("Expected %r got %r" % (s, line))
line = f.readline()
if line:
raise TestFailed("Expected EOF but got %r" % line)
f.close()
# A pattern with prime length, to avoid simple relationships with
# stdio buffer sizes.
示例6: ints
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import TestFailed [as 别名]
def ints():
if verbose: print "Testing int operations..."
numops(100, 3)
# The following crashes in Python 2.2
vereq((1).__nonzero__(), 1)
vereq((0).__nonzero__(), 0)
# This returns 'NotImplemented' in Python 2.2
class C(int):
def __add__(self, other):
return NotImplemented
vereq(C(5L), 5)
try:
C() + ""
except TypeError:
pass
else:
raise TestFailed, "NotImplemented should have caused TypeError"
import sys
try:
C(sys.maxint+1)
except OverflowError:
pass
else:
raise TestFailed, "should have raised OverflowError"
示例7: keywords
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import TestFailed [as 别名]
def keywords():
if verbose:
print "Testing keyword args to basic type constructors ..."
vereq(int(x=1), 1)
vereq(float(x=2), 2.0)
vereq(long(x=3), 3L)
vereq(complex(imag=42, real=666), complex(666, 42))
vereq(str(object=500), '500')
vereq(unicode(string='abc', errors='strict'), u'abc')
vereq(tuple(sequence=range(3)), (0, 1, 2))
vereq(list(sequence=(0, 1, 2)), range(3))
# note: as of Python 2.3, dict() no longer has an "items" keyword arg
for constructor in (int, float, long, complex, str, unicode,
tuple, list, file):
try:
constructor(bogus_keyword_arg=1)
except TypeError:
pass
else:
raise TestFailed("expected TypeError from bogus keyword "
"argument to %r" % constructor)
示例8: delhook
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import TestFailed [as 别名]
def delhook():
if verbose: print "Testing __del__ hook..."
log = []
class C(object):
def __del__(self):
log.append(1)
c = C()
vereq(log, [])
del c
extra_collect()
vereq(log, [1])
class D(object): pass
d = D()
try: del d[0]
except TypeError: pass
else: raise TestFailed, "invalid del() didn't raise TypeError"
示例9: hashinherit
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import TestFailed [as 别名]
def hashinherit():
if verbose: print "Testing hash of mutable subclasses..."
class mydict(dict):
pass
d = mydict()
try:
hash(d)
except TypeError:
pass
else:
raise TestFailed, "hash() of dict subclass should fail"
class mylist(list):
pass
d = mylist()
try:
hash(d)
except TypeError:
pass
else:
raise TestFailed, "hash() of list subclass should fail"
示例10: __cmp__
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import TestFailed [as 别名]
def __cmp__(self, other):
raise test_support.TestFailed, "Number.__cmp__() should not be called"
示例11: tester0
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import TestFailed [as 别名]
def tester0(fn, wantResult):
gotResult = eval(fn)
if wantResult != gotResult:
raise TestFailed, "%s should return: %r but returned: %r" \
%(fn, wantResult, gotResult)
示例12: __reduce__
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import TestFailed [as 别名]
def __reduce__(self):
raise TestFailed, "This __reduce__ shouldn't be called"
示例13: check_ok
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import TestFailed [as 别名]
def check_ok(x, x_str):
assert x > 0.0
x2 = eval(x_str)
assert x2 > 0.0
diff = abs(x - x2)
# If diff is no larger than 3 ULP (wrt x2), then diff/8 is no larger
# than 0.375 ULP, so adding diff/8 to x2 should have no effect.
if x2 + (diff / 8.) != x2:
raise TestFailed("Manifest const %s lost too much precision " % x_str)
示例14: test_copy_reduce_ex
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import TestFailed [as 别名]
def test_copy_reduce_ex(self):
class C(object):
def __reduce_ex__(self, proto):
return ""
def __reduce__(self):
raise test_support.TestFailed, "shouldn't call this"
x = C()
y = copy.copy(x)
self.assertTrue(y is x)
示例15: test_deepcopy_reduce_ex
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import TestFailed [as 别名]
def test_deepcopy_reduce_ex(self):
class C(object):
def __reduce_ex__(self, proto):
return ""
def __reduce__(self):
raise test_support.TestFailed, "shouldn't call this"
x = C()
y = copy.deepcopy(x)
self.assertTrue(y is x)