本文整理汇总了Python中test.test_support.check_py3k_warnings函数的典型用法代码示例。如果您正苦于以下问题:Python check_py3k_warnings函数的具体用法?Python check_py3k_warnings怎么用?Python check_py3k_warnings使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了check_py3k_warnings函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_basic_proxy
def test_basic_proxy(self):
o = C()
self.check_proxy(o, weakref.proxy(o))
L = UserList.UserList()
p = weakref.proxy(L)
self.assertFalse(p, "proxy for empty UserList should be false")
p.append(12)
self.assertEqual(len(L), 1)
self.assertTrue(p, "proxy for non-empty UserList should be true")
with test_support.check_py3k_warnings():
p[:] = [2, 3]
self.assertEqual(len(L), 2)
self.assertEqual(len(p), 2)
self.assertIn(3, p, "proxy didn't support __contains__() properly")
p[1] = 5
self.assertEqual(L[1], 5)
self.assertEqual(p[1], 5)
L2 = UserList.UserList(L)
p2 = weakref.proxy(L2)
self.assertEqual(p, p2)
## self.assertEqual(repr(L2), repr(p2))
L3 = UserList.UserList(range(10))
p3 = weakref.proxy(L3)
with test_support.check_py3k_warnings():
self.assertEqual(L3[:], p3[:])
self.assertEqual(L3[5:], p3[5:])
self.assertEqual(L3[:5], p3[:5])
self.assertEqual(L3[2:5], p3[2:5])
示例2: test_valid_non_numeric_input_types_for_x
def test_valid_non_numeric_input_types_for_x(self):
# Test possible valid non-numeric types for x, including subclasses
# of the allowed built-in types.
class CustomStr(str): pass
class CustomByteArray(bytearray): pass
factories = [str, bytearray, CustomStr, CustomByteArray, buffer]
if have_unicode:
class CustomUnicode(unicode): pass
factories += [unicode, CustomUnicode]
for f in factories:
with test_support.check_py3k_warnings(quiet=True):
x = f('100')
msg = 'x has value %s and type %s' % (x, type(x).__name__)
try:
self.assertEqual(int(x), 100, msg=msg)
if isinstance(x, basestring):
self.assertEqual(int(x, 2), 4, msg=msg)
except TypeError, err:
raise AssertionError('For %s got TypeError: %s' %
(type(x).__name__, err))
if not isinstance(x, basestring):
errmsg = "can't convert non-string"
with self.assertRaisesRegexp(TypeError, errmsg, msg=msg):
int(x, 2)
errmsg = 'invalid literal'
with self.assertRaisesRegexp(ValueError, errmsg, msg=msg), \
test_support.check_py3k_warnings(quiet=True):
int(f('A' * 0x10))
示例3: test_softspace
def test_softspace(self):
expected = 'file.softspace not supported in 3.x'
with file(__file__) as f:
with check_py3k_warnings() as w:
self.assertWarning(f.softspace, w, expected)
def set():
f.softspace = 0
with check_py3k_warnings() as w:
self.assertWarning(set(), w, expected)
示例4: test_multiplicative_ops
def test_multiplicative_ops(self):
x = 1 * 1
with check_py3k_warnings(('classic int division', DeprecationWarning)):
x = 1 / 1
x = 1 / 1.0
x = 1 % 1
with check_py3k_warnings(('classic int division', DeprecationWarning)):
x = 1 / 1 * 1 % 1
x = 1 / 1.0 * 1 % 1
示例5: test_et_hash
def test_et_hash(self):
from _testcapi import getargs_et_hash
self.assertEqual(getargs_et_hash('abc\xe9'), 'abc\xe9')
self.assertEqual(getargs_et_hash(u'abc'), 'abc')
self.assertEqual(getargs_et_hash('abc\xe9', 'ascii'), 'abc\xe9')
self.assertEqual(getargs_et_hash(u'abc\xe9', 'latin1'), 'abc\xe9')
self.assertRaises(UnicodeEncodeError, getargs_et_hash,
u'abc\xe9', 'ascii')
self.assertRaises(LookupError, getargs_et_hash, u'abc', 'spam')
self.assertRaises(TypeError, getargs_et_hash,
bytearray('bytearray'), 'latin1')
self.assertRaises(TypeError, getargs_et_hash,
memoryview('memoryview'), 'latin1')
with test_support.check_py3k_warnings():
self.assertEqual(getargs_et_hash(buffer('abc'), 'ascii'), 'abc')
self.assertEqual(getargs_et_hash(buffer(u'abc'), 'ascii'), 'abc')
self.assertRaises(TypeError, getargs_et_hash, None, 'latin1')
self.assertEqual(getargs_et_hash('nul:\0', 'latin1'), 'nul:\0')
self.assertEqual(getargs_et_hash(u'nul:\0', 'latin1'), 'nul:\0')
buf = bytearray('x'*8)
self.assertEqual(getargs_et_hash(u'abc\xe9', 'latin1', buf), 'abc\xe9')
self.assertEqual(buf, bytearray('abc\xe9\x00xxx'))
buf = bytearray('x'*5)
self.assertEqual(getargs_et_hash(u'abc\xe9', 'latin1', buf), 'abc\xe9')
self.assertEqual(buf, bytearray('abc\xe9\x00'))
buf = bytearray('x'*4)
self.assertRaises(TypeError, getargs_et_hash, u'abc\xe9', 'latin1', buf)
self.assertEqual(buf, bytearray('x'*4))
buf = bytearray()
self.assertRaises(TypeError, getargs_et_hash, u'abc\xe9', 'latin1', buf)
示例6: test_basics
def test_basics(self):
c = Counter("abcaba")
self.assertEqual(c, Counter({"a": 3, "b": 2, "c": 1}))
self.assertEqual(c, Counter(a=3, b=2, c=1))
self.assertIsInstance(c, dict)
self.assertIsInstance(c, Mapping)
self.assertTrue(issubclass(Counter, dict))
self.assertTrue(issubclass(Counter, Mapping))
self.assertEqual(len(c), 3)
self.assertEqual(sum(c.values()), 6)
self.assertEqual(sorted(c.values()), [1, 2, 3])
self.assertEqual(sorted(c.keys()), ["a", "b", "c"])
self.assertEqual(sorted(c), ["a", "b", "c"])
self.assertEqual(sorted(c.items()), [("a", 3), ("b", 2), ("c", 1)])
self.assertEqual(c["b"], 2)
self.assertEqual(c["z"], 0)
with test_support.check_py3k_warnings():
self.assertEqual(c.has_key("c"), True)
self.assertEqual(c.has_key("z"), False)
self.assertEqual(c.__contains__("c"), True)
self.assertEqual(c.__contains__("z"), False)
self.assertEqual(c.get("b", 10), 2)
self.assertEqual(c.get("z", 10), 10)
self.assertEqual(c, dict(a=3, b=2, c=1))
self.assertEqual(repr(c), "Counter({'a': 3, 'b': 2, 'c': 1})")
self.assertEqual(c.most_common(), [("a", 3), ("b", 2), ("c", 1)])
for i in range(5):
self.assertEqual(c.most_common(i), [("a", 3), ("b", 2), ("c", 1)][:i])
self.assertEqual("".join(sorted(c.elements())), "aaabbc")
c["a"] += 1 # increment an existing value
c["b"] -= 2 # sub existing value to zero
del c["c"] # remove an entry
del c["c"] # make sure that del doesn't raise KeyError
c["d"] -= 2 # sub from a missing value
c["e"] = -5 # directly assign a missing value
c["f"] += 4 # add to a missing value
self.assertEqual(c, dict(a=4, b=0, d=-2, e=-5, f=4))
self.assertEqual("".join(sorted(c.elements())), "aaaaffff")
self.assertEqual(c.pop("f"), 4)
self.assertNotIn("f", c)
for i in range(3):
elem, cnt = c.popitem()
self.assertNotIn(elem, c)
c.clear()
self.assertEqual(c, {})
self.assertEqual(repr(c), "Counter()")
self.assertRaises(NotImplementedError, Counter.fromkeys, "abc")
self.assertRaises(TypeError, hash, c)
c.update(dict(a=5, b=3))
c.update(c=1)
c.update(Counter("a" * 50 + "b" * 30))
c.update() # test case with no args
c.__init__("a" * 500 + "b" * 300)
c.__init__("cdc")
c.__init__()
self.assertEqual(c, dict(a=555, b=333, c=3, d=1))
self.assertEqual(c.setdefault("d", 5), 1)
self.assertEqual(c["d"], 1)
self.assertEqual(c.setdefault("e", 5), 5)
self.assertEqual(c["e"], 5)
示例7: setUp
def setUp(self):
self.con = sqlite.connect(":memory:")
cur = self.con.cursor()
cur.execute(
"""
create table test(
t text,
i integer,
f float,
n,
b blob
)
"""
)
with test_support.check_py3k_warnings():
cur.execute(
"insert into test(t, i, f, n, b) values (?, ?, ?, ?, ?)", ("foo", 5, 3.14, None, buffer("blob"))
)
self.con.create_aggregate("nostep", 1, AggrNoStep)
self.con.create_aggregate("nofinalize", 1, AggrNoFinalize)
self.con.create_aggregate("excInit", 1, AggrExceptionInInit)
self.con.create_aggregate("excStep", 1, AggrExceptionInStep)
self.con.create_aggregate("excFinalize", 1, AggrExceptionInFinalize)
self.con.create_aggregate("checkType", 2, AggrCheckType)
self.con.create_aggregate("mysum", 1, AggrSum)
示例8: test_main
def test_main():
with test_support.check_py3k_warnings(
(".+__(get|set|del)slice__ has been removed", DeprecationWarning),
("classic int division", DeprecationWarning),
("<> not supported", DeprecationWarning),
):
test_support.run_unittest(ClassTests)
示例9: CheckFuncReturnBlob
def CheckFuncReturnBlob(self):
cur = self.con.cursor()
cur.execute("select returnblob()")
val = cur.fetchone()[0]
with test_support.check_py3k_warnings():
self.assertEqual(type(val), buffer)
self.assertEqual(val, buffer("blob"))
示例10: test_main
def test_main():
with check_py3k_warnings(("exceptions must derive from BaseException",
DeprecationWarning),
("catching classes that don't inherit "
"from BaseException is not allowed",
DeprecationWarning)):
run_unittest(OpcodeTest)
示例11: CheckBlob
def CheckBlob(self):
with test_support.check_py3k_warnings():
val = buffer("Guglhupf")
self.cur.execute("insert into test(b) values (?)", (val,))
self.cur.execute("select b from test")
row = self.cur.fetchone()
self.assertEqual(row[0], val)
示例12: testAttributes
def testAttributes(self):
# verify expected attributes exist
f = self.f
with test_support.check_py3k_warnings():
softspace = f.softspace
f.name # merely shouldn't blow up
f.mode # ditto
f.closed # ditto
with test_support.check_py3k_warnings():
# verify softspace is writable
f.softspace = softspace # merely shouldn't blow up
# verify the others aren't
for attr in 'name', 'mode', 'closed':
self.assertRaises((AttributeError, TypeError), setattr, f, attr, 'oops')
示例13: testComplexDefinitions
def testComplexDefinitions(self):
def makeReturner(*lst):
def returner():
return lst
return returner
self.assertEqual(makeReturner(1,2,3)(), (1,2,3))
def makeReturner2(**kwargs):
def returner():
return kwargs
return returner
self.assertEqual(makeReturner2(a=11)()['a'], 11)
with check_py3k_warnings(("tuple parameter unpacking has been removed",
SyntaxWarning)):
exec """\
def makeAddPair((a, b)):
def addPair((c, d)):
return (a + c, b + d)
return addPair
""" in locals()
self.assertEqual(makeAddPair((1, 2))((100, 200)), (101,202))
示例14: test_auto_overflow
def test_auto_overflow(self):
special = [0, 1, 2, 3, sys.maxint-1, sys.maxint, sys.maxint+1]
sqrt = int(math.sqrt(sys.maxint))
special.extend([sqrt-1, sqrt, sqrt+1])
special.extend([-i for i in special])
def checkit(*args):
# Heavy use of nested scopes here!
self.assertEqual(got, expected,
Frm("for %r expected %r got %r", args, expected, got))
for x in special:
longx = long(x)
expected = -longx
got = -x
checkit('-', x)
for y in special:
longy = long(y)
expected = longx + longy
got = x + y
checkit(x, '+', y)
expected = longx - longy
got = x - y
checkit(x, '-', y)
expected = longx * longy
got = x * y
checkit(x, '*', y)
if y:
with test_support.check_py3k_warnings():
expected = longx / longy
got = x / y
checkit(x, '/', y)
expected = longx // longy
got = x // y
checkit(x, '//', y)
expected = divmod(longx, longy)
got = divmod(longx, longy)
checkit(x, 'divmod', y)
if abs(y) < 5 and not (x == 0 and y < 0):
expected = longx ** longy
got = x ** y
checkit(x, '**', y)
for z in special:
if z != 0 :
if y >= 0:
expected = pow(longx, longy, long(z))
got = pow(x, y, z)
checkit('pow', x, y, '%', z)
else:
self.assertRaises(TypeError, pow,longx, longy, long(z))
示例15: testMethods
def testMethods(self):
methods = ['fileno', 'flush', 'isatty', 'next', 'read', 'readinto',
'readline', 'readlines', 'seek', 'tell', 'truncate',
'write', '__iter__']
deprecated_methods = ['xreadlines']
if sys.platform.startswith('atheos'):
methods.remove('truncate')
# __exit__ should close the file
self.f.__exit__(None, None, None)
self.assertTrue(self.f.closed)
for methodname in methods:
method = getattr(self.f, methodname)
args = {'readinto': (bytearray(''),),
'seek': (0,),
'write': ('',),
}.get(methodname, ())
# should raise on closed file
self.assertRaises(ValueError, method, *args)
with test_support.check_py3k_warnings():
for methodname in deprecated_methods:
method = getattr(self.f, methodname)
self.assertRaises(ValueError, method)
self.assertRaises(ValueError, self.f.writelines, [])
# file is closed, __exit__ shouldn't do anything
self.assertEqual(self.f.__exit__(None, None, None), None)
# it must also return None if an exception was given
try:
1 // 0
except:
self.assertEqual(self.f.__exit__(*sys.exc_info()), None)