convert usage of fail* to assert*
This commit is contained in:
parent
be96cf608f
commit
5c8da86f3a
|
@ -14,22 +14,22 @@ class AnonTest(unittest.TestCase):
|
|||
("y", c_int)]
|
||||
_anonymous_ = ["_"]
|
||||
|
||||
self.failUnlessEqual(Y.a.offset, sizeof(c_int))
|
||||
self.failUnlessEqual(Y.b.offset, sizeof(c_int))
|
||||
self.assertEqual(Y.a.offset, sizeof(c_int))
|
||||
self.assertEqual(Y.b.offset, sizeof(c_int))
|
||||
|
||||
self.failUnlessEqual(ANON.a.offset, 0)
|
||||
self.failUnlessEqual(ANON.b.offset, 0)
|
||||
self.assertEqual(ANON.a.offset, 0)
|
||||
self.assertEqual(ANON.b.offset, 0)
|
||||
|
||||
def test_anon_nonseq(self):
|
||||
# TypeError: _anonymous_ must be a sequence
|
||||
self.failUnlessRaises(TypeError,
|
||||
self.assertRaises(TypeError,
|
||||
lambda: type(Structure)("Name",
|
||||
(Structure,),
|
||||
{"_fields_": [], "_anonymous_": 42}))
|
||||
|
||||
def test_anon_nonmember(self):
|
||||
# AttributeError: type object 'Name' has no attribute 'x'
|
||||
self.failUnlessRaises(AttributeError,
|
||||
self.assertRaises(AttributeError,
|
||||
lambda: type(Structure)("Name",
|
||||
(Structure,),
|
||||
{"_fields_": [],
|
||||
|
@ -50,11 +50,11 @@ class AnonTest(unittest.TestCase):
|
|||
("y", c_int)]
|
||||
_anonymous_ = ["_"]
|
||||
|
||||
self.failUnlessEqual(Y.x.offset, 0)
|
||||
self.failUnlessEqual(Y.a.offset, sizeof(c_int))
|
||||
self.failUnlessEqual(Y.b.offset, sizeof(c_int))
|
||||
self.failUnlessEqual(Y._.offset, sizeof(c_int))
|
||||
self.failUnlessEqual(Y.y.offset, sizeof(c_int) * 2)
|
||||
self.assertEqual(Y.x.offset, 0)
|
||||
self.assertEqual(Y.a.offset, sizeof(c_int))
|
||||
self.assertEqual(Y.b.offset, sizeof(c_int))
|
||||
self.assertEqual(Y._.offset, sizeof(c_int))
|
||||
self.assertEqual(Y.y.offset, sizeof(c_int) * 2)
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
|
@ -26,7 +26,7 @@ class Test(unittest.TestCase):
|
|||
c.pvalues = val_array
|
||||
|
||||
# memory contains 4 NUL bytes now, that's correct
|
||||
self.failUnlessEqual("00-00-00-00", dump(val_array))
|
||||
self.assertEqual("00-00-00-00", dump(val_array))
|
||||
|
||||
# set the values of the array through the pointer:
|
||||
for i in range(4):
|
||||
|
@ -35,7 +35,7 @@ class Test(unittest.TestCase):
|
|||
values = [c.pvalues[i].val for i in range(4)]
|
||||
|
||||
# These are the expected results: here s the bug!
|
||||
self.failUnlessEqual(
|
||||
self.assertEqual(
|
||||
(values, dump(val_array)),
|
||||
([1, 2, 3, 4], "01-02-03-04")
|
||||
)
|
||||
|
@ -45,7 +45,7 @@ class Test(unittest.TestCase):
|
|||
val_array = (Value * 4)()
|
||||
|
||||
# memory contains 4 NUL bytes now, that's correct
|
||||
self.failUnlessEqual("00-00-00-00", dump(val_array))
|
||||
self.assertEqual("00-00-00-00", dump(val_array))
|
||||
|
||||
ptr = cast(val_array, POINTER(Value))
|
||||
# set the values of the array through the pointer:
|
||||
|
@ -55,7 +55,7 @@ class Test(unittest.TestCase):
|
|||
values = [ptr[i].val for i in range(4)]
|
||||
|
||||
# These are the expected results: here s the bug!
|
||||
self.failUnlessEqual(
|
||||
self.assertEqual(
|
||||
(values, dump(val_array)),
|
||||
([1, 2, 3, 4], "01-02-03-04")
|
||||
)
|
||||
|
|
|
@ -19,23 +19,23 @@ class ArrayTestCase(unittest.TestCase):
|
|||
|
||||
ia = int_array(*init)
|
||||
# length of instance ok?
|
||||
self.failUnlessEqual(len(ia), alen)
|
||||
self.assertEqual(len(ia), alen)
|
||||
|
||||
# slot values ok?
|
||||
values = [ia[i] for i in range(len(init))]
|
||||
self.failUnlessEqual(values, init)
|
||||
self.assertEqual(values, init)
|
||||
|
||||
# change the items
|
||||
from operator import setitem
|
||||
new_values = range(42, 42+alen)
|
||||
[setitem(ia, n, new_values[n]) for n in range(alen)]
|
||||
values = [ia[i] for i in range(len(init))]
|
||||
self.failUnlessEqual(values, new_values)
|
||||
self.assertEqual(values, new_values)
|
||||
|
||||
# are the items initialized to 0?
|
||||
ia = int_array()
|
||||
values = [ia[i] for i in range(len(init))]
|
||||
self.failUnlessEqual(values, [0] * len(init))
|
||||
self.assertEqual(values, [0] * len(init))
|
||||
|
||||
# Too many in itializers should be caught
|
||||
self.assertRaises(IndexError, int_array, *range(alen*2))
|
||||
|
@ -48,14 +48,14 @@ class ArrayTestCase(unittest.TestCase):
|
|||
# CharArray("abc")
|
||||
self.assertRaises(TypeError, CharArray, "abc")
|
||||
|
||||
self.failUnlessEqual(ca[0], "a")
|
||||
self.failUnlessEqual(ca[1], "b")
|
||||
self.failUnlessEqual(ca[2], "c")
|
||||
self.failUnlessEqual(ca[-3], "a")
|
||||
self.failUnlessEqual(ca[-2], "b")
|
||||
self.failUnlessEqual(ca[-1], "c")
|
||||
self.assertEqual(ca[0], "a")
|
||||
self.assertEqual(ca[1], "b")
|
||||
self.assertEqual(ca[2], "c")
|
||||
self.assertEqual(ca[-3], "a")
|
||||
self.assertEqual(ca[-2], "b")
|
||||
self.assertEqual(ca[-1], "c")
|
||||
|
||||
self.failUnlessEqual(len(ca), 3)
|
||||
self.assertEqual(len(ca), 3)
|
||||
|
||||
# slicing is now supported, but not extended slicing (3-argument)!
|
||||
from operator import getslice, delitem
|
||||
|
@ -72,34 +72,34 @@ class ArrayTestCase(unittest.TestCase):
|
|||
|
||||
na = numarray()
|
||||
values = [na[i] for i in range(alen)]
|
||||
self.failUnlessEqual(values, [0] * alen)
|
||||
self.assertEqual(values, [0] * alen)
|
||||
|
||||
na = numarray(*[c_int()] * alen)
|
||||
values = [na[i] for i in range(alen)]
|
||||
self.failUnlessEqual(values, [0]*alen)
|
||||
self.assertEqual(values, [0]*alen)
|
||||
|
||||
na = numarray(1, 2, 3, 4, 5)
|
||||
values = [i for i in na]
|
||||
self.failUnlessEqual(values, [1, 2, 3, 4, 5])
|
||||
self.assertEqual(values, [1, 2, 3, 4, 5])
|
||||
|
||||
na = numarray(*map(c_int, (1, 2, 3, 4, 5)))
|
||||
values = [i for i in na]
|
||||
self.failUnlessEqual(values, [1, 2, 3, 4, 5])
|
||||
self.assertEqual(values, [1, 2, 3, 4, 5])
|
||||
|
||||
def test_classcache(self):
|
||||
self.failUnless(not ARRAY(c_int, 3) is ARRAY(c_int, 4))
|
||||
self.failUnless(ARRAY(c_int, 3) is ARRAY(c_int, 3))
|
||||
self.assertTrue(not ARRAY(c_int, 3) is ARRAY(c_int, 4))
|
||||
self.assertTrue(ARRAY(c_int, 3) is ARRAY(c_int, 3))
|
||||
|
||||
def test_from_address(self):
|
||||
# Failed with 0.9.8, reported by JUrner
|
||||
p = create_string_buffer("foo")
|
||||
sz = (c_char * 3).from_address(addressof(p))
|
||||
self.failUnlessEqual(sz[:], "foo")
|
||||
self.failUnlessEqual(sz[::], "foo")
|
||||
self.failUnlessEqual(sz[::-1], "oof")
|
||||
self.failUnlessEqual(sz[::3], "f")
|
||||
self.failUnlessEqual(sz[1:4:2], "o")
|
||||
self.failUnlessEqual(sz.value, "foo")
|
||||
self.assertEqual(sz[:], "foo")
|
||||
self.assertEqual(sz[::], "foo")
|
||||
self.assertEqual(sz[::-1], "oof")
|
||||
self.assertEqual(sz[::3], "f")
|
||||
self.assertEqual(sz[1:4:2], "o")
|
||||
self.assertEqual(sz.value, "foo")
|
||||
|
||||
try:
|
||||
create_unicode_buffer
|
||||
|
@ -109,12 +109,12 @@ class ArrayTestCase(unittest.TestCase):
|
|||
def test_from_addressW(self):
|
||||
p = create_unicode_buffer("foo")
|
||||
sz = (c_wchar * 3).from_address(addressof(p))
|
||||
self.failUnlessEqual(sz[:], "foo")
|
||||
self.failUnlessEqual(sz[::], "foo")
|
||||
self.failUnlessEqual(sz[::-1], "oof")
|
||||
self.failUnlessEqual(sz[::3], "f")
|
||||
self.failUnlessEqual(sz[1:4:2], "o")
|
||||
self.failUnlessEqual(sz.value, "foo")
|
||||
self.assertEqual(sz[:], "foo")
|
||||
self.assertEqual(sz[::], "foo")
|
||||
self.assertEqual(sz[::-1], "oof")
|
||||
self.assertEqual(sz[::3], "f")
|
||||
self.assertEqual(sz[1:4:2], "o")
|
||||
self.assertEqual(sz.value, "foo")
|
||||
|
||||
def test_cache(self):
|
||||
# Array types are cached internally in the _ctypes extension,
|
||||
|
@ -128,7 +128,7 @@ class ArrayTestCase(unittest.TestCase):
|
|||
# Create a new array type based on it:
|
||||
t1 = my_int * 1
|
||||
t2 = my_int * 1
|
||||
self.failUnless(t1 is t2)
|
||||
self.assertTrue(t1 is t2)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -25,8 +25,8 @@ class BasicWrapTestCase(unittest.TestCase):
|
|||
f = dll._testfunc_i_bhilfd
|
||||
f.argtypes = [c_byte, c_wchar, c_int, c_long, c_float, c_double]
|
||||
result = f(self.wrap(1), self.wrap(u"x"), self.wrap(3), self.wrap(4), self.wrap(5.0), self.wrap(6.0))
|
||||
self.failUnlessEqual(result, 139)
|
||||
self.failUnless(type(result), int)
|
||||
self.assertEqual(result, 139)
|
||||
self.assertTrue(type(result), int)
|
||||
|
||||
def test_pointers(self):
|
||||
f = dll._testfunc_p_p
|
||||
|
@ -39,18 +39,18 @@ class BasicWrapTestCase(unittest.TestCase):
|
|||
|
||||
v = c_int(42)
|
||||
|
||||
self.failUnlessEqual(pointer(v).contents.value, 42)
|
||||
self.assertEqual(pointer(v).contents.value, 42)
|
||||
result = f(self.wrap(pointer(v)))
|
||||
self.failUnlessEqual(type(result), POINTER(c_int))
|
||||
self.failUnlessEqual(result.contents.value, 42)
|
||||
self.assertEqual(type(result), POINTER(c_int))
|
||||
self.assertEqual(result.contents.value, 42)
|
||||
|
||||
# This on works...
|
||||
result = f(self.wrap(pointer(v)))
|
||||
self.failUnlessEqual(result.contents.value, v.value)
|
||||
self.assertEqual(result.contents.value, v.value)
|
||||
|
||||
p = pointer(c_int(99))
|
||||
result = f(self.wrap(p))
|
||||
self.failUnlessEqual(result.contents.value, 99)
|
||||
self.assertEqual(result.contents.value, 99)
|
||||
|
||||
def test_shorts(self):
|
||||
f = dll._testfunc_callback_i_if
|
||||
|
@ -67,7 +67,7 @@ class BasicWrapTestCase(unittest.TestCase):
|
|||
|
||||
cb = CallBack(callback)
|
||||
f(self.wrap(2**18), self.wrap(cb))
|
||||
self.failUnlessEqual(args, expected)
|
||||
self.assertEqual(args, expected)
|
||||
|
||||
################################################################
|
||||
|
||||
|
@ -84,17 +84,17 @@ class BasicWrapTestCase(unittest.TestCase):
|
|||
cb = MyCallback(callback)
|
||||
|
||||
result = f(self.wrap(-10), self.wrap(cb))
|
||||
self.failUnlessEqual(result, -18)
|
||||
self.assertEqual(result, -18)
|
||||
|
||||
# test with prototype
|
||||
f.argtypes = [c_int, MyCallback]
|
||||
cb = MyCallback(callback)
|
||||
|
||||
result = f(self.wrap(-10), self.wrap(cb))
|
||||
self.failUnlessEqual(result, -18)
|
||||
self.assertEqual(result, -18)
|
||||
|
||||
result = f(self.wrap(-10), self.wrap(cb))
|
||||
self.failUnlessEqual(result, -18)
|
||||
self.assertEqual(result, -18)
|
||||
|
||||
AnotherCallback = CALLBACK_FUNCTYPE(c_int, c_int, c_int, c_int, c_int)
|
||||
|
||||
|
@ -116,12 +116,12 @@ class BasicWrapTestCase(unittest.TestCase):
|
|||
|
||||
def callback(value):
|
||||
#print "called back with", value
|
||||
self.failUnlessEqual(type(value), int)
|
||||
self.assertEqual(type(value), int)
|
||||
return value
|
||||
|
||||
cb = MyCallback(callback)
|
||||
result = f(self.wrap(-10), self.wrap(cb))
|
||||
self.failUnlessEqual(result, -18)
|
||||
self.assertEqual(result, -18)
|
||||
|
||||
def test_longlong_callbacks(self):
|
||||
|
||||
|
@ -133,12 +133,12 @@ class BasicWrapTestCase(unittest.TestCase):
|
|||
f.argtypes = [c_longlong, MyCallback]
|
||||
|
||||
def callback(value):
|
||||
self.failUnless(isinstance(value, (int, long)))
|
||||
self.assertTrue(isinstance(value, (int, long)))
|
||||
return value & 0x7FFFFFFF
|
||||
|
||||
cb = MyCallback(callback)
|
||||
|
||||
self.failUnlessEqual(13577625587, int(f(self.wrap(1000000000000), self.wrap(cb))))
|
||||
self.assertEqual(13577625587, int(f(self.wrap(1000000000000), self.wrap(cb))))
|
||||
|
||||
def test_byval(self):
|
||||
# without prototype
|
||||
|
@ -148,7 +148,7 @@ class BasicWrapTestCase(unittest.TestCase):
|
|||
result = dll._testfunc_byval(ptin, byref(ptout))
|
||||
got = result, ptout.x, ptout.y
|
||||
expected = 3, 1, 2
|
||||
self.failUnlessEqual(got, expected)
|
||||
self.assertEqual(got, expected)
|
||||
|
||||
# with prototype
|
||||
ptin = POINT(101, 102)
|
||||
|
@ -158,7 +158,7 @@ class BasicWrapTestCase(unittest.TestCase):
|
|||
result = dll._testfunc_byval(self.wrap(ptin), byref(ptout))
|
||||
got = result, ptout.x, ptout.y
|
||||
expected = 203, 101, 102
|
||||
self.failUnlessEqual(got, expected)
|
||||
self.assertEqual(got, expected)
|
||||
|
||||
def test_struct_return_2H(self):
|
||||
class S2H(Structure):
|
||||
|
@ -168,7 +168,7 @@ class BasicWrapTestCase(unittest.TestCase):
|
|||
dll.ret_2h_func.argtypes = [S2H]
|
||||
inp = S2H(99, 88)
|
||||
s2h = dll.ret_2h_func(self.wrap(inp))
|
||||
self.failUnlessEqual((s2h.x, s2h.y), (99*2, 88*3))
|
||||
self.assertEqual((s2h.x, s2h.y), (99*2, 88*3))
|
||||
|
||||
def test_struct_return_8H(self):
|
||||
class S8I(Structure):
|
||||
|
@ -184,7 +184,7 @@ class BasicWrapTestCase(unittest.TestCase):
|
|||
dll.ret_8i_func.argtypes = [S8I]
|
||||
inp = S8I(9, 8, 7, 6, 5, 4, 3, 2)
|
||||
s8i = dll.ret_8i_func(self.wrap(inp))
|
||||
self.failUnlessEqual((s8i.a, s8i.b, s8i.c, s8i.d, s8i.e, s8i.f, s8i.g, s8i.h),
|
||||
self.assertEqual((s8i.a, s8i.b, s8i.c, s8i.d, s8i.e, s8i.f, s8i.g, s8i.h),
|
||||
(9*2, 8*3, 7*4, 6*5, 5*6, 4*7, 3*8, 2*9))
|
||||
|
||||
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
|
|
@ -37,14 +37,14 @@ class C_Test(unittest.TestCase):
|
|||
for name in "ABCDEFGHI":
|
||||
b = BITS()
|
||||
setattr(b, name, i)
|
||||
self.failUnlessEqual((name, i, getattr(b, name)), (name, i, func(byref(b), name)))
|
||||
self.assertEqual((name, i, getattr(b, name)), (name, i, func(byref(b), name)))
|
||||
|
||||
def test_shorts(self):
|
||||
for i in range(256):
|
||||
for name in "MNOPQRS":
|
||||
b = BITS()
|
||||
setattr(b, name, i)
|
||||
self.failUnlessEqual((name, i, getattr(b, name)), (name, i, func(byref(b), name)))
|
||||
self.assertEqual((name, i, getattr(b, name)), (name, i, func(byref(b), name)))
|
||||
|
||||
signed_int_types = (c_byte, c_short, c_int, c_long, c_longlong)
|
||||
unsigned_int_types = (c_ubyte, c_ushort, c_uint, c_ulong, c_ulonglong)
|
||||
|
@ -58,10 +58,10 @@ class BitFieldTest(unittest.TestCase):
|
|||
("b", c_longlong, 62),
|
||||
("c", c_longlong, 1)]
|
||||
|
||||
self.failUnlessEqual(sizeof(X), sizeof(c_longlong))
|
||||
self.assertEqual(sizeof(X), sizeof(c_longlong))
|
||||
x = X()
|
||||
x.a, x.b, x.c = -1, 7, -1
|
||||
self.failUnlessEqual((x.a, x.b, x.c), (-1, 7, -1))
|
||||
self.assertEqual((x.a, x.b, x.c), (-1, 7, -1))
|
||||
|
||||
def test_ulonglong(self):
|
||||
class X(Structure):
|
||||
|
@ -69,11 +69,11 @@ class BitFieldTest(unittest.TestCase):
|
|||
("b", c_ulonglong, 62),
|
||||
("c", c_ulonglong, 1)]
|
||||
|
||||
self.failUnlessEqual(sizeof(X), sizeof(c_longlong))
|
||||
self.assertEqual(sizeof(X), sizeof(c_longlong))
|
||||
x = X()
|
||||
self.failUnlessEqual((x.a, x.b, x.c), (0, 0, 0))
|
||||
self.assertEqual((x.a, x.b, x.c), (0, 0, 0))
|
||||
x.a, x.b, x.c = 7, 7, 7
|
||||
self.failUnlessEqual((x.a, x.b, x.c), (1, 7, 1))
|
||||
self.assertEqual((x.a, x.b, x.c), (1, 7, 1))
|
||||
|
||||
def test_signed(self):
|
||||
for c_typ in signed_int_types:
|
||||
|
@ -82,14 +82,14 @@ class BitFieldTest(unittest.TestCase):
|
|||
("a", c_typ, 3),
|
||||
("b", c_typ, 3),
|
||||
("c", c_typ, 1)]
|
||||
self.failUnlessEqual(sizeof(X), sizeof(c_typ)*2)
|
||||
self.assertEqual(sizeof(X), sizeof(c_typ)*2)
|
||||
|
||||
x = X()
|
||||
self.failUnlessEqual((c_typ, x.a, x.b, x.c), (c_typ, 0, 0, 0))
|
||||
self.assertEqual((c_typ, x.a, x.b, x.c), (c_typ, 0, 0, 0))
|
||||
x.a = -1
|
||||
self.failUnlessEqual((c_typ, x.a, x.b, x.c), (c_typ, -1, 0, 0))
|
||||
self.assertEqual((c_typ, x.a, x.b, x.c), (c_typ, -1, 0, 0))
|
||||
x.a, x.b = 0, -1
|
||||
self.failUnlessEqual((c_typ, x.a, x.b, x.c), (c_typ, 0, -1, 0))
|
||||
self.assertEqual((c_typ, x.a, x.b, x.c), (c_typ, 0, -1, 0))
|
||||
|
||||
|
||||
def test_unsigned(self):
|
||||
|
@ -98,14 +98,14 @@ class BitFieldTest(unittest.TestCase):
|
|||
_fields_ = [("a", c_typ, 3),
|
||||
("b", c_typ, 3),
|
||||
("c", c_typ, 1)]
|
||||
self.failUnlessEqual(sizeof(X), sizeof(c_typ))
|
||||
self.assertEqual(sizeof(X), sizeof(c_typ))
|
||||
|
||||
x = X()
|
||||
self.failUnlessEqual((c_typ, x.a, x.b, x.c), (c_typ, 0, 0, 0))
|
||||
self.assertEqual((c_typ, x.a, x.b, x.c), (c_typ, 0, 0, 0))
|
||||
x.a = -1
|
||||
self.failUnlessEqual((c_typ, x.a, x.b, x.c), (c_typ, 7, 0, 0))
|
||||
self.assertEqual((c_typ, x.a, x.b, x.c), (c_typ, 7, 0, 0))
|
||||
x.a, x.b = 0, -1
|
||||
self.failUnlessEqual((c_typ, x.a, x.b, x.c), (c_typ, 0, 7, 0))
|
||||
self.assertEqual((c_typ, x.a, x.b, x.c), (c_typ, 0, 7, 0))
|
||||
|
||||
|
||||
def fail_fields(self, *fields):
|
||||
|
@ -115,17 +115,17 @@ class BitFieldTest(unittest.TestCase):
|
|||
def test_nonint_types(self):
|
||||
# bit fields are not allowed on non-integer types.
|
||||
result = self.fail_fields(("a", c_char_p, 1))
|
||||
self.failUnlessEqual(result, (TypeError, 'bit fields not allowed for type c_char_p'))
|
||||
self.assertEqual(result, (TypeError, 'bit fields not allowed for type c_char_p'))
|
||||
|
||||
result = self.fail_fields(("a", c_void_p, 1))
|
||||
self.failUnlessEqual(result, (TypeError, 'bit fields not allowed for type c_void_p'))
|
||||
self.assertEqual(result, (TypeError, 'bit fields not allowed for type c_void_p'))
|
||||
|
||||
if c_int != c_long:
|
||||
result = self.fail_fields(("a", POINTER(c_int), 1))
|
||||
self.failUnlessEqual(result, (TypeError, 'bit fields not allowed for type LP_c_int'))
|
||||
self.assertEqual(result, (TypeError, 'bit fields not allowed for type LP_c_int'))
|
||||
|
||||
result = self.fail_fields(("a", c_char, 1))
|
||||
self.failUnlessEqual(result, (TypeError, 'bit fields not allowed for type c_char'))
|
||||
self.assertEqual(result, (TypeError, 'bit fields not allowed for type c_char'))
|
||||
|
||||
try:
|
||||
c_wchar
|
||||
|
@ -133,59 +133,59 @@ class BitFieldTest(unittest.TestCase):
|
|||
pass
|
||||
else:
|
||||
result = self.fail_fields(("a", c_wchar, 1))
|
||||
self.failUnlessEqual(result, (TypeError, 'bit fields not allowed for type c_wchar'))
|
||||
self.assertEqual(result, (TypeError, 'bit fields not allowed for type c_wchar'))
|
||||
|
||||
class Dummy(Structure):
|
||||
_fields_ = []
|
||||
|
||||
result = self.fail_fields(("a", Dummy, 1))
|
||||
self.failUnlessEqual(result, (TypeError, 'bit fields not allowed for type Dummy'))
|
||||
self.assertEqual(result, (TypeError, 'bit fields not allowed for type Dummy'))
|
||||
|
||||
def test_single_bitfield_size(self):
|
||||
for c_typ in int_types:
|
||||
result = self.fail_fields(("a", c_typ, -1))
|
||||
self.failUnlessEqual(result, (ValueError, 'number of bits invalid for bit field'))
|
||||
self.assertEqual(result, (ValueError, 'number of bits invalid for bit field'))
|
||||
|
||||
result = self.fail_fields(("a", c_typ, 0))
|
||||
self.failUnlessEqual(result, (ValueError, 'number of bits invalid for bit field'))
|
||||
self.assertEqual(result, (ValueError, 'number of bits invalid for bit field'))
|
||||
|
||||
class X(Structure):
|
||||
_fields_ = [("a", c_typ, 1)]
|
||||
self.failUnlessEqual(sizeof(X), sizeof(c_typ))
|
||||
self.assertEqual(sizeof(X), sizeof(c_typ))
|
||||
|
||||
class X(Structure):
|
||||
_fields_ = [("a", c_typ, sizeof(c_typ)*8)]
|
||||
self.failUnlessEqual(sizeof(X), sizeof(c_typ))
|
||||
self.assertEqual(sizeof(X), sizeof(c_typ))
|
||||
|
||||
result = self.fail_fields(("a", c_typ, sizeof(c_typ)*8 + 1))
|
||||
self.failUnlessEqual(result, (ValueError, 'number of bits invalid for bit field'))
|
||||
self.assertEqual(result, (ValueError, 'number of bits invalid for bit field'))
|
||||
|
||||
def test_multi_bitfields_size(self):
|
||||
class X(Structure):
|
||||
_fields_ = [("a", c_short, 1),
|
||||
("b", c_short, 14),
|
||||
("c", c_short, 1)]
|
||||
self.failUnlessEqual(sizeof(X), sizeof(c_short))
|
||||
self.assertEqual(sizeof(X), sizeof(c_short))
|
||||
|
||||
class X(Structure):
|
||||
_fields_ = [("a", c_short, 1),
|
||||
("a1", c_short),
|
||||
("b", c_short, 14),
|
||||
("c", c_short, 1)]
|
||||
self.failUnlessEqual(sizeof(X), sizeof(c_short)*3)
|
||||
self.failUnlessEqual(X.a.offset, 0)
|
||||
self.failUnlessEqual(X.a1.offset, sizeof(c_short))
|
||||
self.failUnlessEqual(X.b.offset, sizeof(c_short)*2)
|
||||
self.failUnlessEqual(X.c.offset, sizeof(c_short)*2)
|
||||
self.assertEqual(sizeof(X), sizeof(c_short)*3)
|
||||
self.assertEqual(X.a.offset, 0)
|
||||
self.assertEqual(X.a1.offset, sizeof(c_short))
|
||||
self.assertEqual(X.b.offset, sizeof(c_short)*2)
|
||||
self.assertEqual(X.c.offset, sizeof(c_short)*2)
|
||||
|
||||
class X(Structure):
|
||||
_fields_ = [("a", c_short, 3),
|
||||
("b", c_short, 14),
|
||||
("c", c_short, 14)]
|
||||
self.failUnlessEqual(sizeof(X), sizeof(c_short)*3)
|
||||
self.failUnlessEqual(X.a.offset, sizeof(c_short)*0)
|
||||
self.failUnlessEqual(X.b.offset, sizeof(c_short)*1)
|
||||
self.failUnlessEqual(X.c.offset, sizeof(c_short)*2)
|
||||
self.assertEqual(sizeof(X), sizeof(c_short)*3)
|
||||
self.assertEqual(X.a.offset, sizeof(c_short)*0)
|
||||
self.assertEqual(X.b.offset, sizeof(c_short)*1)
|
||||
self.assertEqual(X.c.offset, sizeof(c_short)*2)
|
||||
|
||||
|
||||
def get_except(self, func, *args, **kw):
|
||||
|
@ -199,21 +199,21 @@ class BitFieldTest(unittest.TestCase):
|
|||
_fields_ = [("a", c_byte, 4),
|
||||
("b", c_int, 4)]
|
||||
if os.name in ("nt", "ce"):
|
||||
self.failUnlessEqual(sizeof(X), sizeof(c_int)*2)
|
||||
self.assertEqual(sizeof(X), sizeof(c_int)*2)
|
||||
else:
|
||||
self.failUnlessEqual(sizeof(X), sizeof(c_int))
|
||||
self.assertEqual(sizeof(X), sizeof(c_int))
|
||||
|
||||
def test_mixed_2(self):
|
||||
class X(Structure):
|
||||
_fields_ = [("a", c_byte, 4),
|
||||
("b", c_int, 32)]
|
||||
self.failUnlessEqual(sizeof(X), sizeof(c_int)*2)
|
||||
self.assertEqual(sizeof(X), sizeof(c_int)*2)
|
||||
|
||||
def test_mixed_3(self):
|
||||
class X(Structure):
|
||||
_fields_ = [("a", c_byte, 4),
|
||||
("b", c_ubyte, 4)]
|
||||
self.failUnlessEqual(sizeof(X), sizeof(c_byte))
|
||||
self.assertEqual(sizeof(X), sizeof(c_byte))
|
||||
|
||||
def test_mixed_4(self):
|
||||
class X(Structure):
|
||||
|
@ -227,9 +227,9 @@ class BitFieldTest(unittest.TestCase):
|
|||
# does (unless GCC is run with '-mms-bitfields' which
|
||||
# produces code compatible with MSVC).
|
||||
if os.name in ("nt", "ce"):
|
||||
self.failUnlessEqual(sizeof(X), sizeof(c_int) * 4)
|
||||
self.assertEqual(sizeof(X), sizeof(c_int) * 4)
|
||||
else:
|
||||
self.failUnlessEqual(sizeof(X), sizeof(c_int) * 2)
|
||||
self.assertEqual(sizeof(X), sizeof(c_int) * 2)
|
||||
|
||||
def test_anon_bitfields(self):
|
||||
# anonymous bit-fields gave a strange error message
|
||||
|
|
|
@ -5,32 +5,32 @@ class StringBufferTestCase(unittest.TestCase):
|
|||
|
||||
def test_buffer(self):
|
||||
b = create_string_buffer(32)
|
||||
self.failUnlessEqual(len(b), 32)
|
||||
self.failUnlessEqual(sizeof(b), 32 * sizeof(c_char))
|
||||
self.failUnless(type(b[0]) is str)
|
||||
self.assertEqual(len(b), 32)
|
||||
self.assertEqual(sizeof(b), 32 * sizeof(c_char))
|
||||
self.assertTrue(type(b[0]) is str)
|
||||
|
||||
b = create_string_buffer("abc")
|
||||
self.failUnlessEqual(len(b), 4) # trailing nul char
|
||||
self.failUnlessEqual(sizeof(b), 4 * sizeof(c_char))
|
||||
self.failUnless(type(b[0]) is str)
|
||||
self.failUnlessEqual(b[0], "a")
|
||||
self.failUnlessEqual(b[:], "abc\0")
|
||||
self.failUnlessEqual(b[::], "abc\0")
|
||||
self.failUnlessEqual(b[::-1], "\0cba")
|
||||
self.failUnlessEqual(b[::2], "ac")
|
||||
self.failUnlessEqual(b[::5], "a")
|
||||
self.assertEqual(len(b), 4) # trailing nul char
|
||||
self.assertEqual(sizeof(b), 4 * sizeof(c_char))
|
||||
self.assertTrue(type(b[0]) is str)
|
||||
self.assertEqual(b[0], "a")
|
||||
self.assertEqual(b[:], "abc\0")
|
||||
self.assertEqual(b[::], "abc\0")
|
||||
self.assertEqual(b[::-1], "\0cba")
|
||||
self.assertEqual(b[::2], "ac")
|
||||
self.assertEqual(b[::5], "a")
|
||||
|
||||
def test_string_conversion(self):
|
||||
b = create_string_buffer(u"abc")
|
||||
self.failUnlessEqual(len(b), 4) # trailing nul char
|
||||
self.failUnlessEqual(sizeof(b), 4 * sizeof(c_char))
|
||||
self.failUnless(type(b[0]) is str)
|
||||
self.failUnlessEqual(b[0], "a")
|
||||
self.failUnlessEqual(b[:], "abc\0")
|
||||
self.failUnlessEqual(b[::], "abc\0")
|
||||
self.failUnlessEqual(b[::-1], "\0cba")
|
||||
self.failUnlessEqual(b[::2], "ac")
|
||||
self.failUnlessEqual(b[::5], "a")
|
||||
self.assertEqual(len(b), 4) # trailing nul char
|
||||
self.assertEqual(sizeof(b), 4 * sizeof(c_char))
|
||||
self.assertTrue(type(b[0]) is str)
|
||||
self.assertEqual(b[0], "a")
|
||||
self.assertEqual(b[:], "abc\0")
|
||||
self.assertEqual(b[::], "abc\0")
|
||||
self.assertEqual(b[::-1], "\0cba")
|
||||
self.assertEqual(b[::2], "ac")
|
||||
self.assertEqual(b[::5], "a")
|
||||
|
||||
try:
|
||||
c_wchar
|
||||
|
@ -39,32 +39,32 @@ class StringBufferTestCase(unittest.TestCase):
|
|||
else:
|
||||
def test_unicode_buffer(self):
|
||||
b = create_unicode_buffer(32)
|
||||
self.failUnlessEqual(len(b), 32)
|
||||
self.failUnlessEqual(sizeof(b), 32 * sizeof(c_wchar))
|
||||
self.failUnless(type(b[0]) is unicode)
|
||||
self.assertEqual(len(b), 32)
|
||||
self.assertEqual(sizeof(b), 32 * sizeof(c_wchar))
|
||||
self.assertTrue(type(b[0]) is unicode)
|
||||
|
||||
b = create_unicode_buffer(u"abc")
|
||||
self.failUnlessEqual(len(b), 4) # trailing nul char
|
||||
self.failUnlessEqual(sizeof(b), 4 * sizeof(c_wchar))
|
||||
self.failUnless(type(b[0]) is unicode)
|
||||
self.failUnlessEqual(b[0], u"a")
|
||||
self.failUnlessEqual(b[:], "abc\0")
|
||||
self.failUnlessEqual(b[::], "abc\0")
|
||||
self.failUnlessEqual(b[::-1], "\0cba")
|
||||
self.failUnlessEqual(b[::2], "ac")
|
||||
self.failUnlessEqual(b[::5], "a")
|
||||
self.assertEqual(len(b), 4) # trailing nul char
|
||||
self.assertEqual(sizeof(b), 4 * sizeof(c_wchar))
|
||||
self.assertTrue(type(b[0]) is unicode)
|
||||
self.assertEqual(b[0], u"a")
|
||||
self.assertEqual(b[:], "abc\0")
|
||||
self.assertEqual(b[::], "abc\0")
|
||||
self.assertEqual(b[::-1], "\0cba")
|
||||
self.assertEqual(b[::2], "ac")
|
||||
self.assertEqual(b[::5], "a")
|
||||
|
||||
def test_unicode_conversion(self):
|
||||
b = create_unicode_buffer("abc")
|
||||
self.failUnlessEqual(len(b), 4) # trailing nul char
|
||||
self.failUnlessEqual(sizeof(b), 4 * sizeof(c_wchar))
|
||||
self.failUnless(type(b[0]) is unicode)
|
||||
self.failUnlessEqual(b[0], u"a")
|
||||
self.failUnlessEqual(b[:], "abc\0")
|
||||
self.failUnlessEqual(b[::], "abc\0")
|
||||
self.failUnlessEqual(b[::-1], "\0cba")
|
||||
self.failUnlessEqual(b[::2], "ac")
|
||||
self.failUnlessEqual(b[::5], "a")
|
||||
self.assertEqual(len(b), 4) # trailing nul char
|
||||
self.assertEqual(sizeof(b), 4 * sizeof(c_wchar))
|
||||
self.assertTrue(type(b[0]) is unicode)
|
||||
self.assertEqual(b[0], u"a")
|
||||
self.assertEqual(b[:], "abc\0")
|
||||
self.assertEqual(b[::], "abc\0")
|
||||
self.assertEqual(b[::-1], "\0cba")
|
||||
self.assertEqual(b[::2], "ac")
|
||||
self.assertEqual(b[::5], "a")
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
|
@ -23,131 +23,131 @@ class Test(unittest.TestCase):
|
|||
|
||||
def test_endian_short(self):
|
||||
if sys.byteorder == "little":
|
||||
self.failUnless(c_short.__ctype_le__ is c_short)
|
||||
self.failUnless(c_short.__ctype_be__.__ctype_le__ is c_short)
|
||||
self.assertTrue(c_short.__ctype_le__ is c_short)
|
||||
self.assertTrue(c_short.__ctype_be__.__ctype_le__ is c_short)
|
||||
else:
|
||||
self.failUnless(c_short.__ctype_be__ is c_short)
|
||||
self.failUnless(c_short.__ctype_le__.__ctype_be__ is c_short)
|
||||
self.assertTrue(c_short.__ctype_be__ is c_short)
|
||||
self.assertTrue(c_short.__ctype_le__.__ctype_be__ is c_short)
|
||||
s = c_short.__ctype_be__(0x1234)
|
||||
self.failUnlessEqual(bin(struct.pack(">h", 0x1234)), "1234")
|
||||
self.failUnlessEqual(bin(s), "1234")
|
||||
self.failUnlessEqual(s.value, 0x1234)
|
||||
self.assertEqual(bin(struct.pack(">h", 0x1234)), "1234")
|
||||
self.assertEqual(bin(s), "1234")
|
||||
self.assertEqual(s.value, 0x1234)
|
||||
|
||||
s = c_short.__ctype_le__(0x1234)
|
||||
self.failUnlessEqual(bin(struct.pack("<h", 0x1234)), "3412")
|
||||
self.failUnlessEqual(bin(s), "3412")
|
||||
self.failUnlessEqual(s.value, 0x1234)
|
||||
self.assertEqual(bin(struct.pack("<h", 0x1234)), "3412")
|
||||
self.assertEqual(bin(s), "3412")
|
||||
self.assertEqual(s.value, 0x1234)
|
||||
|
||||
s = c_ushort.__ctype_be__(0x1234)
|
||||
self.failUnlessEqual(bin(struct.pack(">h", 0x1234)), "1234")
|
||||
self.failUnlessEqual(bin(s), "1234")
|
||||
self.failUnlessEqual(s.value, 0x1234)
|
||||
self.assertEqual(bin(struct.pack(">h", 0x1234)), "1234")
|
||||
self.assertEqual(bin(s), "1234")
|
||||
self.assertEqual(s.value, 0x1234)
|
||||
|
||||
s = c_ushort.__ctype_le__(0x1234)
|
||||
self.failUnlessEqual(bin(struct.pack("<h", 0x1234)), "3412")
|
||||
self.failUnlessEqual(bin(s), "3412")
|
||||
self.failUnlessEqual(s.value, 0x1234)
|
||||
self.assertEqual(bin(struct.pack("<h", 0x1234)), "3412")
|
||||
self.assertEqual(bin(s), "3412")
|
||||
self.assertEqual(s.value, 0x1234)
|
||||
|
||||
def test_endian_int(self):
|
||||
if sys.byteorder == "little":
|
||||
self.failUnless(c_int.__ctype_le__ is c_int)
|
||||
self.failUnless(c_int.__ctype_be__.__ctype_le__ is c_int)
|
||||
self.assertTrue(c_int.__ctype_le__ is c_int)
|
||||
self.assertTrue(c_int.__ctype_be__.__ctype_le__ is c_int)
|
||||
else:
|
||||
self.failUnless(c_int.__ctype_be__ is c_int)
|
||||
self.failUnless(c_int.__ctype_le__.__ctype_be__ is c_int)
|
||||
self.assertTrue(c_int.__ctype_be__ is c_int)
|
||||
self.assertTrue(c_int.__ctype_le__.__ctype_be__ is c_int)
|
||||
|
||||
s = c_int.__ctype_be__(0x12345678)
|
||||
self.failUnlessEqual(bin(struct.pack(">i", 0x12345678)), "12345678")
|
||||
self.failUnlessEqual(bin(s), "12345678")
|
||||
self.failUnlessEqual(s.value, 0x12345678)
|
||||
self.assertEqual(bin(struct.pack(">i", 0x12345678)), "12345678")
|
||||
self.assertEqual(bin(s), "12345678")
|
||||
self.assertEqual(s.value, 0x12345678)
|
||||
|
||||
s = c_int.__ctype_le__(0x12345678)
|
||||
self.failUnlessEqual(bin(struct.pack("<i", 0x12345678)), "78563412")
|
||||
self.failUnlessEqual(bin(s), "78563412")
|
||||
self.failUnlessEqual(s.value, 0x12345678)
|
||||
self.assertEqual(bin(struct.pack("<i", 0x12345678)), "78563412")
|
||||
self.assertEqual(bin(s), "78563412")
|
||||
self.assertEqual(s.value, 0x12345678)
|
||||
|
||||
s = c_uint.__ctype_be__(0x12345678)
|
||||
self.failUnlessEqual(bin(struct.pack(">I", 0x12345678)), "12345678")
|
||||
self.failUnlessEqual(bin(s), "12345678")
|
||||
self.failUnlessEqual(s.value, 0x12345678)
|
||||
self.assertEqual(bin(struct.pack(">I", 0x12345678)), "12345678")
|
||||
self.assertEqual(bin(s), "12345678")
|
||||
self.assertEqual(s.value, 0x12345678)
|
||||
|
||||
s = c_uint.__ctype_le__(0x12345678)
|
||||
self.failUnlessEqual(bin(struct.pack("<I", 0x12345678)), "78563412")
|
||||
self.failUnlessEqual(bin(s), "78563412")
|
||||
self.failUnlessEqual(s.value, 0x12345678)
|
||||
self.assertEqual(bin(struct.pack("<I", 0x12345678)), "78563412")
|
||||
self.assertEqual(bin(s), "78563412")
|
||||
self.assertEqual(s.value, 0x12345678)
|
||||
|
||||
def test_endian_longlong(self):
|
||||
if sys.byteorder == "little":
|
||||
self.failUnless(c_longlong.__ctype_le__ is c_longlong)
|
||||
self.failUnless(c_longlong.__ctype_be__.__ctype_le__ is c_longlong)
|
||||
self.assertTrue(c_longlong.__ctype_le__ is c_longlong)
|
||||
self.assertTrue(c_longlong.__ctype_be__.__ctype_le__ is c_longlong)
|
||||
else:
|
||||
self.failUnless(c_longlong.__ctype_be__ is c_longlong)
|
||||
self.failUnless(c_longlong.__ctype_le__.__ctype_be__ is c_longlong)
|
||||
self.assertTrue(c_longlong.__ctype_be__ is c_longlong)
|
||||
self.assertTrue(c_longlong.__ctype_le__.__ctype_be__ is c_longlong)
|
||||
|
||||
s = c_longlong.__ctype_be__(0x1234567890ABCDEF)
|
||||
self.failUnlessEqual(bin(struct.pack(">q", 0x1234567890ABCDEF)), "1234567890ABCDEF")
|
||||
self.failUnlessEqual(bin(s), "1234567890ABCDEF")
|
||||
self.failUnlessEqual(s.value, 0x1234567890ABCDEF)
|
||||
self.assertEqual(bin(struct.pack(">q", 0x1234567890ABCDEF)), "1234567890ABCDEF")
|
||||
self.assertEqual(bin(s), "1234567890ABCDEF")
|
||||
self.assertEqual(s.value, 0x1234567890ABCDEF)
|
||||
|
||||
s = c_longlong.__ctype_le__(0x1234567890ABCDEF)
|
||||
self.failUnlessEqual(bin(struct.pack("<q", 0x1234567890ABCDEF)), "EFCDAB9078563412")
|
||||
self.failUnlessEqual(bin(s), "EFCDAB9078563412")
|
||||
self.failUnlessEqual(s.value, 0x1234567890ABCDEF)
|
||||
self.assertEqual(bin(struct.pack("<q", 0x1234567890ABCDEF)), "EFCDAB9078563412")
|
||||
self.assertEqual(bin(s), "EFCDAB9078563412")
|
||||
self.assertEqual(s.value, 0x1234567890ABCDEF)
|
||||
|
||||
s = c_ulonglong.__ctype_be__(0x1234567890ABCDEF)
|
||||
self.failUnlessEqual(bin(struct.pack(">Q", 0x1234567890ABCDEF)), "1234567890ABCDEF")
|
||||
self.failUnlessEqual(bin(s), "1234567890ABCDEF")
|
||||
self.failUnlessEqual(s.value, 0x1234567890ABCDEF)
|
||||
self.assertEqual(bin(struct.pack(">Q", 0x1234567890ABCDEF)), "1234567890ABCDEF")
|
||||
self.assertEqual(bin(s), "1234567890ABCDEF")
|
||||
self.assertEqual(s.value, 0x1234567890ABCDEF)
|
||||
|
||||
s = c_ulonglong.__ctype_le__(0x1234567890ABCDEF)
|
||||
self.failUnlessEqual(bin(struct.pack("<Q", 0x1234567890ABCDEF)), "EFCDAB9078563412")
|
||||
self.failUnlessEqual(bin(s), "EFCDAB9078563412")
|
||||
self.failUnlessEqual(s.value, 0x1234567890ABCDEF)
|
||||
self.assertEqual(bin(struct.pack("<Q", 0x1234567890ABCDEF)), "EFCDAB9078563412")
|
||||
self.assertEqual(bin(s), "EFCDAB9078563412")
|
||||
self.assertEqual(s.value, 0x1234567890ABCDEF)
|
||||
|
||||
def test_endian_float(self):
|
||||
if sys.byteorder == "little":
|
||||
self.failUnless(c_float.__ctype_le__ is c_float)
|
||||
self.failUnless(c_float.__ctype_be__.__ctype_le__ is c_float)
|
||||
self.assertTrue(c_float.__ctype_le__ is c_float)
|
||||
self.assertTrue(c_float.__ctype_be__.__ctype_le__ is c_float)
|
||||
else:
|
||||
self.failUnless(c_float.__ctype_be__ is c_float)
|
||||
self.failUnless(c_float.__ctype_le__.__ctype_be__ is c_float)
|
||||
self.assertTrue(c_float.__ctype_be__ is c_float)
|
||||
self.assertTrue(c_float.__ctype_le__.__ctype_be__ is c_float)
|
||||
s = c_float(math.pi)
|
||||
self.failUnlessEqual(bin(struct.pack("f", math.pi)), bin(s))
|
||||
self.assertEqual(bin(struct.pack("f", math.pi)), bin(s))
|
||||
# Hm, what's the precision of a float compared to a double?
|
||||
self.failUnlessAlmostEqual(s.value, math.pi, 6)
|
||||
self.assertAlmostEqual(s.value, math.pi, 6)
|
||||
s = c_float.__ctype_le__(math.pi)
|
||||
self.failUnlessAlmostEqual(s.value, math.pi, 6)
|
||||
self.failUnlessEqual(bin(struct.pack("<f", math.pi)), bin(s))
|
||||
self.assertAlmostEqual(s.value, math.pi, 6)
|
||||
self.assertEqual(bin(struct.pack("<f", math.pi)), bin(s))
|
||||
s = c_float.__ctype_be__(math.pi)
|
||||
self.failUnlessAlmostEqual(s.value, math.pi, 6)
|
||||
self.failUnlessEqual(bin(struct.pack(">f", math.pi)), bin(s))
|
||||
self.assertAlmostEqual(s.value, math.pi, 6)
|
||||
self.assertEqual(bin(struct.pack(">f", math.pi)), bin(s))
|
||||
|
||||
def test_endian_double(self):
|
||||
if sys.byteorder == "little":
|
||||
self.failUnless(c_double.__ctype_le__ is c_double)
|
||||
self.failUnless(c_double.__ctype_be__.__ctype_le__ is c_double)
|
||||
self.assertTrue(c_double.__ctype_le__ is c_double)
|
||||
self.assertTrue(c_double.__ctype_be__.__ctype_le__ is c_double)
|
||||
else:
|
||||
self.failUnless(c_double.__ctype_be__ is c_double)
|
||||
self.failUnless(c_double.__ctype_le__.__ctype_be__ is c_double)
|
||||
self.assertTrue(c_double.__ctype_be__ is c_double)
|
||||
self.assertTrue(c_double.__ctype_le__.__ctype_be__ is c_double)
|
||||
s = c_double(math.pi)
|
||||
self.failUnlessEqual(s.value, math.pi)
|
||||
self.failUnlessEqual(bin(struct.pack("d", math.pi)), bin(s))
|
||||
self.assertEqual(s.value, math.pi)
|
||||
self.assertEqual(bin(struct.pack("d", math.pi)), bin(s))
|
||||
s = c_double.__ctype_le__(math.pi)
|
||||
self.failUnlessEqual(s.value, math.pi)
|
||||
self.failUnlessEqual(bin(struct.pack("<d", math.pi)), bin(s))
|
||||
self.assertEqual(s.value, math.pi)
|
||||
self.assertEqual(bin(struct.pack("<d", math.pi)), bin(s))
|
||||
s = c_double.__ctype_be__(math.pi)
|
||||
self.failUnlessEqual(s.value, math.pi)
|
||||
self.failUnlessEqual(bin(struct.pack(">d", math.pi)), bin(s))
|
||||
self.assertEqual(s.value, math.pi)
|
||||
self.assertEqual(bin(struct.pack(">d", math.pi)), bin(s))
|
||||
|
||||
def test_endian_other(self):
|
||||
self.failUnless(c_byte.__ctype_le__ is c_byte)
|
||||
self.failUnless(c_byte.__ctype_be__ is c_byte)
|
||||
self.assertTrue(c_byte.__ctype_le__ is c_byte)
|
||||
self.assertTrue(c_byte.__ctype_be__ is c_byte)
|
||||
|
||||
self.failUnless(c_ubyte.__ctype_le__ is c_ubyte)
|
||||
self.failUnless(c_ubyte.__ctype_be__ is c_ubyte)
|
||||
self.assertTrue(c_ubyte.__ctype_le__ is c_ubyte)
|
||||
self.assertTrue(c_ubyte.__ctype_be__ is c_ubyte)
|
||||
|
||||
self.failUnless(c_char.__ctype_le__ is c_char)
|
||||
self.failUnless(c_char.__ctype_be__ is c_char)
|
||||
self.assertTrue(c_char.__ctype_le__ is c_char)
|
||||
self.assertTrue(c_char.__ctype_be__ is c_char)
|
||||
|
||||
def test_struct_fields_1(self):
|
||||
if sys.byteorder == "little":
|
||||
|
@ -219,7 +219,7 @@ class Test(unittest.TestCase):
|
|||
|
||||
s1 = S(0x12, 0x1234, 0x12345678, 3.14)
|
||||
s2 = struct.pack(fmt, 0x12, 0x1234, 0x12345678, 3.14)
|
||||
self.failUnlessEqual(bin(s1), bin(s2))
|
||||
self.assertEqual(bin(s1), bin(s2))
|
||||
|
||||
def test_unaligned_nonnative_struct_fields(self):
|
||||
if sys.byteorder == "little":
|
||||
|
@ -247,7 +247,7 @@ class Test(unittest.TestCase):
|
|||
s1.i = 0x12345678
|
||||
s1.d = 3.14
|
||||
s2 = struct.pack(fmt, 0x12, 0x1234, 0x12345678, 3.14)
|
||||
self.failUnlessEqual(bin(s1), bin(s2))
|
||||
self.assertEqual(bin(s1), bin(s2))
|
||||
|
||||
def test_unaligned_native_struct_fields(self):
|
||||
if sys.byteorder == "little":
|
||||
|
@ -274,7 +274,7 @@ class Test(unittest.TestCase):
|
|||
s1.i = 0x12345678
|
||||
s1.d = 3.14
|
||||
s2 = struct.pack(fmt, 0x12, 0x1234, 0x12345678, 3.14)
|
||||
self.failUnlessEqual(bin(s1), bin(s2))
|
||||
self.assertEqual(bin(s1), bin(s2))
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
|
@ -17,18 +17,18 @@ class Callbacks(unittest.TestCase):
|
|||
PROTO = self.functype.im_func(typ, typ)
|
||||
result = PROTO(self.callback)(arg)
|
||||
if typ == c_float:
|
||||
self.failUnlessAlmostEqual(result, arg, places=5)
|
||||
self.assertAlmostEqual(result, arg, places=5)
|
||||
else:
|
||||
self.failUnlessEqual(self.got_args, (arg,))
|
||||
self.failUnlessEqual(result, arg)
|
||||
self.assertEqual(self.got_args, (arg,))
|
||||
self.assertEqual(result, arg)
|
||||
|
||||
PROTO = self.functype.im_func(typ, c_byte, typ)
|
||||
result = PROTO(self.callback)(-3, arg)
|
||||
if typ == c_float:
|
||||
self.failUnlessAlmostEqual(result, arg, places=5)
|
||||
self.assertAlmostEqual(result, arg, places=5)
|
||||
else:
|
||||
self.failUnlessEqual(self.got_args, (-3, arg))
|
||||
self.failUnlessEqual(result, arg)
|
||||
self.assertEqual(self.got_args, (-3, arg))
|
||||
self.assertEqual(result, arg)
|
||||
|
||||
################
|
||||
|
||||
|
@ -103,7 +103,7 @@ class Callbacks(unittest.TestCase):
|
|||
# ...but this call doesn't leak any more. Where is the refcount?
|
||||
self.check_type(py_object, o)
|
||||
after = grc(o)
|
||||
self.failUnlessEqual((after, o), (before, o))
|
||||
self.assertEqual((after, o), (before, o))
|
||||
|
||||
def test_unsupported_restype_1(self):
|
||||
# Only "fundamental" result types are supported for callback
|
||||
|
@ -148,7 +148,7 @@ class SampleCallbacksTestCase(unittest.TestCase):
|
|||
result = integrate(0.0, 1.0, CALLBACK(func), 10)
|
||||
diff = abs(result - 1./3.)
|
||||
|
||||
self.failUnless(diff < 0.01, "%s not less than 0.01" % diff)
|
||||
self.assertTrue(diff < 0.01, "%s not less than 0.01" % diff)
|
||||
|
||||
################################################################
|
||||
|
||||
|
|
|
@ -9,15 +9,15 @@ class Test(unittest.TestCase):
|
|||
|
||||
# casting an array to a pointer works.
|
||||
ptr = cast(array, POINTER(c_int))
|
||||
self.failUnlessEqual([ptr[i] for i in range(3)], [42, 17, 2])
|
||||
self.assertEqual([ptr[i] for i in range(3)], [42, 17, 2])
|
||||
|
||||
if 2*sizeof(c_short) == sizeof(c_int):
|
||||
ptr = cast(array, POINTER(c_short))
|
||||
if sys.byteorder == "little":
|
||||
self.failUnlessEqual([ptr[i] for i in range(6)],
|
||||
self.assertEqual([ptr[i] for i in range(6)],
|
||||
[42, 0, 17, 0, 2, 0])
|
||||
else:
|
||||
self.failUnlessEqual([ptr[i] for i in range(6)],
|
||||
self.assertEqual([ptr[i] for i in range(6)],
|
||||
[0, 42, 0, 17, 0, 2])
|
||||
|
||||
def test_address2pointer(self):
|
||||
|
@ -25,54 +25,54 @@ class Test(unittest.TestCase):
|
|||
|
||||
address = addressof(array)
|
||||
ptr = cast(c_void_p(address), POINTER(c_int))
|
||||
self.failUnlessEqual([ptr[i] for i in range(3)], [42, 17, 2])
|
||||
self.assertEqual([ptr[i] for i in range(3)], [42, 17, 2])
|
||||
|
||||
ptr = cast(address, POINTER(c_int))
|
||||
self.failUnlessEqual([ptr[i] for i in range(3)], [42, 17, 2])
|
||||
self.assertEqual([ptr[i] for i in range(3)], [42, 17, 2])
|
||||
|
||||
def test_p2a_objects(self):
|
||||
array = (c_char_p * 5)()
|
||||
self.failUnlessEqual(array._objects, None)
|
||||
self.assertEqual(array._objects, None)
|
||||
array[0] = "foo bar"
|
||||
self.failUnlessEqual(array._objects, {'0': "foo bar"})
|
||||
self.assertEqual(array._objects, {'0': "foo bar"})
|
||||
|
||||
p = cast(array, POINTER(c_char_p))
|
||||
# array and p share a common _objects attribute
|
||||
self.failUnless(p._objects is array._objects)
|
||||
self.failUnlessEqual(array._objects, {'0': "foo bar", id(array): array})
|
||||
self.assertTrue(p._objects is array._objects)
|
||||
self.assertEqual(array._objects, {'0': "foo bar", id(array): array})
|
||||
p[0] = "spam spam"
|
||||
self.failUnlessEqual(p._objects, {'0': "spam spam", id(array): array})
|
||||
self.failUnless(array._objects is p._objects)
|
||||
self.assertEqual(p._objects, {'0': "spam spam", id(array): array})
|
||||
self.assertTrue(array._objects is p._objects)
|
||||
p[1] = "foo bar"
|
||||
self.failUnlessEqual(p._objects, {'1': 'foo bar', '0': "spam spam", id(array): array})
|
||||
self.failUnless(array._objects is p._objects)
|
||||
self.assertEqual(p._objects, {'1': 'foo bar', '0': "spam spam", id(array): array})
|
||||
self.assertTrue(array._objects is p._objects)
|
||||
|
||||
def test_other(self):
|
||||
p = cast((c_int * 4)(1, 2, 3, 4), POINTER(c_int))
|
||||
self.failUnlessEqual(p[:4], [1,2, 3, 4])
|
||||
self.failUnlessEqual(p[:4:], [1, 2, 3, 4])
|
||||
self.failUnlessEqual(p[3:-1:-1], [4, 3, 2, 1])
|
||||
self.failUnlessEqual(p[:4:3], [1, 4])
|
||||
self.assertEqual(p[:4], [1,2, 3, 4])
|
||||
self.assertEqual(p[:4:], [1, 2, 3, 4])
|
||||
self.assertEqual(p[3:-1:-1], [4, 3, 2, 1])
|
||||
self.assertEqual(p[:4:3], [1, 4])
|
||||
c_int()
|
||||
self.failUnlessEqual(p[:4], [1, 2, 3, 4])
|
||||
self.failUnlessEqual(p[:4:], [1, 2, 3, 4])
|
||||
self.failUnlessEqual(p[3:-1:-1], [4, 3, 2, 1])
|
||||
self.failUnlessEqual(p[:4:3], [1, 4])
|
||||
self.assertEqual(p[:4], [1, 2, 3, 4])
|
||||
self.assertEqual(p[:4:], [1, 2, 3, 4])
|
||||
self.assertEqual(p[3:-1:-1], [4, 3, 2, 1])
|
||||
self.assertEqual(p[:4:3], [1, 4])
|
||||
p[2] = 96
|
||||
self.failUnlessEqual(p[:4], [1, 2, 96, 4])
|
||||
self.failUnlessEqual(p[:4:], [1, 2, 96, 4])
|
||||
self.failUnlessEqual(p[3:-1:-1], [4, 96, 2, 1])
|
||||
self.failUnlessEqual(p[:4:3], [1, 4])
|
||||
self.assertEqual(p[:4], [1, 2, 96, 4])
|
||||
self.assertEqual(p[:4:], [1, 2, 96, 4])
|
||||
self.assertEqual(p[3:-1:-1], [4, 96, 2, 1])
|
||||
self.assertEqual(p[:4:3], [1, 4])
|
||||
c_int()
|
||||
self.failUnlessEqual(p[:4], [1, 2, 96, 4])
|
||||
self.failUnlessEqual(p[:4:], [1, 2, 96, 4])
|
||||
self.failUnlessEqual(p[3:-1:-1], [4, 96, 2, 1])
|
||||
self.failUnlessEqual(p[:4:3], [1, 4])
|
||||
self.assertEqual(p[:4], [1, 2, 96, 4])
|
||||
self.assertEqual(p[:4:], [1, 2, 96, 4])
|
||||
self.assertEqual(p[3:-1:-1], [4, 96, 2, 1])
|
||||
self.assertEqual(p[:4:3], [1, 4])
|
||||
|
||||
def test_char_p(self):
|
||||
# This didn't work: bad argument to internal function
|
||||
s = c_char_p("hiho")
|
||||
self.failUnlessEqual(cast(cast(s, c_void_p), c_char_p).value,
|
||||
self.assertEqual(cast(cast(s, c_void_p), c_char_p).value,
|
||||
"hiho")
|
||||
|
||||
try:
|
||||
|
@ -82,7 +82,7 @@ class Test(unittest.TestCase):
|
|||
else:
|
||||
def test_wchar_p(self):
|
||||
s = c_wchar_p("hiho")
|
||||
self.failUnlessEqual(cast(cast(s, c_void_p), c_wchar_p).value,
|
||||
self.assertEqual(cast(cast(s, c_void_p), c_wchar_p).value,
|
||||
"hiho")
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
@ -17,176 +17,176 @@ class CFunctions(unittest.TestCase):
|
|||
def test_byte(self):
|
||||
self._dll.tf_b.restype = c_byte
|
||||
self._dll.tf_b.argtypes = (c_byte,)
|
||||
self.failUnlessEqual(self._dll.tf_b(-126), -42)
|
||||
self.failUnlessEqual(self.S(), -126)
|
||||
self.assertEqual(self._dll.tf_b(-126), -42)
|
||||
self.assertEqual(self.S(), -126)
|
||||
|
||||
def test_byte_plus(self):
|
||||
self._dll.tf_bb.restype = c_byte
|
||||
self._dll.tf_bb.argtypes = (c_byte, c_byte)
|
||||
self.failUnlessEqual(self._dll.tf_bb(0, -126), -42)
|
||||
self.failUnlessEqual(self.S(), -126)
|
||||
self.assertEqual(self._dll.tf_bb(0, -126), -42)
|
||||
self.assertEqual(self.S(), -126)
|
||||
|
||||
def test_ubyte(self):
|
||||
self._dll.tf_B.restype = c_ubyte
|
||||
self._dll.tf_B.argtypes = (c_ubyte,)
|
||||
self.failUnlessEqual(self._dll.tf_B(255), 85)
|
||||
self.failUnlessEqual(self.U(), 255)
|
||||
self.assertEqual(self._dll.tf_B(255), 85)
|
||||
self.assertEqual(self.U(), 255)
|
||||
|
||||
def test_ubyte_plus(self):
|
||||
self._dll.tf_bB.restype = c_ubyte
|
||||
self._dll.tf_bB.argtypes = (c_byte, c_ubyte)
|
||||
self.failUnlessEqual(self._dll.tf_bB(0, 255), 85)
|
||||
self.failUnlessEqual(self.U(), 255)
|
||||
self.assertEqual(self._dll.tf_bB(0, 255), 85)
|
||||
self.assertEqual(self.U(), 255)
|
||||
|
||||
def test_short(self):
|
||||
self._dll.tf_h.restype = c_short
|
||||
self._dll.tf_h.argtypes = (c_short,)
|
||||
self.failUnlessEqual(self._dll.tf_h(-32766), -10922)
|
||||
self.failUnlessEqual(self.S(), -32766)
|
||||
self.assertEqual(self._dll.tf_h(-32766), -10922)
|
||||
self.assertEqual(self.S(), -32766)
|
||||
|
||||
def test_short_plus(self):
|
||||
self._dll.tf_bh.restype = c_short
|
||||
self._dll.tf_bh.argtypes = (c_byte, c_short)
|
||||
self.failUnlessEqual(self._dll.tf_bh(0, -32766), -10922)
|
||||
self.failUnlessEqual(self.S(), -32766)
|
||||
self.assertEqual(self._dll.tf_bh(0, -32766), -10922)
|
||||
self.assertEqual(self.S(), -32766)
|
||||
|
||||
def test_ushort(self):
|
||||
self._dll.tf_H.restype = c_ushort
|
||||
self._dll.tf_H.argtypes = (c_ushort,)
|
||||
self.failUnlessEqual(self._dll.tf_H(65535), 21845)
|
||||
self.failUnlessEqual(self.U(), 65535)
|
||||
self.assertEqual(self._dll.tf_H(65535), 21845)
|
||||
self.assertEqual(self.U(), 65535)
|
||||
|
||||
def test_ushort_plus(self):
|
||||
self._dll.tf_bH.restype = c_ushort
|
||||
self._dll.tf_bH.argtypes = (c_byte, c_ushort)
|
||||
self.failUnlessEqual(self._dll.tf_bH(0, 65535), 21845)
|
||||
self.failUnlessEqual(self.U(), 65535)
|
||||
self.assertEqual(self._dll.tf_bH(0, 65535), 21845)
|
||||
self.assertEqual(self.U(), 65535)
|
||||
|
||||
def test_int(self):
|
||||
self._dll.tf_i.restype = c_int
|
||||
self._dll.tf_i.argtypes = (c_int,)
|
||||
self.failUnlessEqual(self._dll.tf_i(-2147483646), -715827882)
|
||||
self.failUnlessEqual(self.S(), -2147483646)
|
||||
self.assertEqual(self._dll.tf_i(-2147483646), -715827882)
|
||||
self.assertEqual(self.S(), -2147483646)
|
||||
|
||||
def test_int_plus(self):
|
||||
self._dll.tf_bi.restype = c_int
|
||||
self._dll.tf_bi.argtypes = (c_byte, c_int)
|
||||
self.failUnlessEqual(self._dll.tf_bi(0, -2147483646), -715827882)
|
||||
self.failUnlessEqual(self.S(), -2147483646)
|
||||
self.assertEqual(self._dll.tf_bi(0, -2147483646), -715827882)
|
||||
self.assertEqual(self.S(), -2147483646)
|
||||
|
||||
def test_uint(self):
|
||||
self._dll.tf_I.restype = c_uint
|
||||
self._dll.tf_I.argtypes = (c_uint,)
|
||||
self.failUnlessEqual(self._dll.tf_I(4294967295), 1431655765)
|
||||
self.failUnlessEqual(self.U(), 4294967295)
|
||||
self.assertEqual(self._dll.tf_I(4294967295), 1431655765)
|
||||
self.assertEqual(self.U(), 4294967295)
|
||||
|
||||
def test_uint_plus(self):
|
||||
self._dll.tf_bI.restype = c_uint
|
||||
self._dll.tf_bI.argtypes = (c_byte, c_uint)
|
||||
self.failUnlessEqual(self._dll.tf_bI(0, 4294967295), 1431655765)
|
||||
self.failUnlessEqual(self.U(), 4294967295)
|
||||
self.assertEqual(self._dll.tf_bI(0, 4294967295), 1431655765)
|
||||
self.assertEqual(self.U(), 4294967295)
|
||||
|
||||
def test_long(self):
|
||||
self._dll.tf_l.restype = c_long
|
||||
self._dll.tf_l.argtypes = (c_long,)
|
||||
self.failUnlessEqual(self._dll.tf_l(-2147483646), -715827882)
|
||||
self.failUnlessEqual(self.S(), -2147483646)
|
||||
self.assertEqual(self._dll.tf_l(-2147483646), -715827882)
|
||||
self.assertEqual(self.S(), -2147483646)
|
||||
|
||||
def test_long_plus(self):
|
||||
self._dll.tf_bl.restype = c_long
|
||||
self._dll.tf_bl.argtypes = (c_byte, c_long)
|
||||
self.failUnlessEqual(self._dll.tf_bl(0, -2147483646), -715827882)
|
||||
self.failUnlessEqual(self.S(), -2147483646)
|
||||
self.assertEqual(self._dll.tf_bl(0, -2147483646), -715827882)
|
||||
self.assertEqual(self.S(), -2147483646)
|
||||
|
||||
def test_ulong(self):
|
||||
self._dll.tf_L.restype = c_ulong
|
||||
self._dll.tf_L.argtypes = (c_ulong,)
|
||||
self.failUnlessEqual(self._dll.tf_L(4294967295), 1431655765)
|
||||
self.failUnlessEqual(self.U(), 4294967295)
|
||||
self.assertEqual(self._dll.tf_L(4294967295), 1431655765)
|
||||
self.assertEqual(self.U(), 4294967295)
|
||||
|
||||
def test_ulong_plus(self):
|
||||
self._dll.tf_bL.restype = c_ulong
|
||||
self._dll.tf_bL.argtypes = (c_char, c_ulong)
|
||||
self.failUnlessEqual(self._dll.tf_bL(' ', 4294967295), 1431655765)
|
||||
self.failUnlessEqual(self.U(), 4294967295)
|
||||
self.assertEqual(self._dll.tf_bL(' ', 4294967295), 1431655765)
|
||||
self.assertEqual(self.U(), 4294967295)
|
||||
|
||||
def test_longlong(self):
|
||||
self._dll.tf_q.restype = c_longlong
|
||||
self._dll.tf_q.argtypes = (c_longlong, )
|
||||
self.failUnlessEqual(self._dll.tf_q(-9223372036854775806), -3074457345618258602)
|
||||
self.failUnlessEqual(self.S(), -9223372036854775806)
|
||||
self.assertEqual(self._dll.tf_q(-9223372036854775806), -3074457345618258602)
|
||||
self.assertEqual(self.S(), -9223372036854775806)
|
||||
|
||||
def test_longlong_plus(self):
|
||||
self._dll.tf_bq.restype = c_longlong
|
||||
self._dll.tf_bq.argtypes = (c_byte, c_longlong)
|
||||
self.failUnlessEqual(self._dll.tf_bq(0, -9223372036854775806), -3074457345618258602)
|
||||
self.failUnlessEqual(self.S(), -9223372036854775806)
|
||||
self.assertEqual(self._dll.tf_bq(0, -9223372036854775806), -3074457345618258602)
|
||||
self.assertEqual(self.S(), -9223372036854775806)
|
||||
|
||||
def test_ulonglong(self):
|
||||
self._dll.tf_Q.restype = c_ulonglong
|
||||
self._dll.tf_Q.argtypes = (c_ulonglong, )
|
||||
self.failUnlessEqual(self._dll.tf_Q(18446744073709551615), 6148914691236517205)
|
||||
self.failUnlessEqual(self.U(), 18446744073709551615)
|
||||
self.assertEqual(self._dll.tf_Q(18446744073709551615), 6148914691236517205)
|
||||
self.assertEqual(self.U(), 18446744073709551615)
|
||||
|
||||
def test_ulonglong_plus(self):
|
||||
self._dll.tf_bQ.restype = c_ulonglong
|
||||
self._dll.tf_bQ.argtypes = (c_byte, c_ulonglong)
|
||||
self.failUnlessEqual(self._dll.tf_bQ(0, 18446744073709551615), 6148914691236517205)
|
||||
self.failUnlessEqual(self.U(), 18446744073709551615)
|
||||
self.assertEqual(self._dll.tf_bQ(0, 18446744073709551615), 6148914691236517205)
|
||||
self.assertEqual(self.U(), 18446744073709551615)
|
||||
|
||||
def test_float(self):
|
||||
self._dll.tf_f.restype = c_float
|
||||
self._dll.tf_f.argtypes = (c_float,)
|
||||
self.failUnlessEqual(self._dll.tf_f(-42.), -14.)
|
||||
self.failUnlessEqual(self.S(), -42)
|
||||
self.assertEqual(self._dll.tf_f(-42.), -14.)
|
||||
self.assertEqual(self.S(), -42)
|
||||
|
||||
def test_float_plus(self):
|
||||
self._dll.tf_bf.restype = c_float
|
||||
self._dll.tf_bf.argtypes = (c_byte, c_float)
|
||||
self.failUnlessEqual(self._dll.tf_bf(0, -42.), -14.)
|
||||
self.failUnlessEqual(self.S(), -42)
|
||||
self.assertEqual(self._dll.tf_bf(0, -42.), -14.)
|
||||
self.assertEqual(self.S(), -42)
|
||||
|
||||
def test_double(self):
|
||||
self._dll.tf_d.restype = c_double
|
||||
self._dll.tf_d.argtypes = (c_double,)
|
||||
self.failUnlessEqual(self._dll.tf_d(42.), 14.)
|
||||
self.failUnlessEqual(self.S(), 42)
|
||||
self.assertEqual(self._dll.tf_d(42.), 14.)
|
||||
self.assertEqual(self.S(), 42)
|
||||
|
||||
def test_double_plus(self):
|
||||
self._dll.tf_bd.restype = c_double
|
||||
self._dll.tf_bd.argtypes = (c_byte, c_double)
|
||||
self.failUnlessEqual(self._dll.tf_bd(0, 42.), 14.)
|
||||
self.failUnlessEqual(self.S(), 42)
|
||||
self.assertEqual(self._dll.tf_bd(0, 42.), 14.)
|
||||
self.assertEqual(self.S(), 42)
|
||||
|
||||
def test_longdouble(self):
|
||||
self._dll.tf_D.restype = c_longdouble
|
||||
self._dll.tf_D.argtypes = (c_longdouble,)
|
||||
self.failUnlessEqual(self._dll.tf_D(42.), 14.)
|
||||
self.failUnlessEqual(self.S(), 42)
|
||||
self.assertEqual(self._dll.tf_D(42.), 14.)
|
||||
self.assertEqual(self.S(), 42)
|
||||
|
||||
def test_longdouble_plus(self):
|
||||
self._dll.tf_bD.restype = c_longdouble
|
||||
self._dll.tf_bD.argtypes = (c_byte, c_longdouble)
|
||||
self.failUnlessEqual(self._dll.tf_bD(0, 42.), 14.)
|
||||
self.failUnlessEqual(self.S(), 42)
|
||||
self.assertEqual(self._dll.tf_bD(0, 42.), 14.)
|
||||
self.assertEqual(self.S(), 42)
|
||||
|
||||
def test_callwithresult(self):
|
||||
def process_result(result):
|
||||
return result * 2
|
||||
self._dll.tf_i.restype = process_result
|
||||
self._dll.tf_i.argtypes = (c_int,)
|
||||
self.failUnlessEqual(self._dll.tf_i(42), 28)
|
||||
self.failUnlessEqual(self.S(), 42)
|
||||
self.failUnlessEqual(self._dll.tf_i(-42), -28)
|
||||
self.failUnlessEqual(self.S(), -42)
|
||||
self.assertEqual(self._dll.tf_i(42), 28)
|
||||
self.assertEqual(self.S(), 42)
|
||||
self.assertEqual(self._dll.tf_i(-42), -28)
|
||||
self.assertEqual(self.S(), -42)
|
||||
|
||||
def test_void(self):
|
||||
self._dll.tv_i.restype = None
|
||||
self._dll.tv_i.argtypes = (c_int,)
|
||||
self.failUnlessEqual(self._dll.tv_i(42), None)
|
||||
self.failUnlessEqual(self.S(), 42)
|
||||
self.failUnlessEqual(self._dll.tv_i(-42), None)
|
||||
self.failUnlessEqual(self.S(), -42)
|
||||
self.assertEqual(self._dll.tv_i(42), None)
|
||||
self.assertEqual(self.S(), 42)
|
||||
self.assertEqual(self._dll.tv_i(-42), None)
|
||||
self.assertEqual(self.S(), -42)
|
||||
|
||||
# The following repeates the above tests with stdcall functions (where
|
||||
# they are available)
|
||||
|
|
|
@ -14,16 +14,16 @@ class Test(unittest.TestCase):
|
|||
|
||||
import _ctypes_test
|
||||
dll = CDLL(_ctypes_test.__file__)
|
||||
self.failUnlessEqual(42, dll._testfunc_p_p(42))
|
||||
self.assertEqual(42, dll._testfunc_p_p(42))
|
||||
|
||||
dll._testfunc_p_p.restype = CHECKED
|
||||
self.failUnlessEqual("42", dll._testfunc_p_p(42))
|
||||
self.assertEqual("42", dll._testfunc_p_p(42))
|
||||
|
||||
dll._testfunc_p_p.restype = None
|
||||
self.failUnlessEqual(None, dll._testfunc_p_p(42))
|
||||
self.assertEqual(None, dll._testfunc_p_p(42))
|
||||
|
||||
del dll._testfunc_p_p.restype
|
||||
self.failUnlessEqual(42, dll._testfunc_p_p(42))
|
||||
self.assertEqual(42, dll._testfunc_p_p(42))
|
||||
|
||||
try:
|
||||
oledll
|
||||
|
@ -31,7 +31,7 @@ class Test(unittest.TestCase):
|
|||
pass
|
||||
else:
|
||||
def test_oledll(self):
|
||||
self.failUnlessRaises(WindowsError,
|
||||
self.assertRaises(WindowsError,
|
||||
oledll.oleaut32.CreateTypeLib2,
|
||||
0, None, None)
|
||||
|
||||
|
|
|
@ -15,11 +15,11 @@ class Test(unittest.TestCase):
|
|||
|
||||
libc_open.argtypes = c_char_p, c_int
|
||||
|
||||
self.failUnlessEqual(libc_open("", 0), -1)
|
||||
self.failUnlessEqual(get_errno(), errno.ENOENT)
|
||||
self.assertEqual(libc_open("", 0), -1)
|
||||
self.assertEqual(get_errno(), errno.ENOENT)
|
||||
|
||||
self.failUnlessEqual(set_errno(32), errno.ENOENT)
|
||||
self.failUnlessEqual(get_errno(), 32)
|
||||
self.assertEqual(set_errno(32), errno.ENOENT)
|
||||
self.assertEqual(get_errno(), 32)
|
||||
|
||||
|
||||
def _worker():
|
||||
|
@ -31,14 +31,14 @@ class Test(unittest.TestCase):
|
|||
else:
|
||||
libc_open = libc.open
|
||||
libc_open.argtypes = c_char_p, c_int
|
||||
self.failUnlessEqual(libc_open("", 0), -1)
|
||||
self.failUnlessEqual(get_errno(), 0)
|
||||
self.assertEqual(libc_open("", 0), -1)
|
||||
self.assertEqual(get_errno(), 0)
|
||||
|
||||
t = threading.Thread(target=_worker)
|
||||
t.start()
|
||||
t.join()
|
||||
|
||||
self.failUnlessEqual(get_errno(), 32)
|
||||
self.assertEqual(get_errno(), 32)
|
||||
set_errno(0)
|
||||
|
||||
if os.name == "nt":
|
||||
|
@ -48,11 +48,11 @@ class Test(unittest.TestCase):
|
|||
GetModuleHandle = dll.GetModuleHandleA
|
||||
GetModuleHandle.argtypes = [c_wchar_p]
|
||||
|
||||
self.failUnlessEqual(0, GetModuleHandle("foo"))
|
||||
self.failUnlessEqual(get_last_error(), 126)
|
||||
self.assertEqual(0, GetModuleHandle("foo"))
|
||||
self.assertEqual(get_last_error(), 126)
|
||||
|
||||
self.failUnlessEqual(set_last_error(32), 126)
|
||||
self.failUnlessEqual(get_last_error(), 32)
|
||||
self.assertEqual(set_last_error(32), 126)
|
||||
self.assertEqual(get_last_error(), 32)
|
||||
|
||||
def _worker():
|
||||
set_last_error(0)
|
||||
|
@ -62,13 +62,13 @@ class Test(unittest.TestCase):
|
|||
GetModuleHandle.argtypes = [c_wchar_p]
|
||||
GetModuleHandle("bar")
|
||||
|
||||
self.failUnlessEqual(get_last_error(), 0)
|
||||
self.assertEqual(get_last_error(), 0)
|
||||
|
||||
t = threading.Thread(target=_worker)
|
||||
t.start()
|
||||
t.join()
|
||||
|
||||
self.failUnlessEqual(get_last_error(), 32)
|
||||
self.assertEqual(get_last_error(), 32)
|
||||
|
||||
set_last_error(0)
|
||||
|
||||
|
|
|
@ -76,7 +76,7 @@ class Test_OpenGL_libs(unittest.TestCase):
|
|||
## sqrt = libm.sqrt
|
||||
## sqrt.argtypes = (c_double,)
|
||||
## sqrt.restype = c_double
|
||||
## self.failUnlessEqual(sqrt(2), math.sqrt(2))
|
||||
## self.assertEqual(sqrt(2), math.sqrt(2))
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
|
@ -16,14 +16,14 @@ class Test(unittest.TestCase):
|
|||
|
||||
y = X.from_buffer(a)
|
||||
self.assertEqual(y.c_int, a[0])
|
||||
self.failIf(y.init_called)
|
||||
self.assertFalse(y.init_called)
|
||||
|
||||
self.assertEqual(x[:], a.tolist())
|
||||
|
||||
a[0], a[-1] = 200, -200
|
||||
self.assertEqual(x[:], a.tolist())
|
||||
|
||||
self.assert_(a in x._objects.values())
|
||||
self.assertTrue(a in x._objects.values())
|
||||
|
||||
self.assertRaises(ValueError,
|
||||
c_int.from_buffer, a, -1)
|
||||
|
@ -49,7 +49,7 @@ class Test(unittest.TestCase):
|
|||
|
||||
y = X.from_buffer_copy(a)
|
||||
self.assertEqual(y.c_int, a[0])
|
||||
self.failIf(y.init_called)
|
||||
self.assertFalse(y.init_called)
|
||||
|
||||
self.assertEqual(x[:], range(16))
|
||||
|
||||
|
|
|
@ -18,10 +18,10 @@ class CFuncPtrTestCase(unittest.TestCase):
|
|||
return len(args)
|
||||
|
||||
x = X(func)
|
||||
self.failUnlessEqual(x.restype, c_int)
|
||||
self.failUnlessEqual(x.argtypes, (c_int, c_int))
|
||||
self.failUnlessEqual(sizeof(x), sizeof(c_voidp))
|
||||
self.failUnlessEqual(sizeof(X), sizeof(c_voidp))
|
||||
self.assertEqual(x.restype, c_int)
|
||||
self.assertEqual(x.argtypes, (c_int, c_int))
|
||||
self.assertEqual(sizeof(x), sizeof(c_voidp))
|
||||
self.assertEqual(sizeof(X), sizeof(c_voidp))
|
||||
|
||||
def test_first(self):
|
||||
StdCallback = WINFUNCTYPE(c_int, c_int, c_int)
|
||||
|
@ -33,12 +33,12 @@ class CFuncPtrTestCase(unittest.TestCase):
|
|||
s = StdCallback(func)
|
||||
c = CdeclCallback(func)
|
||||
|
||||
self.failUnlessEqual(s(1, 2), 3)
|
||||
self.failUnlessEqual(c(1, 2), 3)
|
||||
self.assertEqual(s(1, 2), 3)
|
||||
self.assertEqual(c(1, 2), 3)
|
||||
# The following no longer raises a TypeError - it is now
|
||||
# possible, as in C, to call cdecl functions with more parameters.
|
||||
#self.assertRaises(TypeError, c, 1, 2, 3)
|
||||
self.failUnlessEqual(c(1, 2, 3, 4, 5, 6), 3)
|
||||
self.assertEqual(c(1, 2, 3, 4, 5, 6), 3)
|
||||
if not WINFUNCTYPE is CFUNCTYPE and os.name != "ce":
|
||||
self.assertRaises(TypeError, s, 1, 2, 3)
|
||||
|
||||
|
@ -75,9 +75,9 @@ class CFuncPtrTestCase(unittest.TestCase):
|
|||
## "lpfnWndProc", WNDPROC_2(wndproc))
|
||||
# instead:
|
||||
|
||||
self.failUnless(WNDPROC is WNDPROC_2)
|
||||
self.assertTrue(WNDPROC is WNDPROC_2)
|
||||
# 'wndclass.lpfnWndProc' leaks 94 references. Why?
|
||||
self.failUnlessEqual(wndclass.lpfnWndProc(1, 2, 3, 4), 10)
|
||||
self.assertEqual(wndclass.lpfnWndProc(1, 2, 3, 4), 10)
|
||||
|
||||
|
||||
f = wndclass.lpfnWndProc
|
||||
|
@ -85,7 +85,7 @@ class CFuncPtrTestCase(unittest.TestCase):
|
|||
del wndclass
|
||||
del wndproc
|
||||
|
||||
self.failUnlessEqual(f(10, 11, 12, 13), 46)
|
||||
self.assertEqual(f(10, 11, 12, 13), 46)
|
||||
|
||||
def test_dllfunctions(self):
|
||||
|
||||
|
@ -97,8 +97,8 @@ class CFuncPtrTestCase(unittest.TestCase):
|
|||
strchr = lib.my_strchr
|
||||
strchr.restype = c_char_p
|
||||
strchr.argtypes = (c_char_p, c_char)
|
||||
self.failUnlessEqual(strchr("abcdefghi", "b"), "bcdefghi")
|
||||
self.failUnlessEqual(strchr("abcdefghi", "x"), None)
|
||||
self.assertEqual(strchr("abcdefghi", "b"), "bcdefghi")
|
||||
self.assertEqual(strchr("abcdefghi", "x"), None)
|
||||
|
||||
|
||||
strtok = lib.my_strtok
|
||||
|
@ -118,10 +118,10 @@ class CFuncPtrTestCase(unittest.TestCase):
|
|||
## b.value = s
|
||||
|
||||
## b = c_string(s)
|
||||
self.failUnlessEqual(strtok(b, "\n"), "a")
|
||||
self.failUnlessEqual(strtok(None, "\n"), "b")
|
||||
self.failUnlessEqual(strtok(None, "\n"), "c")
|
||||
self.failUnlessEqual(strtok(None, "\n"), None)
|
||||
self.assertEqual(strtok(b, "\n"), "a")
|
||||
self.assertEqual(strtok(None, "\n"), "b")
|
||||
self.assertEqual(strtok(None, "\n"), "c")
|
||||
self.assertEqual(strtok(None, "\n"), None)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -71,8 +71,8 @@ class FunctionTestCase(unittest.TestCase):
|
|||
f = dll._testfunc_i_bhilfd
|
||||
f.argtypes = [c_byte, c_wchar, c_int, c_long, c_float, c_double]
|
||||
result = f(1, u"x", 3, 4, 5.0, 6.0)
|
||||
self.failUnlessEqual(result, 139)
|
||||
self.failUnlessEqual(type(result), int)
|
||||
self.assertEqual(result, 139)
|
||||
self.assertEqual(type(result), int)
|
||||
|
||||
def test_wchar_result(self):
|
||||
try:
|
||||
|
@ -83,38 +83,38 @@ class FunctionTestCase(unittest.TestCase):
|
|||
f.argtypes = [c_byte, c_short, c_int, c_long, c_float, c_double]
|
||||
f.restype = c_wchar
|
||||
result = f(0, 0, 0, 0, 0, 0)
|
||||
self.failUnlessEqual(result, u'\x00')
|
||||
self.assertEqual(result, u'\x00')
|
||||
|
||||
def test_voidresult(self):
|
||||
f = dll._testfunc_v
|
||||
f.restype = None
|
||||
f.argtypes = [c_int, c_int, POINTER(c_int)]
|
||||
result = c_int()
|
||||
self.failUnlessEqual(None, f(1, 2, byref(result)))
|
||||
self.failUnlessEqual(result.value, 3)
|
||||
self.assertEqual(None, f(1, 2, byref(result)))
|
||||
self.assertEqual(result.value, 3)
|
||||
|
||||
def test_intresult(self):
|
||||
f = dll._testfunc_i_bhilfd
|
||||
f.argtypes = [c_byte, c_short, c_int, c_long, c_float, c_double]
|
||||
f.restype = c_int
|
||||
result = f(1, 2, 3, 4, 5.0, 6.0)
|
||||
self.failUnlessEqual(result, 21)
|
||||
self.failUnlessEqual(type(result), int)
|
||||
self.assertEqual(result, 21)
|
||||
self.assertEqual(type(result), int)
|
||||
|
||||
result = f(-1, -2, -3, -4, -5.0, -6.0)
|
||||
self.failUnlessEqual(result, -21)
|
||||
self.failUnlessEqual(type(result), int)
|
||||
self.assertEqual(result, -21)
|
||||
self.assertEqual(type(result), int)
|
||||
|
||||
# If we declare the function to return a short,
|
||||
# is the high part split off?
|
||||
f.restype = c_short
|
||||
result = f(1, 2, 3, 4, 5.0, 6.0)
|
||||
self.failUnlessEqual(result, 21)
|
||||
self.failUnlessEqual(type(result), int)
|
||||
self.assertEqual(result, 21)
|
||||
self.assertEqual(type(result), int)
|
||||
|
||||
result = f(1, 2, 3, 0x10004, 5.0, 6.0)
|
||||
self.failUnlessEqual(result, 21)
|
||||
self.failUnlessEqual(type(result), int)
|
||||
self.assertEqual(result, 21)
|
||||
self.assertEqual(type(result), int)
|
||||
|
||||
# You cannot assing character format codes as restype any longer
|
||||
self.assertRaises(TypeError, setattr, f, "restype", "i")
|
||||
|
@ -124,36 +124,36 @@ class FunctionTestCase(unittest.TestCase):
|
|||
f.argtypes = [c_byte, c_short, c_int, c_long, c_float, c_double]
|
||||
f.restype = c_float
|
||||
result = f(1, 2, 3, 4, 5.0, 6.0)
|
||||
self.failUnlessEqual(result, 21)
|
||||
self.failUnlessEqual(type(result), float)
|
||||
self.assertEqual(result, 21)
|
||||
self.assertEqual(type(result), float)
|
||||
|
||||
result = f(-1, -2, -3, -4, -5.0, -6.0)
|
||||
self.failUnlessEqual(result, -21)
|
||||
self.failUnlessEqual(type(result), float)
|
||||
self.assertEqual(result, -21)
|
||||
self.assertEqual(type(result), float)
|
||||
|
||||
def test_doubleresult(self):
|
||||
f = dll._testfunc_d_bhilfd
|
||||
f.argtypes = [c_byte, c_short, c_int, c_long, c_float, c_double]
|
||||
f.restype = c_double
|
||||
result = f(1, 2, 3, 4, 5.0, 6.0)
|
||||
self.failUnlessEqual(result, 21)
|
||||
self.failUnlessEqual(type(result), float)
|
||||
self.assertEqual(result, 21)
|
||||
self.assertEqual(type(result), float)
|
||||
|
||||
result = f(-1, -2, -3, -4, -5.0, -6.0)
|
||||
self.failUnlessEqual(result, -21)
|
||||
self.failUnlessEqual(type(result), float)
|
||||
self.assertEqual(result, -21)
|
||||
self.assertEqual(type(result), float)
|
||||
|
||||
def test_longdoubleresult(self):
|
||||
f = dll._testfunc_D_bhilfD
|
||||
f.argtypes = [c_byte, c_short, c_int, c_long, c_float, c_longdouble]
|
||||
f.restype = c_longdouble
|
||||
result = f(1, 2, 3, 4, 5.0, 6.0)
|
||||
self.failUnlessEqual(result, 21)
|
||||
self.failUnlessEqual(type(result), float)
|
||||
self.assertEqual(result, 21)
|
||||
self.assertEqual(type(result), float)
|
||||
|
||||
result = f(-1, -2, -3, -4, -5.0, -6.0)
|
||||
self.failUnlessEqual(result, -21)
|
||||
self.failUnlessEqual(type(result), float)
|
||||
self.assertEqual(result, -21)
|
||||
self.assertEqual(type(result), float)
|
||||
|
||||
def test_longlongresult(self):
|
||||
try:
|
||||
|
@ -164,23 +164,23 @@ class FunctionTestCase(unittest.TestCase):
|
|||
f.restype = c_longlong
|
||||
f.argtypes = [c_byte, c_short, c_int, c_long, c_float, c_double]
|
||||
result = f(1, 2, 3, 4, 5.0, 6.0)
|
||||
self.failUnlessEqual(result, 21)
|
||||
self.assertEqual(result, 21)
|
||||
|
||||
f = dll._testfunc_q_bhilfdq
|
||||
f.restype = c_longlong
|
||||
f.argtypes = [c_byte, c_short, c_int, c_long, c_float, c_double, c_longlong]
|
||||
result = f(1, 2, 3, 4, 5.0, 6.0, 21)
|
||||
self.failUnlessEqual(result, 42)
|
||||
self.assertEqual(result, 42)
|
||||
|
||||
def test_stringresult(self):
|
||||
f = dll._testfunc_p_p
|
||||
f.argtypes = None
|
||||
f.restype = c_char_p
|
||||
result = f("123")
|
||||
self.failUnlessEqual(result, "123")
|
||||
self.assertEqual(result, "123")
|
||||
|
||||
result = f(None)
|
||||
self.failUnlessEqual(result, None)
|
||||
self.assertEqual(result, None)
|
||||
|
||||
def test_pointers(self):
|
||||
f = dll._testfunc_p_p
|
||||
|
@ -193,29 +193,29 @@ class FunctionTestCase(unittest.TestCase):
|
|||
|
||||
v = c_int(42)
|
||||
|
||||
self.failUnlessEqual(pointer(v).contents.value, 42)
|
||||
self.assertEqual(pointer(v).contents.value, 42)
|
||||
result = f(pointer(v))
|
||||
self.failUnlessEqual(type(result), POINTER(c_int))
|
||||
self.failUnlessEqual(result.contents.value, 42)
|
||||
self.assertEqual(type(result), POINTER(c_int))
|
||||
self.assertEqual(result.contents.value, 42)
|
||||
|
||||
# This on works...
|
||||
result = f(pointer(v))
|
||||
self.failUnlessEqual(result.contents.value, v.value)
|
||||
self.assertEqual(result.contents.value, v.value)
|
||||
|
||||
p = pointer(c_int(99))
|
||||
result = f(p)
|
||||
self.failUnlessEqual(result.contents.value, 99)
|
||||
self.assertEqual(result.contents.value, 99)
|
||||
|
||||
arg = byref(v)
|
||||
result = f(arg)
|
||||
self.failIfEqual(result.contents, v.value)
|
||||
self.assertNotEqual(result.contents, v.value)
|
||||
|
||||
self.assertRaises(ArgumentError, f, byref(c_short(22)))
|
||||
|
||||
# It is dangerous, however, because you don't control the lifetime
|
||||
# of the pointer:
|
||||
result = f(byref(c_int(99)))
|
||||
self.failIfEqual(result.contents, 99)
|
||||
self.assertNotEqual(result.contents, 99)
|
||||
|
||||
def test_errors(self):
|
||||
f = dll._testfunc_p_p
|
||||
|
@ -242,7 +242,7 @@ class FunctionTestCase(unittest.TestCase):
|
|||
|
||||
cb = CallBack(callback)
|
||||
f(2**18, cb)
|
||||
self.failUnlessEqual(args, expected)
|
||||
self.assertEqual(args, expected)
|
||||
|
||||
################################################################
|
||||
|
||||
|
@ -259,13 +259,13 @@ class FunctionTestCase(unittest.TestCase):
|
|||
|
||||
cb = MyCallback(callback)
|
||||
result = f(-10, cb)
|
||||
self.failUnlessEqual(result, -18)
|
||||
self.assertEqual(result, -18)
|
||||
|
||||
# test with prototype
|
||||
f.argtypes = [c_int, MyCallback]
|
||||
cb = MyCallback(callback)
|
||||
result = f(-10, cb)
|
||||
self.failUnlessEqual(result, -18)
|
||||
self.assertEqual(result, -18)
|
||||
|
||||
AnotherCallback = WINFUNCTYPE(c_int, c_int, c_int, c_int, c_int)
|
||||
|
||||
|
@ -288,12 +288,12 @@ class FunctionTestCase(unittest.TestCase):
|
|||
|
||||
def callback(value):
|
||||
#print "called back with", value
|
||||
self.failUnlessEqual(type(value), int)
|
||||
self.assertEqual(type(value), int)
|
||||
return value
|
||||
|
||||
cb = MyCallback(callback)
|
||||
result = f(-10, cb)
|
||||
self.failUnlessEqual(result, -18)
|
||||
self.assertEqual(result, -18)
|
||||
|
||||
def test_longlong_callbacks(self):
|
||||
|
||||
|
@ -305,12 +305,12 @@ class FunctionTestCase(unittest.TestCase):
|
|||
f.argtypes = [c_longlong, MyCallback]
|
||||
|
||||
def callback(value):
|
||||
self.failUnless(isinstance(value, (int, long)))
|
||||
self.assertTrue(isinstance(value, (int, long)))
|
||||
return value & 0x7FFFFFFF
|
||||
|
||||
cb = MyCallback(callback)
|
||||
|
||||
self.failUnlessEqual(13577625587, f(1000000000000, cb))
|
||||
self.assertEqual(13577625587, f(1000000000000, cb))
|
||||
|
||||
def test_errors(self):
|
||||
self.assertRaises(AttributeError, getattr, dll, "_xxx_yyy")
|
||||
|
@ -325,7 +325,7 @@ class FunctionTestCase(unittest.TestCase):
|
|||
result = dll._testfunc_byval(ptin, byref(ptout))
|
||||
got = result, ptout.x, ptout.y
|
||||
expected = 3, 1, 2
|
||||
self.failUnlessEqual(got, expected)
|
||||
self.assertEqual(got, expected)
|
||||
|
||||
# with prototype
|
||||
ptin = POINT(101, 102)
|
||||
|
@ -335,7 +335,7 @@ class FunctionTestCase(unittest.TestCase):
|
|||
result = dll._testfunc_byval(ptin, byref(ptout))
|
||||
got = result, ptout.x, ptout.y
|
||||
expected = 203, 101, 102
|
||||
self.failUnlessEqual(got, expected)
|
||||
self.assertEqual(got, expected)
|
||||
|
||||
def test_struct_return_2H(self):
|
||||
class S2H(Structure):
|
||||
|
@ -345,7 +345,7 @@ class FunctionTestCase(unittest.TestCase):
|
|||
dll.ret_2h_func.argtypes = [S2H]
|
||||
inp = S2H(99, 88)
|
||||
s2h = dll.ret_2h_func(inp)
|
||||
self.failUnlessEqual((s2h.x, s2h.y), (99*2, 88*3))
|
||||
self.assertEqual((s2h.x, s2h.y), (99*2, 88*3))
|
||||
|
||||
if sys.platform == "win32":
|
||||
def test_struct_return_2H_stdcall(self):
|
||||
|
@ -356,7 +356,7 @@ class FunctionTestCase(unittest.TestCase):
|
|||
windll.s_ret_2h_func.restype = S2H
|
||||
windll.s_ret_2h_func.argtypes = [S2H]
|
||||
s2h = windll.s_ret_2h_func(S2H(99, 88))
|
||||
self.failUnlessEqual((s2h.x, s2h.y), (99*2, 88*3))
|
||||
self.assertEqual((s2h.x, s2h.y), (99*2, 88*3))
|
||||
|
||||
def test_struct_return_8H(self):
|
||||
class S8I(Structure):
|
||||
|
@ -372,7 +372,7 @@ class FunctionTestCase(unittest.TestCase):
|
|||
dll.ret_8i_func.argtypes = [S8I]
|
||||
inp = S8I(9, 8, 7, 6, 5, 4, 3, 2)
|
||||
s8i = dll.ret_8i_func(inp)
|
||||
self.failUnlessEqual((s8i.a, s8i.b, s8i.c, s8i.d, s8i.e, s8i.f, s8i.g, s8i.h),
|
||||
self.assertEqual((s8i.a, s8i.b, s8i.c, s8i.d, s8i.e, s8i.f, s8i.g, s8i.h),
|
||||
(9*2, 8*3, 7*4, 6*5, 5*6, 4*7, 3*8, 2*9))
|
||||
|
||||
if sys.platform == "win32":
|
||||
|
@ -390,7 +390,7 @@ class FunctionTestCase(unittest.TestCase):
|
|||
windll.s_ret_8i_func.argtypes = [S8I]
|
||||
inp = S8I(9, 8, 7, 6, 5, 4, 3, 2)
|
||||
s8i = windll.s_ret_8i_func(inp)
|
||||
self.failUnlessEqual((s8i.a, s8i.b, s8i.c, s8i.d, s8i.e, s8i.f, s8i.g, s8i.h),
|
||||
self.assertEqual((s8i.a, s8i.b, s8i.c, s8i.d, s8i.e, s8i.f, s8i.g, s8i.h),
|
||||
(9*2, 8*3, 7*4, 6*5, 5*6, 4*7, 3*8, 2*9))
|
||||
|
||||
def test_sf1651235(self):
|
||||
|
@ -401,7 +401,7 @@ class FunctionTestCase(unittest.TestCase):
|
|||
return 0
|
||||
|
||||
callback = proto(callback)
|
||||
self.failUnlessRaises(ArgumentError, lambda: callback((1, 2, 3, 4), POINT()))
|
||||
self.assertRaises(ArgumentError, lambda: callback((1, 2, 3, 4), POINT()))
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -30,7 +30,7 @@ class MyTestCase(unittest.TestCase):
|
|||
for i in range(8):
|
||||
result.append(p.name)
|
||||
p = p.next[0]
|
||||
self.failUnlessEqual(result, ["foo", "bar"] * 4)
|
||||
self.assertEqual(result, ["foo", "bar"] * 4)
|
||||
|
||||
# to not leak references, we must clean _pointer_type_cache
|
||||
from ctypes import _pointer_type_cache
|
||||
|
|
|
@ -24,17 +24,17 @@ class InitTest(unittest.TestCase):
|
|||
# make sure the only accessing a nested structure
|
||||
# doesn't call the structure's __new__ and __init__
|
||||
y = Y()
|
||||
self.failUnlessEqual((y.x.a, y.x.b), (0, 0))
|
||||
self.failUnlessEqual(y.x.new_was_called, False)
|
||||
self.assertEqual((y.x.a, y.x.b), (0, 0))
|
||||
self.assertEqual(y.x.new_was_called, False)
|
||||
|
||||
# But explicitely creating an X structure calls __new__ and __init__, of course.
|
||||
x = X()
|
||||
self.failUnlessEqual((x.a, x.b), (9, 12))
|
||||
self.failUnlessEqual(x.new_was_called, True)
|
||||
self.assertEqual((x.a, x.b), (9, 12))
|
||||
self.assertEqual(x.new_was_called, True)
|
||||
|
||||
y.x = x
|
||||
self.failUnlessEqual((y.x.a, y.x.b), (9, 12))
|
||||
self.failUnlessEqual(y.x.new_was_called, False)
|
||||
self.assertEqual((y.x.a, y.x.b), (9, 12))
|
||||
self.assertEqual(y.x.new_was_called, False)
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
|
@ -18,22 +18,22 @@ What about pointers?
|
|||
"""
|
||||
|
||||
class ObjectsTestCase(unittest.TestCase):
|
||||
def failUnlessSame(self, a, b):
|
||||
self.failUnlessEqual(id(a), id(b))
|
||||
def assertTrueSame(self, a, b):
|
||||
self.assertEqual(id(a), id(b))
|
||||
|
||||
def test_ints(self):
|
||||
i = 42000123
|
||||
self.failUnlessEqual(3, grc(i))
|
||||
self.assertEqual(3, grc(i))
|
||||
ci = c_int(i)
|
||||
self.failUnlessEqual(3, grc(i))
|
||||
self.failUnlessEqual(ci._objects, None)
|
||||
self.assertEqual(3, grc(i))
|
||||
self.assertEqual(ci._objects, None)
|
||||
|
||||
def test_c_char_p(self):
|
||||
s = "Hello, World"
|
||||
self.failUnlessEqual(3, grc(s))
|
||||
self.assertEqual(3, grc(s))
|
||||
cs = c_char_p(s)
|
||||
self.failUnlessEqual(4, grc(s))
|
||||
self.failUnlessSame(cs._objects, s)
|
||||
self.assertEqual(4, grc(s))
|
||||
self.assertTrueSame(cs._objects, s)
|
||||
|
||||
def test_simple_struct(self):
|
||||
class X(Structure):
|
||||
|
@ -42,10 +42,10 @@ class ObjectsTestCase(unittest.TestCase):
|
|||
a = 421234
|
||||
b = 421235
|
||||
x = X()
|
||||
self.failUnlessEqual(x._objects, None)
|
||||
self.assertEqual(x._objects, None)
|
||||
x.a = a
|
||||
x.b = b
|
||||
self.failUnlessEqual(x._objects, None)
|
||||
self.assertEqual(x._objects, None)
|
||||
|
||||
def test_embedded_structs(self):
|
||||
class X(Structure):
|
||||
|
@ -55,13 +55,13 @@ class ObjectsTestCase(unittest.TestCase):
|
|||
_fields_ = [("x", X), ("y", X)]
|
||||
|
||||
y = Y()
|
||||
self.failUnlessEqual(y._objects, None)
|
||||
self.assertEqual(y._objects, None)
|
||||
|
||||
x1, x2 = X(), X()
|
||||
y.x, y.y = x1, x2
|
||||
self.failUnlessEqual(y._objects, {"0": {}, "1": {}})
|
||||
self.assertEqual(y._objects, {"0": {}, "1": {}})
|
||||
x1.a, x2.b = 42, 93
|
||||
self.failUnlessEqual(y._objects, {"0": {}, "1": {}})
|
||||
self.assertEqual(y._objects, {"0": {}, "1": {}})
|
||||
|
||||
def test_xxx(self):
|
||||
class X(Structure):
|
||||
|
@ -76,11 +76,11 @@ class ObjectsTestCase(unittest.TestCase):
|
|||
x = X()
|
||||
x.a = s1
|
||||
x.b = s2
|
||||
self.failUnlessEqual(x._objects, {"0": s1, "1": s2})
|
||||
self.assertEqual(x._objects, {"0": s1, "1": s2})
|
||||
|
||||
y = Y()
|
||||
y.x = x
|
||||
self.failUnlessEqual(y._objects, {"0": {"0": s1, "1": s2}})
|
||||
self.assertEqual(y._objects, {"0": {"0": s1, "1": s2}})
|
||||
## x = y.x
|
||||
## del y
|
||||
## print x._b_base_._objects
|
||||
|
@ -91,7 +91,7 @@ class ObjectsTestCase(unittest.TestCase):
|
|||
|
||||
A = c_int*4
|
||||
a = A(11, 22, 33, 44)
|
||||
self.failUnlessEqual(a._objects, None)
|
||||
self.assertEqual(a._objects, None)
|
||||
|
||||
x = X()
|
||||
x.data = a
|
||||
|
|
|
@ -91,7 +91,7 @@ class PointerTestCase(unittest.TestCase):
|
|||
def test_p_cint(self):
|
||||
i = c_int(42)
|
||||
x = pointer(i)
|
||||
self.failUnlessEqual(x._objects, {'1': i})
|
||||
self.assertEqual(x._objects, {'1': i})
|
||||
|
||||
class DeletePointerTestCase(unittest.TestCase):
|
||||
def X_test(self):
|
||||
|
|
|
@ -9,9 +9,9 @@ class LibTest(unittest.TestCase):
|
|||
def test_sqrt(self):
|
||||
lib.my_sqrt.argtypes = c_double,
|
||||
lib.my_sqrt.restype = c_double
|
||||
self.failUnlessEqual(lib.my_sqrt(4.0), 2.0)
|
||||
self.assertEqual(lib.my_sqrt(4.0), 2.0)
|
||||
import math
|
||||
self.failUnlessEqual(lib.my_sqrt(2.0), math.sqrt(2.0))
|
||||
self.assertEqual(lib.my_sqrt(2.0), math.sqrt(2.0))
|
||||
|
||||
def test_qsort(self):
|
||||
comparefunc = CFUNCTYPE(c_int, POINTER(c_char), POINTER(c_char))
|
||||
|
@ -23,7 +23,7 @@ class LibTest(unittest.TestCase):
|
|||
|
||||
chars = create_string_buffer("spam, spam, and spam")
|
||||
lib.my_qsort(chars, len(chars)-1, sizeof(c_char), comparefunc(sort))
|
||||
self.failUnlessEqual(chars.raw, " ,,aaaadmmmnpppsss\x00")
|
||||
self.assertEqual(chars.raw, " ,,aaaadmmmnpppsss\x00")
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
|
@ -43,7 +43,7 @@ class LoaderTest(unittest.TestCase):
|
|||
|
||||
if os.name in ("nt", "ce"):
|
||||
def test_load_library(self):
|
||||
self.failIf(libc_name is None)
|
||||
self.assertFalse(libc_name is None)
|
||||
if is_resource_enabled("printing"):
|
||||
print find_library("kernel32")
|
||||
print find_library("user32")
|
||||
|
@ -70,9 +70,9 @@ class LoaderTest(unittest.TestCase):
|
|||
a_name = addressof(func_name)
|
||||
f_ord_addr = c_void_p.from_address(a_ord).value
|
||||
f_name_addr = c_void_p.from_address(a_name).value
|
||||
self.failUnlessEqual(hex(f_ord_addr), hex(f_name_addr))
|
||||
self.assertEqual(hex(f_ord_addr), hex(f_name_addr))
|
||||
|
||||
self.failUnlessRaises(AttributeError, dll.__getitem__, 1234)
|
||||
self.assertRaises(AttributeError, dll.__getitem__, 1234)
|
||||
|
||||
if os.name == "nt":
|
||||
def test_1703286_A(self):
|
||||
|
@ -94,13 +94,13 @@ class LoaderTest(unittest.TestCase):
|
|||
advapi32 = windll.advapi32
|
||||
# Calling CloseEventLog with a NULL argument should fail,
|
||||
# but the call should not segfault or so.
|
||||
self.failUnlessEqual(0, advapi32.CloseEventLog(None))
|
||||
self.assertEqual(0, advapi32.CloseEventLog(None))
|
||||
windll.kernel32.GetProcAddress.argtypes = c_void_p, c_char_p
|
||||
windll.kernel32.GetProcAddress.restype = c_void_p
|
||||
proc = windll.kernel32.GetProcAddress(advapi32._handle, "CloseEventLog")
|
||||
self.failUnless(proc)
|
||||
self.assertTrue(proc)
|
||||
# This is the real test: call the function via 'call_function'
|
||||
self.failUnlessEqual(0, call_function(proc, (None,)))
|
||||
self.assertEqual(0, call_function(proc, (None,)))
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
|
@ -48,14 +48,14 @@ class MachOTest(unittest.TestCase):
|
|||
if sys.platform == "darwin":
|
||||
def test_find(self):
|
||||
|
||||
self.failUnlessEqual(find_lib('pthread'),
|
||||
self.assertEqual(find_lib('pthread'),
|
||||
'/usr/lib/libSystem.B.dylib')
|
||||
|
||||
result = find_lib('z')
|
||||
self.failUnless(result.startswith('/usr/lib/libz.1'))
|
||||
self.failUnless(result.endswith('.dylib'))
|
||||
self.assertTrue(result.startswith('/usr/lib/libz.1'))
|
||||
self.assertTrue(result.endswith('.dylib'))
|
||||
|
||||
self.failUnlessEqual(find_lib('IOKit'),
|
||||
self.assertEqual(find_lib('IOKit'),
|
||||
'/System/Library/Frameworks/IOKit.framework/Versions/A/IOKit')
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
@ -19,45 +19,45 @@ class MemFunctionsTest(unittest.TestCase):
|
|||
a = create_string_buffer(1000000)
|
||||
p = "Hello, World"
|
||||
result = memmove(a, p, len(p))
|
||||
self.failUnlessEqual(a.value, "Hello, World")
|
||||
self.assertEqual(a.value, "Hello, World")
|
||||
|
||||
self.failUnlessEqual(string_at(result), "Hello, World")
|
||||
self.failUnlessEqual(string_at(result, 5), "Hello")
|
||||
self.failUnlessEqual(string_at(result, 16), "Hello, World\0\0\0\0")
|
||||
self.failUnlessEqual(string_at(result, 0), "")
|
||||
self.assertEqual(string_at(result), "Hello, World")
|
||||
self.assertEqual(string_at(result, 5), "Hello")
|
||||
self.assertEqual(string_at(result, 16), "Hello, World\0\0\0\0")
|
||||
self.assertEqual(string_at(result, 0), "")
|
||||
|
||||
def test_memset(self):
|
||||
a = create_string_buffer(1000000)
|
||||
result = memset(a, ord('x'), 16)
|
||||
self.failUnlessEqual(a.value, "xxxxxxxxxxxxxxxx")
|
||||
self.assertEqual(a.value, "xxxxxxxxxxxxxxxx")
|
||||
|
||||
self.failUnlessEqual(string_at(result), "xxxxxxxxxxxxxxxx")
|
||||
self.failUnlessEqual(string_at(a), "xxxxxxxxxxxxxxxx")
|
||||
self.failUnlessEqual(string_at(a, 20), "xxxxxxxxxxxxxxxx\0\0\0\0")
|
||||
self.assertEqual(string_at(result), "xxxxxxxxxxxxxxxx")
|
||||
self.assertEqual(string_at(a), "xxxxxxxxxxxxxxxx")
|
||||
self.assertEqual(string_at(a, 20), "xxxxxxxxxxxxxxxx\0\0\0\0")
|
||||
|
||||
def test_cast(self):
|
||||
a = (c_ubyte * 32)(*map(ord, "abcdef"))
|
||||
self.failUnlessEqual(cast(a, c_char_p).value, "abcdef")
|
||||
self.failUnlessEqual(cast(a, POINTER(c_byte))[:7],
|
||||
self.assertEqual(cast(a, c_char_p).value, "abcdef")
|
||||
self.assertEqual(cast(a, POINTER(c_byte))[:7],
|
||||
[97, 98, 99, 100, 101, 102, 0])
|
||||
self.failUnlessEqual(cast(a, POINTER(c_byte))[:7:],
|
||||
self.assertEqual(cast(a, POINTER(c_byte))[:7:],
|
||||
[97, 98, 99, 100, 101, 102, 0])
|
||||
self.failUnlessEqual(cast(a, POINTER(c_byte))[6:-1:-1],
|
||||
self.assertEqual(cast(a, POINTER(c_byte))[6:-1:-1],
|
||||
[0, 102, 101, 100, 99, 98, 97])
|
||||
self.failUnlessEqual(cast(a, POINTER(c_byte))[:7:2],
|
||||
self.assertEqual(cast(a, POINTER(c_byte))[:7:2],
|
||||
[97, 99, 101, 0])
|
||||
self.failUnlessEqual(cast(a, POINTER(c_byte))[:7:7],
|
||||
self.assertEqual(cast(a, POINTER(c_byte))[:7:7],
|
||||
[97])
|
||||
|
||||
def test_string_at(self):
|
||||
s = string_at("foo bar")
|
||||
# XXX The following may be wrong, depending on how Python
|
||||
# manages string instances
|
||||
self.failUnlessEqual(2, sys.getrefcount(s))
|
||||
self.failUnless(s, "foo bar")
|
||||
self.assertEqual(2, sys.getrefcount(s))
|
||||
self.assertTrue(s, "foo bar")
|
||||
|
||||
self.failUnlessEqual(string_at("foo bar", 8), "foo bar\0")
|
||||
self.failUnlessEqual(string_at("foo bar", 3), "foo")
|
||||
self.assertEqual(string_at("foo bar", 8), "foo bar\0")
|
||||
self.assertEqual(string_at("foo bar", 3), "foo")
|
||||
|
||||
try:
|
||||
create_unicode_buffer
|
||||
|
@ -68,12 +68,12 @@ class MemFunctionsTest(unittest.TestCase):
|
|||
p = create_unicode_buffer("Hello, World")
|
||||
a = create_unicode_buffer(1000000)
|
||||
result = memmove(a, p, len(p) * sizeof(c_wchar))
|
||||
self.failUnlessEqual(a.value, "Hello, World")
|
||||
self.assertEqual(a.value, "Hello, World")
|
||||
|
||||
self.failUnlessEqual(wstring_at(a), "Hello, World")
|
||||
self.failUnlessEqual(wstring_at(a, 5), "Hello")
|
||||
self.failUnlessEqual(wstring_at(a, 16), "Hello, World\0\0\0\0")
|
||||
self.failUnlessEqual(wstring_at(a, 0), "")
|
||||
self.assertEqual(wstring_at(a), "Hello, World")
|
||||
self.assertEqual(wstring_at(a, 5), "Hello")
|
||||
self.assertEqual(wstring_at(a, 16), "Hello, World\0\0\0\0")
|
||||
self.assertEqual(wstring_at(a, 0), "")
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
|
@ -55,25 +55,25 @@ class NumberTestCase(unittest.TestCase):
|
|||
def test_default_init(self):
|
||||
# default values are set to zero
|
||||
for t in signed_types + unsigned_types + float_types:
|
||||
self.failUnlessEqual(t().value, 0)
|
||||
self.assertEqual(t().value, 0)
|
||||
|
||||
def test_unsigned_values(self):
|
||||
# the value given to the constructor is available
|
||||
# as the 'value' attribute
|
||||
for t, (l, h) in zip(unsigned_types, unsigned_ranges):
|
||||
self.failUnlessEqual(t(l).value, l)
|
||||
self.failUnlessEqual(t(h).value, h)
|
||||
self.assertEqual(t(l).value, l)
|
||||
self.assertEqual(t(h).value, h)
|
||||
|
||||
def test_signed_values(self):
|
||||
# see above
|
||||
for t, (l, h) in zip(signed_types, signed_ranges):
|
||||
self.failUnlessEqual(t(l).value, l)
|
||||
self.failUnlessEqual(t(h).value, h)
|
||||
self.assertEqual(t(l).value, l)
|
||||
self.assertEqual(t(h).value, h)
|
||||
|
||||
def test_bool_values(self):
|
||||
from operator import truth
|
||||
for t, v in zip(bool_types, bool_values):
|
||||
self.failUnlessEqual(t(v).value, truth(v))
|
||||
self.assertEqual(t(v).value, truth(v))
|
||||
|
||||
def test_typeerror(self):
|
||||
# Only numbers are allowed in the contructor,
|
||||
|
@ -93,13 +93,13 @@ class NumberTestCase(unittest.TestCase):
|
|||
# the from_param class method attribute always
|
||||
# returns PyCArgObject instances
|
||||
for t in signed_types + unsigned_types + float_types:
|
||||
self.failUnlessEqual(ArgType, type(t.from_param(0)))
|
||||
self.assertEqual(ArgType, type(t.from_param(0)))
|
||||
|
||||
def test_byref(self):
|
||||
# calling byref returns also a PyCArgObject instance
|
||||
for t in signed_types + unsigned_types + float_types + bool_types:
|
||||
parm = byref(t())
|
||||
self.failUnlessEqual(ArgType, type(parm))
|
||||
self.assertEqual(ArgType, type(parm))
|
||||
|
||||
|
||||
def test_floats(self):
|
||||
|
@ -110,10 +110,10 @@ class NumberTestCase(unittest.TestCase):
|
|||
return 2.0
|
||||
f = FloatLike()
|
||||
for t in float_types:
|
||||
self.failUnlessEqual(t(2.0).value, 2.0)
|
||||
self.failUnlessEqual(t(2).value, 2.0)
|
||||
self.failUnlessEqual(t(2L).value, 2.0)
|
||||
self.failUnlessEqual(t(f).value, 2.0)
|
||||
self.assertEqual(t(2.0).value, 2.0)
|
||||
self.assertEqual(t(2).value, 2.0)
|
||||
self.assertEqual(t(2L).value, 2.0)
|
||||
self.assertEqual(t(f).value, 2.0)
|
||||
|
||||
def test_integers(self):
|
||||
class FloatLike(object):
|
||||
|
@ -129,7 +129,7 @@ class NumberTestCase(unittest.TestCase):
|
|||
for t in signed_types + unsigned_types:
|
||||
self.assertRaises(TypeError, t, 3.14)
|
||||
self.assertRaises(TypeError, t, f)
|
||||
self.failUnlessEqual(t(i).value, 2)
|
||||
self.assertEqual(t(i).value, 2)
|
||||
|
||||
def test_sizes(self):
|
||||
for t in signed_types + unsigned_types + float_types + bool_types:
|
||||
|
@ -138,9 +138,9 @@ class NumberTestCase(unittest.TestCase):
|
|||
except struct.error:
|
||||
continue
|
||||
# sizeof of the type...
|
||||
self.failUnlessEqual(sizeof(t), size)
|
||||
self.assertEqual(sizeof(t), size)
|
||||
# and sizeof of an instance
|
||||
self.failUnlessEqual(sizeof(t()), size)
|
||||
self.assertEqual(sizeof(t()), size)
|
||||
|
||||
def test_alignments(self):
|
||||
for t in signed_types + unsigned_types + float_types:
|
||||
|
@ -148,10 +148,10 @@ class NumberTestCase(unittest.TestCase):
|
|||
align = struct.calcsize("c%c" % code) - struct.calcsize(code)
|
||||
|
||||
# alignment of the type...
|
||||
self.failUnlessEqual((code, alignment(t)),
|
||||
self.assertEqual((code, alignment(t)),
|
||||
(code, align))
|
||||
# and alignment of an instance
|
||||
self.failUnlessEqual((code, alignment(t())),
|
||||
self.assertEqual((code, alignment(t())),
|
||||
(code, align))
|
||||
|
||||
def test_int_from_address(self):
|
||||
|
@ -167,12 +167,12 @@ class NumberTestCase(unittest.TestCase):
|
|||
|
||||
# v now is an integer at an 'external' memory location
|
||||
v = t.from_address(a.buffer_info()[0])
|
||||
self.failUnlessEqual(v.value, a[0])
|
||||
self.failUnlessEqual(type(v), t)
|
||||
self.assertEqual(v.value, a[0])
|
||||
self.assertEqual(type(v), t)
|
||||
|
||||
# changing the value at the memory location changes v's value also
|
||||
a[0] = 42
|
||||
self.failUnlessEqual(v.value, a[0])
|
||||
self.assertEqual(v.value, a[0])
|
||||
|
||||
|
||||
def test_float_from_address(self):
|
||||
|
@ -180,11 +180,11 @@ class NumberTestCase(unittest.TestCase):
|
|||
for t in float_types:
|
||||
a = array(t._type_, [3.14])
|
||||
v = t.from_address(a.buffer_info()[0])
|
||||
self.failUnlessEqual(v.value, a[0])
|
||||
self.failUnless(type(v) is t)
|
||||
self.assertEqual(v.value, a[0])
|
||||
self.assertTrue(type(v) is t)
|
||||
a[0] = 2.3456e17
|
||||
self.failUnlessEqual(v.value, a[0])
|
||||
self.failUnless(type(v) is t)
|
||||
self.assertEqual(v.value, a[0])
|
||||
self.assertTrue(type(v) is t)
|
||||
|
||||
def test_char_from_address(self):
|
||||
from ctypes import c_char
|
||||
|
@ -192,11 +192,11 @@ class NumberTestCase(unittest.TestCase):
|
|||
|
||||
a = array('c', 'x')
|
||||
v = c_char.from_address(a.buffer_info()[0])
|
||||
self.failUnlessEqual(v.value, a[0])
|
||||
self.failUnless(type(v) is c_char)
|
||||
self.assertEqual(v.value, a[0])
|
||||
self.assertTrue(type(v) is c_char)
|
||||
|
||||
a[0] = '?'
|
||||
self.failUnlessEqual(v.value, a[0])
|
||||
self.assertEqual(v.value, a[0])
|
||||
|
||||
# array does not support c_bool / 't'
|
||||
# def test_bool_from_address(self):
|
||||
|
@ -204,11 +204,11 @@ class NumberTestCase(unittest.TestCase):
|
|||
# from array import array
|
||||
# a = array(c_bool._type_, [True])
|
||||
# v = t.from_address(a.buffer_info()[0])
|
||||
# self.failUnlessEqual(v.value, a[0])
|
||||
# self.failUnlessEqual(type(v) is t)
|
||||
# self.assertEqual(v.value, a[0])
|
||||
# self.assertEqual(type(v) is t)
|
||||
# a[0] = False
|
||||
# self.failUnlessEqual(v.value, a[0])
|
||||
# self.failUnlessEqual(type(v) is t)
|
||||
# self.assertEqual(v.value, a[0])
|
||||
# self.assertEqual(type(v) is t)
|
||||
|
||||
def test_init(self):
|
||||
# c_int() can be initialized from Python's int, and c_int.
|
||||
|
|
|
@ -33,8 +33,8 @@ class SimpleTypesTestCase(unittest.TestCase):
|
|||
return value * 4
|
||||
from_param = classmethod(from_param)
|
||||
|
||||
self.failUnlessEqual(CVOIDP.from_param("abc"), "abcabc")
|
||||
self.failUnlessEqual(CCHARP.from_param("abc"), "abcabcabcabc")
|
||||
self.assertEqual(CVOIDP.from_param("abc"), "abcabc")
|
||||
self.assertEqual(CCHARP.from_param("abc"), "abcabcabcabc")
|
||||
|
||||
try:
|
||||
from ctypes import c_wchar_p
|
||||
|
@ -46,7 +46,7 @@ class SimpleTypesTestCase(unittest.TestCase):
|
|||
return value * 3
|
||||
from_param = classmethod(from_param)
|
||||
|
||||
self.failUnlessEqual(CWCHARP.from_param("abc"), "abcabcabc")
|
||||
self.assertEqual(CWCHARP.from_param("abc"), "abcabcabc")
|
||||
|
||||
# XXX Replace by c_char_p tests
|
||||
def test_cstrings(self):
|
||||
|
@ -55,10 +55,10 @@ class SimpleTypesTestCase(unittest.TestCase):
|
|||
# c_char_p.from_param on a Python String packs the string
|
||||
# into a cparam object
|
||||
s = "123"
|
||||
self.failUnless(c_char_p.from_param(s)._obj is s)
|
||||
self.assertTrue(c_char_p.from_param(s)._obj is s)
|
||||
|
||||
# new in 0.9.1: convert (encode) unicode to ascii
|
||||
self.failUnlessEqual(c_char_p.from_param(u"123")._obj, "123")
|
||||
self.assertEqual(c_char_p.from_param(u"123")._obj, "123")
|
||||
self.assertRaises(UnicodeEncodeError, c_char_p.from_param, u"123\377")
|
||||
|
||||
self.assertRaises(TypeError, c_char_p.from_param, 42)
|
||||
|
@ -66,7 +66,7 @@ class SimpleTypesTestCase(unittest.TestCase):
|
|||
# calling c_char_p.from_param with a c_char_p instance
|
||||
# returns the argument itself:
|
||||
a = c_char_p("123")
|
||||
self.failUnless(c_char_p.from_param(a) is a)
|
||||
self.assertTrue(c_char_p.from_param(a) is a)
|
||||
|
||||
def test_cw_strings(self):
|
||||
from ctypes import byref
|
||||
|
@ -77,15 +77,15 @@ class SimpleTypesTestCase(unittest.TestCase):
|
|||
return
|
||||
s = u"123"
|
||||
if sys.platform == "win32":
|
||||
self.failUnless(c_wchar_p.from_param(s)._obj is s)
|
||||
self.assertTrue(c_wchar_p.from_param(s)._obj is s)
|
||||
self.assertRaises(TypeError, c_wchar_p.from_param, 42)
|
||||
|
||||
# new in 0.9.1: convert (decode) ascii to unicode
|
||||
self.failUnlessEqual(c_wchar_p.from_param("123")._obj, u"123")
|
||||
self.assertEqual(c_wchar_p.from_param("123")._obj, u"123")
|
||||
self.assertRaises(UnicodeDecodeError, c_wchar_p.from_param, "123\377")
|
||||
|
||||
pa = c_wchar_p.from_param(c_wchar_p(u"123"))
|
||||
self.failUnlessEqual(type(pa), c_wchar_p)
|
||||
self.assertEqual(type(pa), c_wchar_p)
|
||||
|
||||
def test_int_pointers(self):
|
||||
from ctypes import c_short, c_uint, c_int, c_long, POINTER, pointer
|
||||
|
@ -94,10 +94,10 @@ class SimpleTypesTestCase(unittest.TestCase):
|
|||
## p = pointer(c_int(42))
|
||||
## x = LPINT.from_param(p)
|
||||
x = LPINT.from_param(pointer(c_int(42)))
|
||||
self.failUnlessEqual(x.contents.value, 42)
|
||||
self.failUnlessEqual(LPINT(c_int(42)).contents.value, 42)
|
||||
self.assertEqual(x.contents.value, 42)
|
||||
self.assertEqual(LPINT(c_int(42)).contents.value, 42)
|
||||
|
||||
self.failUnlessEqual(LPINT.from_param(None), 0)
|
||||
self.assertEqual(LPINT.from_param(None), 0)
|
||||
|
||||
if c_int != c_long:
|
||||
self.assertRaises(TypeError, LPINT.from_param, pointer(c_long(42)))
|
||||
|
@ -133,8 +133,8 @@ class SimpleTypesTestCase(unittest.TestCase):
|
|||
from ctypes import c_short, c_uint, c_int, c_long, POINTER
|
||||
INTARRAY = c_int * 3
|
||||
ia = INTARRAY()
|
||||
self.failUnlessEqual(len(ia), 3)
|
||||
self.failUnlessEqual([ia[i] for i in range(3)], [0, 0, 0])
|
||||
self.assertEqual(len(ia), 3)
|
||||
self.assertEqual([ia[i] for i in range(3)], [0, 0, 0])
|
||||
|
||||
# Pointers are only compatible with arrays containing items of
|
||||
# the same type!
|
||||
|
@ -161,8 +161,8 @@ class SimpleTypesTestCase(unittest.TestCase):
|
|||
return None
|
||||
|
||||
func.argtypes = (Adapter(),)
|
||||
self.failUnlessEqual(func(None), None)
|
||||
self.failUnlessEqual(func(object()), None)
|
||||
self.assertEqual(func(None), None)
|
||||
self.assertEqual(func(object()), None)
|
||||
|
||||
class Adapter(object):
|
||||
def from_param(cls, obj):
|
||||
|
@ -171,7 +171,7 @@ class SimpleTypesTestCase(unittest.TestCase):
|
|||
func.argtypes = (Adapter(),)
|
||||
# don't know how to convert parameter 1
|
||||
self.assertRaises(ArgumentError, func, object())
|
||||
self.failUnlessEqual(func(c_void_p(42)), 42)
|
||||
self.assertEqual(func(c_void_p(42)), 42)
|
||||
|
||||
class Adapter(object):
|
||||
def from_param(cls, obj):
|
||||
|
|
|
@ -45,20 +45,20 @@ class Test(unittest.TestCase):
|
|||
ob = tp()
|
||||
v = memoryview(ob)
|
||||
try:
|
||||
self.failUnlessEqual(normalize(v.format), normalize(fmt))
|
||||
self.failUnlessEqual(v.size, sizeof(ob))
|
||||
self.failUnlessEqual(v.itemsize, sizeof(itemtp))
|
||||
self.failUnlessEqual(v.shape, shape)
|
||||
self.assertEqual(normalize(v.format), normalize(fmt))
|
||||
self.assertEqual(v.size, sizeof(ob))
|
||||
self.assertEqual(v.itemsize, sizeof(itemtp))
|
||||
self.assertEqual(v.shape, shape)
|
||||
# ctypes object always have a non-strided memory block
|
||||
self.failUnlessEqual(v.strides, None)
|
||||
self.assertEqual(v.strides, None)
|
||||
# they are always read/write
|
||||
self.failIf(v.readonly)
|
||||
self.assertFalse(v.readonly)
|
||||
|
||||
if v.shape:
|
||||
n = 1
|
||||
for dim in v.shape:
|
||||
n = n * dim
|
||||
self.failUnlessEqual(v.itemsize * n, v.size)
|
||||
self.assertEqual(v.itemsize * n, v.size)
|
||||
except:
|
||||
# so that we can see the failing type
|
||||
print(tp)
|
||||
|
@ -69,20 +69,20 @@ class Test(unittest.TestCase):
|
|||
ob = tp()
|
||||
v = memoryview(ob)
|
||||
try:
|
||||
self.failUnlessEqual(v.format, fmt)
|
||||
self.failUnlessEqual(v.size, sizeof(ob))
|
||||
self.failUnlessEqual(v.itemsize, sizeof(itemtp))
|
||||
self.failUnlessEqual(v.shape, shape)
|
||||
self.assertEqual(v.format, fmt)
|
||||
self.assertEqual(v.size, sizeof(ob))
|
||||
self.assertEqual(v.itemsize, sizeof(itemtp))
|
||||
self.assertEqual(v.shape, shape)
|
||||
# ctypes object always have a non-strided memory block
|
||||
self.failUnlessEqual(v.strides, None)
|
||||
self.assertEqual(v.strides, None)
|
||||
# they are always read/write
|
||||
self.failIf(v.readonly)
|
||||
self.assertFalse(v.readonly)
|
||||
|
||||
if v.shape:
|
||||
n = 1
|
||||
for dim in v.shape:
|
||||
n = n * dim
|
||||
self.failUnlessEqual(v.itemsize * n, v.size)
|
||||
self.assertEqual(v.itemsize * n, v.size)
|
||||
except:
|
||||
# so that we can see the failing type
|
||||
print(tp)
|
||||
|
|
|
@ -27,8 +27,8 @@ class PickleTest(unittest.TestCase):
|
|||
c_double(3.14),
|
||||
]:
|
||||
dst = self.loads(self.dumps(src))
|
||||
self.failUnlessEqual(src.__dict__, dst.__dict__)
|
||||
self.failUnlessEqual(buffer(src)[:],
|
||||
self.assertEqual(src.__dict__, dst.__dict__)
|
||||
self.assertEqual(buffer(src)[:],
|
||||
buffer(dst)[:])
|
||||
|
||||
def test_struct(self):
|
||||
|
@ -36,17 +36,17 @@ class PickleTest(unittest.TestCase):
|
|||
|
||||
x = X()
|
||||
x.a = 42
|
||||
self.failUnlessEqual(X.init_called, 1)
|
||||
self.assertEqual(X.init_called, 1)
|
||||
|
||||
y = self.loads(self.dumps(x))
|
||||
|
||||
# loads must NOT call __init__
|
||||
self.failUnlessEqual(X.init_called, 1)
|
||||
self.assertEqual(X.init_called, 1)
|
||||
|
||||
# ctypes instances are identical when the instance __dict__
|
||||
# and the memory buffer are identical
|
||||
self.failUnlessEqual(y.__dict__, x.__dict__)
|
||||
self.failUnlessEqual(buffer(y)[:],
|
||||
self.assertEqual(y.__dict__, x.__dict__)
|
||||
self.assertEqual(buffer(y)[:],
|
||||
buffer(x)[:])
|
||||
|
||||
def test_unpickable(self):
|
||||
|
|
|
@ -17,7 +17,7 @@ class PointersTestCase(unittest.TestCase):
|
|||
|
||||
POINTER(c_ulong)(c_ulong(22))
|
||||
# Pointer can't set contents: has no _type_
|
||||
self.failUnlessRaises(TypeError, A, c_ulong(33))
|
||||
self.assertRaises(TypeError, A, c_ulong(33))
|
||||
|
||||
def test_pass_pointers(self):
|
||||
dll = CDLL(_ctypes_test.__file__)
|
||||
|
@ -27,12 +27,12 @@ class PointersTestCase(unittest.TestCase):
|
|||
i = c_int(12345678)
|
||||
## func.argtypes = (POINTER(c_int),)
|
||||
address = func(byref(i))
|
||||
self.failUnlessEqual(c_int.from_address(address).value, 12345678)
|
||||
self.assertEqual(c_int.from_address(address).value, 12345678)
|
||||
|
||||
func.restype = POINTER(c_int)
|
||||
res = func(pointer(i))
|
||||
self.failUnlessEqual(res.contents.value, 12345678)
|
||||
self.failUnlessEqual(res[0], 12345678)
|
||||
self.assertEqual(res.contents.value, 12345678)
|
||||
self.assertEqual(res[0], 12345678)
|
||||
|
||||
def test_change_pointers(self):
|
||||
dll = CDLL(_ctypes_test.__file__)
|
||||
|
@ -43,18 +43,18 @@ class PointersTestCase(unittest.TestCase):
|
|||
func.argtypes = (POINTER(c_int),)
|
||||
|
||||
res = func(pointer(i))
|
||||
self.failUnlessEqual(res[0], 87654)
|
||||
self.failUnlessEqual(res.contents.value, 87654)
|
||||
self.assertEqual(res[0], 87654)
|
||||
self.assertEqual(res.contents.value, 87654)
|
||||
|
||||
# C code: *res = 54345
|
||||
res[0] = 54345
|
||||
self.failUnlessEqual(i.value, 54345)
|
||||
self.assertEqual(i.value, 54345)
|
||||
|
||||
# C code:
|
||||
# int x = 12321;
|
||||
# res = &x
|
||||
res.contents = c_int(12321)
|
||||
self.failUnlessEqual(i.value, 54345)
|
||||
self.assertEqual(i.value, 54345)
|
||||
|
||||
def test_callbacks_with_pointers(self):
|
||||
# a function type receiving a pointer
|
||||
|
@ -78,7 +78,7 @@ class PointersTestCase(unittest.TestCase):
|
|||
|
||||
## i = c_int(42)
|
||||
## callback(byref(i))
|
||||
## self.failUnless(i.value == 84)
|
||||
## self.assertTrue(i.value == 84)
|
||||
|
||||
doit(callback)
|
||||
## print self.result
|
||||
|
@ -91,11 +91,11 @@ class PointersTestCase(unittest.TestCase):
|
|||
i = ct(42)
|
||||
p = pointer(i)
|
||||
## print type(p.contents), ct
|
||||
self.failUnless(type(p.contents) is ct)
|
||||
self.assertTrue(type(p.contents) is ct)
|
||||
# p.contents is the same as p[0]
|
||||
## print p.contents
|
||||
## self.failUnless(p.contents == 42)
|
||||
## self.failUnless(p[0] == 42)
|
||||
## self.assertTrue(p.contents == 42)
|
||||
## self.assertTrue(p[0] == 42)
|
||||
|
||||
self.assertRaises(TypeError, delitem, p, 0)
|
||||
|
||||
|
@ -117,9 +117,9 @@ class PointersTestCase(unittest.TestCase):
|
|||
|
||||
pt = pointer(Table(1, 2, 3))
|
||||
|
||||
self.failUnlessEqual(pt.contents.a, 1)
|
||||
self.failUnlessEqual(pt.contents.b, 2)
|
||||
self.failUnlessEqual(pt.contents.c, 3)
|
||||
self.assertEqual(pt.contents.a, 1)
|
||||
self.assertEqual(pt.contents.b, 2)
|
||||
self.assertEqual(pt.contents.c, 3)
|
||||
|
||||
pt.contents.c = 33
|
||||
|
||||
|
@ -130,8 +130,8 @@ class PointersTestCase(unittest.TestCase):
|
|||
p = pointer(c_int(42))
|
||||
# Although a pointer can be indexed, it ha no length
|
||||
self.assertRaises(TypeError, len, p)
|
||||
self.failUnlessEqual(p[0], 42)
|
||||
self.failUnlessEqual(p.contents.value, 42)
|
||||
self.assertEqual(p[0], 42)
|
||||
self.assertEqual(p.contents.value, 42)
|
||||
|
||||
def test_charpp(self):
|
||||
"""Test that a character pointer-to-pointer is correctly passed"""
|
||||
|
@ -156,20 +156,20 @@ class PointersTestCase(unittest.TestCase):
|
|||
pp = pointer(p)
|
||||
q = pointer(y)
|
||||
pp[0] = q # <==
|
||||
self.failUnlessEqual(p[0], 6)
|
||||
self.assertEqual(p[0], 6)
|
||||
def test_c_void_p(self):
|
||||
# http://sourceforge.net/tracker/?func=detail&aid=1518190&group_id=5470&atid=105470
|
||||
if sizeof(c_void_p) == 4:
|
||||
self.failUnlessEqual(c_void_p(0xFFFFFFFFL).value,
|
||||
self.assertEqual(c_void_p(0xFFFFFFFFL).value,
|
||||
c_void_p(-1).value)
|
||||
self.failUnlessEqual(c_void_p(0xFFFFFFFFFFFFFFFFL).value,
|
||||
self.assertEqual(c_void_p(0xFFFFFFFFFFFFFFFFL).value,
|
||||
c_void_p(-1).value)
|
||||
elif sizeof(c_void_p) == 8:
|
||||
self.failUnlessEqual(c_void_p(0xFFFFFFFFL).value,
|
||||
self.assertEqual(c_void_p(0xFFFFFFFFL).value,
|
||||
0xFFFFFFFFL)
|
||||
self.failUnlessEqual(c_void_p(0xFFFFFFFFFFFFFFFFL).value,
|
||||
self.assertEqual(c_void_p(0xFFFFFFFFFFFFFFFFL).value,
|
||||
c_void_p(-1).value)
|
||||
self.failUnlessEqual(c_void_p(0xFFFFFFFFFFFFFFFFFFFFFFFFL).value,
|
||||
self.assertEqual(c_void_p(0xFFFFFFFFFFFFFFFFFFFFFFFFL).value,
|
||||
c_void_p(-1).value)
|
||||
|
||||
self.assertRaises(TypeError, c_void_p, 3.14) # make sure floats are NOT accepted
|
||||
|
@ -177,16 +177,16 @@ class PointersTestCase(unittest.TestCase):
|
|||
|
||||
def test_pointers_bool(self):
|
||||
# NULL pointers have a boolean False value, non-NULL pointers True.
|
||||
self.failUnlessEqual(bool(POINTER(c_int)()), False)
|
||||
self.failUnlessEqual(bool(pointer(c_int())), True)
|
||||
self.assertEqual(bool(POINTER(c_int)()), False)
|
||||
self.assertEqual(bool(pointer(c_int())), True)
|
||||
|
||||
self.failUnlessEqual(bool(CFUNCTYPE(None)(0)), False)
|
||||
self.failUnlessEqual(bool(CFUNCTYPE(None)(42)), True)
|
||||
self.assertEqual(bool(CFUNCTYPE(None)(0)), False)
|
||||
self.assertEqual(bool(CFUNCTYPE(None)(42)), True)
|
||||
|
||||
# COM methods are boolean True:
|
||||
if sys.platform == "win32":
|
||||
mth = WINFUNCTYPE(None)(42, "name", (), None)
|
||||
self.failUnlessEqual(bool(mth), True)
|
||||
self.assertEqual(bool(mth), True)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -58,23 +58,23 @@ class CharPointersTestCase(unittest.TestCase):
|
|||
try:
|
||||
func()
|
||||
except TypeError, details:
|
||||
self.failUnlessEqual(str(details), "required argument 'input' missing")
|
||||
self.assertEqual(str(details), "required argument 'input' missing")
|
||||
else:
|
||||
self.fail("TypeError not raised")
|
||||
|
||||
self.failUnlessEqual(func(None), None)
|
||||
self.failUnlessEqual(func(input=None), None)
|
||||
self.assertEqual(func(None), None)
|
||||
self.assertEqual(func(input=None), None)
|
||||
|
||||
|
||||
def test_int_pointer_arg(self):
|
||||
func = testdll._testfunc_p_p
|
||||
func.restype = c_long
|
||||
self.failUnlessEqual(0, func(0))
|
||||
self.assertEqual(0, func(0))
|
||||
|
||||
ci = c_int(0)
|
||||
|
||||
func.argtypes = POINTER(c_int),
|
||||
self.failUnlessEqual(positive_address(addressof(ci)),
|
||||
self.assertEqual(positive_address(addressof(ci)),
|
||||
positive_address(func(byref(ci))))
|
||||
|
||||
func.argtypes = c_char_p,
|
||||
|
@ -91,45 +91,45 @@ class CharPointersTestCase(unittest.TestCase):
|
|||
func.restype = c_char_p
|
||||
func.argtypes = POINTER(c_char),
|
||||
|
||||
self.failUnlessEqual(None, func(None))
|
||||
self.failUnlessEqual("123", func("123"))
|
||||
self.failUnlessEqual(None, func(c_char_p(None)))
|
||||
self.failUnlessEqual("123", func(c_char_p("123")))
|
||||
self.assertEqual(None, func(None))
|
||||
self.assertEqual("123", func("123"))
|
||||
self.assertEqual(None, func(c_char_p(None)))
|
||||
self.assertEqual("123", func(c_char_p("123")))
|
||||
|
||||
self.failUnlessEqual("123", func(c_buffer("123")))
|
||||
self.assertEqual("123", func(c_buffer("123")))
|
||||
ca = c_char("a")
|
||||
self.failUnlessEqual("a", func(pointer(ca))[0])
|
||||
self.failUnlessEqual("a", func(byref(ca))[0])
|
||||
self.assertEqual("a", func(pointer(ca))[0])
|
||||
self.assertEqual("a", func(byref(ca))[0])
|
||||
|
||||
def test_c_char_p_arg(self):
|
||||
func = testdll._testfunc_p_p
|
||||
func.restype = c_char_p
|
||||
func.argtypes = c_char_p,
|
||||
|
||||
self.failUnlessEqual(None, func(None))
|
||||
self.failUnlessEqual("123", func("123"))
|
||||
self.failUnlessEqual(None, func(c_char_p(None)))
|
||||
self.failUnlessEqual("123", func(c_char_p("123")))
|
||||
self.assertEqual(None, func(None))
|
||||
self.assertEqual("123", func("123"))
|
||||
self.assertEqual(None, func(c_char_p(None)))
|
||||
self.assertEqual("123", func(c_char_p("123")))
|
||||
|
||||
self.failUnlessEqual("123", func(c_buffer("123")))
|
||||
self.assertEqual("123", func(c_buffer("123")))
|
||||
ca = c_char("a")
|
||||
self.failUnlessEqual("a", func(pointer(ca))[0])
|
||||
self.failUnlessEqual("a", func(byref(ca))[0])
|
||||
self.assertEqual("a", func(pointer(ca))[0])
|
||||
self.assertEqual("a", func(byref(ca))[0])
|
||||
|
||||
def test_c_void_p_arg(self):
|
||||
func = testdll._testfunc_p_p
|
||||
func.restype = c_char_p
|
||||
func.argtypes = c_void_p,
|
||||
|
||||
self.failUnlessEqual(None, func(None))
|
||||
self.failUnlessEqual("123", func("123"))
|
||||
self.failUnlessEqual("123", func(c_char_p("123")))
|
||||
self.failUnlessEqual(None, func(c_char_p(None)))
|
||||
self.assertEqual(None, func(None))
|
||||
self.assertEqual("123", func("123"))
|
||||
self.assertEqual("123", func(c_char_p("123")))
|
||||
self.assertEqual(None, func(c_char_p(None)))
|
||||
|
||||
self.failUnlessEqual("123", func(c_buffer("123")))
|
||||
self.assertEqual("123", func(c_buffer("123")))
|
||||
ca = c_char("a")
|
||||
self.failUnlessEqual("a", func(pointer(ca))[0])
|
||||
self.failUnlessEqual("a", func(byref(ca))[0])
|
||||
self.assertEqual("a", func(pointer(ca))[0])
|
||||
self.assertEqual("a", func(byref(ca))[0])
|
||||
|
||||
func(byref(c_int()))
|
||||
func(pointer(c_int()))
|
||||
|
@ -140,8 +140,8 @@ class CharPointersTestCase(unittest.TestCase):
|
|||
except NameError:
|
||||
pass
|
||||
else:
|
||||
self.failUnlessEqual(None, func(c_wchar_p(None)))
|
||||
self.failUnlessEqual(u"123", func(c_wchar_p(u"123")))
|
||||
self.assertEqual(None, func(c_wchar_p(None)))
|
||||
self.assertEqual(u"123", func(c_wchar_p(u"123")))
|
||||
|
||||
def test_instance(self):
|
||||
func = testdll._testfunc_p_p
|
||||
|
@ -151,10 +151,10 @@ class CharPointersTestCase(unittest.TestCase):
|
|||
_as_parameter_ = None
|
||||
|
||||
func.argtypes = c_void_p,
|
||||
self.failUnlessEqual(None, func(X()))
|
||||
self.assertEqual(None, func(X()))
|
||||
|
||||
func.argtypes = None
|
||||
self.failUnlessEqual(None, func(X()))
|
||||
self.assertEqual(None, func(X()))
|
||||
|
||||
try:
|
||||
c_wchar
|
||||
|
@ -174,15 +174,15 @@ else:
|
|||
func.restype = c_wchar_p
|
||||
func.argtypes = POINTER(c_wchar),
|
||||
|
||||
self.failUnlessEqual(None, func(None))
|
||||
self.failUnlessEqual(u"123", func(u"123"))
|
||||
self.failUnlessEqual(None, func(c_wchar_p(None)))
|
||||
self.failUnlessEqual(u"123", func(c_wchar_p(u"123")))
|
||||
self.assertEqual(None, func(None))
|
||||
self.assertEqual(u"123", func(u"123"))
|
||||
self.assertEqual(None, func(c_wchar_p(None)))
|
||||
self.assertEqual(u"123", func(c_wchar_p(u"123")))
|
||||
|
||||
self.failUnlessEqual(u"123", func(c_wbuffer(u"123")))
|
||||
self.assertEqual(u"123", func(c_wbuffer(u"123")))
|
||||
ca = c_wchar("a")
|
||||
self.failUnlessEqual(u"a", func(pointer(ca))[0])
|
||||
self.failUnlessEqual(u"a", func(byref(ca))[0])
|
||||
self.assertEqual(u"a", func(pointer(ca))[0])
|
||||
self.assertEqual(u"a", func(byref(ca))[0])
|
||||
|
||||
def test_c_wchar_p_arg(self):
|
||||
func = testdll._testfunc_p_p
|
||||
|
@ -191,16 +191,16 @@ else:
|
|||
|
||||
c_wchar_p.from_param(u"123")
|
||||
|
||||
self.failUnlessEqual(None, func(None))
|
||||
self.failUnlessEqual("123", func(u"123"))
|
||||
self.failUnlessEqual(None, func(c_wchar_p(None)))
|
||||
self.failUnlessEqual("123", func(c_wchar_p("123")))
|
||||
self.assertEqual(None, func(None))
|
||||
self.assertEqual("123", func(u"123"))
|
||||
self.assertEqual(None, func(c_wchar_p(None)))
|
||||
self.assertEqual("123", func(c_wchar_p("123")))
|
||||
|
||||
# XXX Currently, these raise TypeErrors, although they shouldn't:
|
||||
self.failUnlessEqual("123", func(c_wbuffer("123")))
|
||||
self.assertEqual("123", func(c_wbuffer("123")))
|
||||
ca = c_wchar("a")
|
||||
self.failUnlessEqual("a", func(pointer(ca))[0])
|
||||
self.failUnlessEqual("a", func(byref(ca))[0])
|
||||
self.assertEqual("a", func(pointer(ca))[0])
|
||||
self.assertEqual("a", func(byref(ca))[0])
|
||||
|
||||
class ArrayTest(unittest.TestCase):
|
||||
def test(self):
|
||||
|
|
|
@ -23,7 +23,7 @@ class PythonAPITestCase(unittest.TestCase):
|
|||
PyString_FromStringAndSize.restype = py_object
|
||||
PyString_FromStringAndSize.argtypes = c_char_p, c_py_ssize_t
|
||||
|
||||
self.failUnlessEqual(PyString_FromStringAndSize("abcdefghi", 3), "abc")
|
||||
self.assertEqual(PyString_FromStringAndSize("abcdefghi", 3), "abc")
|
||||
|
||||
def test_PyString_FromString(self):
|
||||
pythonapi.PyString_FromString.restype = py_object
|
||||
|
@ -32,10 +32,10 @@ class PythonAPITestCase(unittest.TestCase):
|
|||
s = "abc"
|
||||
refcnt = grc(s)
|
||||
pyob = pythonapi.PyString_FromString(s)
|
||||
self.failUnlessEqual(grc(s), refcnt)
|
||||
self.failUnlessEqual(s, pyob)
|
||||
self.assertEqual(grc(s), refcnt)
|
||||
self.assertEqual(s, pyob)
|
||||
del pyob
|
||||
self.failUnlessEqual(grc(s), refcnt)
|
||||
self.assertEqual(grc(s), refcnt)
|
||||
|
||||
if is_resource_enabled("refcount"):
|
||||
# This test is unreliable, because it is possible that code in
|
||||
|
@ -44,28 +44,28 @@ class PythonAPITestCase(unittest.TestCase):
|
|||
def test_PyInt_Long(self):
|
||||
ref42 = grc(42)
|
||||
pythonapi.PyInt_FromLong.restype = py_object
|
||||
self.failUnlessEqual(pythonapi.PyInt_FromLong(42), 42)
|
||||
self.assertEqual(pythonapi.PyInt_FromLong(42), 42)
|
||||
|
||||
self.failUnlessEqual(grc(42), ref42)
|
||||
self.assertEqual(grc(42), ref42)
|
||||
|
||||
pythonapi.PyInt_AsLong.argtypes = (py_object,)
|
||||
pythonapi.PyInt_AsLong.restype = c_long
|
||||
|
||||
res = pythonapi.PyInt_AsLong(42)
|
||||
self.failUnlessEqual(grc(res), ref42 + 1)
|
||||
self.assertEqual(grc(res), ref42 + 1)
|
||||
del res
|
||||
self.failUnlessEqual(grc(42), ref42)
|
||||
self.assertEqual(grc(42), ref42)
|
||||
|
||||
def test_PyObj_FromPtr(self):
|
||||
s = "abc def ghi jkl"
|
||||
ref = grc(s)
|
||||
# id(python-object) is the address
|
||||
pyobj = PyObj_FromPtr(id(s))
|
||||
self.failUnless(s is pyobj)
|
||||
self.assertTrue(s is pyobj)
|
||||
|
||||
self.failUnlessEqual(grc(s), ref + 1)
|
||||
self.assertEqual(grc(s), ref + 1)
|
||||
del pyobj
|
||||
self.failUnlessEqual(grc(s), ref)
|
||||
self.assertEqual(grc(s), ref)
|
||||
|
||||
def test_PyOS_snprintf(self):
|
||||
PyOS_snprintf = pythonapi.PyOS_snprintf
|
||||
|
@ -73,18 +73,18 @@ class PythonAPITestCase(unittest.TestCase):
|
|||
|
||||
buf = c_buffer(256)
|
||||
PyOS_snprintf(buf, sizeof(buf), "Hello from %s", "ctypes")
|
||||
self.failUnlessEqual(buf.value, "Hello from ctypes")
|
||||
self.assertEqual(buf.value, "Hello from ctypes")
|
||||
|
||||
PyOS_snprintf(buf, sizeof(buf), "Hello from %s", "ctypes", 1, 2, 3)
|
||||
self.failUnlessEqual(buf.value, "Hello from ctypes")
|
||||
self.assertEqual(buf.value, "Hello from ctypes")
|
||||
|
||||
# not enough arguments
|
||||
self.failUnlessRaises(TypeError, PyOS_snprintf, buf)
|
||||
self.assertRaises(TypeError, PyOS_snprintf, buf)
|
||||
|
||||
def test_pyobject_repr(self):
|
||||
self.failUnlessEqual(repr(py_object()), "py_object(<NULL>)")
|
||||
self.failUnlessEqual(repr(py_object(42)), "py_object(42)")
|
||||
self.failUnlessEqual(repr(py_object(object)), "py_object(%r)" % object)
|
||||
self.assertEqual(repr(py_object()), "py_object(<NULL>)")
|
||||
self.assertEqual(repr(py_object(42)), "py_object(42)")
|
||||
self.assertEqual(repr(py_object(object)), "py_object(%r)" % object)
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
|
@ -20,7 +20,7 @@ if sys.platform == "win32":
|
|||
hdll = windll.kernel32.LoadLibraryA("kernel32")
|
||||
funcaddr = windll.kernel32.GetProcAddress(hdll, "GetModuleHandleA")
|
||||
|
||||
self.failUnlessEqual(call_function(funcaddr, (None,)),
|
||||
self.assertEqual(call_function(funcaddr, (None,)),
|
||||
windll.kernel32.GetModuleHandleA(None))
|
||||
|
||||
class CallbackTracbackTestCase(unittest.TestCase):
|
||||
|
@ -49,25 +49,25 @@ class CallbackTracbackTestCase(unittest.TestCase):
|
|||
def test_ValueError(self):
|
||||
cb = CFUNCTYPE(c_int, c_int)(callback_func)
|
||||
out = self.capture_stderr(cb, 42)
|
||||
self.failUnlessEqual(out.splitlines()[-1],
|
||||
self.assertEqual(out.splitlines()[-1],
|
||||
"ValueError: 42")
|
||||
|
||||
def test_IntegerDivisionError(self):
|
||||
cb = CFUNCTYPE(c_int, c_int)(callback_func)
|
||||
out = self.capture_stderr(cb, 0)
|
||||
self.failUnlessEqual(out.splitlines()[-1][:19],
|
||||
self.assertEqual(out.splitlines()[-1][:19],
|
||||
"ZeroDivisionError: ")
|
||||
|
||||
def test_FloatDivisionError(self):
|
||||
cb = CFUNCTYPE(c_int, c_double)(callback_func)
|
||||
out = self.capture_stderr(cb, 0.0)
|
||||
self.failUnlessEqual(out.splitlines()[-1][:19],
|
||||
self.assertEqual(out.splitlines()[-1][:19],
|
||||
"ZeroDivisionError: ")
|
||||
|
||||
def test_TypeErrorDivisionError(self):
|
||||
cb = CFUNCTYPE(c_int, c_char_p)(callback_func)
|
||||
out = self.capture_stderr(cb, "spam")
|
||||
self.failUnlessEqual(out.splitlines()[-1],
|
||||
self.assertEqual(out.splitlines()[-1],
|
||||
"TypeError: "
|
||||
"unsupported operand type(s) for /: 'int' and 'str'")
|
||||
|
||||
|
|
|
@ -21,17 +21,17 @@ class RefcountTestCase(unittest.TestCase):
|
|||
#print "called back with", value
|
||||
return value
|
||||
|
||||
self.failUnlessEqual(grc(callback), 2)
|
||||
self.assertEqual(grc(callback), 2)
|
||||
cb = MyCallback(callback)
|
||||
|
||||
self.failUnless(grc(callback) > 2)
|
||||
self.assertTrue(grc(callback) > 2)
|
||||
result = f(-10, cb)
|
||||
self.failUnlessEqual(result, -18)
|
||||
self.assertEqual(result, -18)
|
||||
cb = None
|
||||
|
||||
gc.collect()
|
||||
|
||||
self.failUnlessEqual(grc(callback), 2)
|
||||
self.assertEqual(grc(callback), 2)
|
||||
|
||||
|
||||
def test_refcount(self):
|
||||
|
@ -39,19 +39,19 @@ class RefcountTestCase(unittest.TestCase):
|
|||
def func(*args):
|
||||
pass
|
||||
# this is the standard refcount for func
|
||||
self.failUnlessEqual(grc(func), 2)
|
||||
self.assertEqual(grc(func), 2)
|
||||
|
||||
# the CFuncPtr instance holds atr least one refcount on func:
|
||||
f = OtherCallback(func)
|
||||
self.failUnless(grc(func) > 2)
|
||||
self.assertTrue(grc(func) > 2)
|
||||
|
||||
# and may release it again
|
||||
del f
|
||||
self.failUnless(grc(func) >= 2)
|
||||
self.assertTrue(grc(func) >= 2)
|
||||
|
||||
# but now it must be gone
|
||||
gc.collect()
|
||||
self.failUnless(grc(func) == 2)
|
||||
self.assertTrue(grc(func) == 2)
|
||||
|
||||
class X(ctypes.Structure):
|
||||
_fields_ = [("a", OtherCallback)]
|
||||
|
@ -59,27 +59,27 @@ class RefcountTestCase(unittest.TestCase):
|
|||
x.a = OtherCallback(func)
|
||||
|
||||
# the CFuncPtr instance holds atr least one refcount on func:
|
||||
self.failUnless(grc(func) > 2)
|
||||
self.assertTrue(grc(func) > 2)
|
||||
|
||||
# and may release it again
|
||||
del x
|
||||
self.failUnless(grc(func) >= 2)
|
||||
self.assertTrue(grc(func) >= 2)
|
||||
|
||||
# and now it must be gone again
|
||||
gc.collect()
|
||||
self.failUnlessEqual(grc(func), 2)
|
||||
self.assertEqual(grc(func), 2)
|
||||
|
||||
f = OtherCallback(func)
|
||||
|
||||
# the CFuncPtr instance holds atr least one refcount on func:
|
||||
self.failUnless(grc(func) > 2)
|
||||
self.assertTrue(grc(func) > 2)
|
||||
|
||||
# create a cycle
|
||||
f.cycle = f
|
||||
|
||||
del f
|
||||
gc.collect()
|
||||
self.failUnlessEqual(grc(func), 2)
|
||||
self.assertEqual(grc(func), 2)
|
||||
|
||||
class AnotherLeak(unittest.TestCase):
|
||||
def test_callback(self):
|
||||
|
@ -92,7 +92,7 @@ class AnotherLeak(unittest.TestCase):
|
|||
|
||||
a = sys.getrefcount(ctypes.c_int)
|
||||
f(1, 2)
|
||||
self.failUnlessEqual(sys.getrefcount(ctypes.c_int), a)
|
||||
self.assertEqual(sys.getrefcount(ctypes.c_int), a)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -18,12 +18,12 @@ class ReprTest(unittest.TestCase):
|
|||
def test_numbers(self):
|
||||
for typ in subclasses:
|
||||
base = typ.__bases__[0]
|
||||
self.failUnless(repr(base(42)).startswith(base.__name__))
|
||||
self.failUnlessEqual("<X object at", repr(typ(42))[:12])
|
||||
self.assertTrue(repr(base(42)).startswith(base.__name__))
|
||||
self.assertEqual("<X object at", repr(typ(42))[:12])
|
||||
|
||||
def test_char(self):
|
||||
self.failUnlessEqual("c_char('x')", repr(c_char('x')))
|
||||
self.failUnlessEqual("<X object at", repr(X('x'))[:12])
|
||||
self.assertEqual("c_char('x')", repr(c_char('x')))
|
||||
self.assertEqual("<X object at", repr(X('x'))[:12])
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
|
@ -12,8 +12,8 @@ class ReturnFuncPtrTestCase(unittest.TestCase):
|
|||
get_strchr = dll.get_strchr
|
||||
get_strchr.restype = CFUNCTYPE(c_char_p, c_char_p, c_char)
|
||||
strchr = get_strchr()
|
||||
self.failUnlessEqual(strchr("abcdef", "b"), "bcdef")
|
||||
self.failUnlessEqual(strchr("abcdef", "x"), None)
|
||||
self.assertEqual(strchr("abcdef", "b"), "bcdef")
|
||||
self.assertEqual(strchr("abcdef", "x"), None)
|
||||
self.assertRaises(ArgumentError, strchr, "abcdef", 3)
|
||||
self.assertRaises(TypeError, strchr, "abcdef")
|
||||
|
||||
|
@ -26,8 +26,8 @@ class ReturnFuncPtrTestCase(unittest.TestCase):
|
|||
# _CFuncPtr instances are now callable with an integer argument
|
||||
# which denotes a function address:
|
||||
strchr = CFUNCTYPE(c_char_p, c_char_p, c_char)(addr)
|
||||
self.failUnless(strchr("abcdef", "b"), "bcdef")
|
||||
self.failUnlessEqual(strchr("abcdef", "x"), None)
|
||||
self.assertTrue(strchr("abcdef", "b"), "bcdef")
|
||||
self.assertEqual(strchr("abcdef", "x"), None)
|
||||
self.assertRaises(ArgumentError, strchr, "abcdef", 3)
|
||||
self.assertRaises(TypeError, strchr, "abcdef")
|
||||
|
||||
|
|
|
@ -12,8 +12,8 @@ class MyInt(c_int):
|
|||
class Test(unittest.TestCase):
|
||||
|
||||
def test_compare(self):
|
||||
self.failUnlessEqual(MyInt(3), MyInt(3))
|
||||
self.failIfEqual(MyInt(42), MyInt(43))
|
||||
self.assertEqual(MyInt(3), MyInt(3))
|
||||
self.assertNotEqual(MyInt(42), MyInt(43))
|
||||
|
||||
def test_ignore_retval(self):
|
||||
# Test if the return value of a callback is ignored
|
||||
|
@ -23,7 +23,7 @@ class Test(unittest.TestCase):
|
|||
return (1, "abc", None)
|
||||
|
||||
cb = proto(func)
|
||||
self.failUnlessEqual(None, cb())
|
||||
self.assertEqual(None, cb())
|
||||
|
||||
|
||||
def test_int_callback(self):
|
||||
|
@ -34,24 +34,24 @@ class Test(unittest.TestCase):
|
|||
|
||||
cb = CFUNCTYPE(None, MyInt)(func)
|
||||
|
||||
self.failUnlessEqual(None, cb(42))
|
||||
self.failUnlessEqual(type(args[-1]), MyInt)
|
||||
self.assertEqual(None, cb(42))
|
||||
self.assertEqual(type(args[-1]), MyInt)
|
||||
|
||||
cb = CFUNCTYPE(c_int, c_int)(func)
|
||||
|
||||
self.failUnlessEqual(42, cb(42))
|
||||
self.failUnlessEqual(type(args[-1]), int)
|
||||
self.assertEqual(42, cb(42))
|
||||
self.assertEqual(type(args[-1]), int)
|
||||
|
||||
def test_int_struct(self):
|
||||
class X(Structure):
|
||||
_fields_ = [("x", MyInt)]
|
||||
|
||||
self.failUnlessEqual(X().x, MyInt())
|
||||
self.assertEqual(X().x, MyInt())
|
||||
|
||||
s = X()
|
||||
s.x = MyInt(42)
|
||||
|
||||
self.failUnlessEqual(s.x, MyInt(42))
|
||||
self.assertEqual(s.x, MyInt(42))
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
|
@ -5,23 +5,23 @@ from ctypes import *
|
|||
|
||||
class SizesTestCase(unittest.TestCase):
|
||||
def test_8(self):
|
||||
self.failUnlessEqual(1, sizeof(c_int8))
|
||||
self.failUnlessEqual(1, sizeof(c_uint8))
|
||||
self.assertEqual(1, sizeof(c_int8))
|
||||
self.assertEqual(1, sizeof(c_uint8))
|
||||
|
||||
def test_16(self):
|
||||
self.failUnlessEqual(2, sizeof(c_int16))
|
||||
self.failUnlessEqual(2, sizeof(c_uint16))
|
||||
self.assertEqual(2, sizeof(c_int16))
|
||||
self.assertEqual(2, sizeof(c_uint16))
|
||||
|
||||
def test_32(self):
|
||||
self.failUnlessEqual(4, sizeof(c_int32))
|
||||
self.failUnlessEqual(4, sizeof(c_uint32))
|
||||
self.assertEqual(4, sizeof(c_int32))
|
||||
self.assertEqual(4, sizeof(c_uint32))
|
||||
|
||||
def test_64(self):
|
||||
self.failUnlessEqual(8, sizeof(c_int64))
|
||||
self.failUnlessEqual(8, sizeof(c_uint64))
|
||||
self.assertEqual(8, sizeof(c_int64))
|
||||
self.assertEqual(8, sizeof(c_uint64))
|
||||
|
||||
def test_size_t(self):
|
||||
self.failUnlessEqual(sizeof(c_void_p), sizeof(c_size_t))
|
||||
self.assertEqual(sizeof(c_void_p), sizeof(c_size_t))
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
|
@ -7,43 +7,43 @@ class SlicesTestCase(unittest.TestCase):
|
|||
def test_getslice_cint(self):
|
||||
a = (c_int * 100)(*xrange(1100, 1200))
|
||||
b = range(1100, 1200)
|
||||
self.failUnlessEqual(a[0:2], b[0:2])
|
||||
self.failUnlessEqual(a[0:2:], b[0:2:])
|
||||
self.failUnlessEqual(len(a), len(b))
|
||||
self.failUnlessEqual(a[5:7], b[5:7])
|
||||
self.failUnlessEqual(a[5:7:], b[5:7:])
|
||||
self.failUnlessEqual(a[-1], b[-1])
|
||||
self.failUnlessEqual(a[:], b[:])
|
||||
self.failUnlessEqual(a[::], b[::])
|
||||
self.failUnlessEqual(a[10::-1], b[10::-1])
|
||||
self.failUnlessEqual(a[30:20:-1], b[30:20:-1])
|
||||
self.failUnlessEqual(a[:12:6], b[:12:6])
|
||||
self.failUnlessEqual(a[2:6:4], b[2:6:4])
|
||||
self.assertEqual(a[0:2], b[0:2])
|
||||
self.assertEqual(a[0:2:], b[0:2:])
|
||||
self.assertEqual(len(a), len(b))
|
||||
self.assertEqual(a[5:7], b[5:7])
|
||||
self.assertEqual(a[5:7:], b[5:7:])
|
||||
self.assertEqual(a[-1], b[-1])
|
||||
self.assertEqual(a[:], b[:])
|
||||
self.assertEqual(a[::], b[::])
|
||||
self.assertEqual(a[10::-1], b[10::-1])
|
||||
self.assertEqual(a[30:20:-1], b[30:20:-1])
|
||||
self.assertEqual(a[:12:6], b[:12:6])
|
||||
self.assertEqual(a[2:6:4], b[2:6:4])
|
||||
|
||||
a[0:5] = range(5, 10)
|
||||
self.failUnlessEqual(a[0:5], range(5, 10))
|
||||
self.failUnlessEqual(a[0:5:], range(5, 10))
|
||||
self.failUnlessEqual(a[4::-1], range(9, 4, -1))
|
||||
self.assertEqual(a[0:5], range(5, 10))
|
||||
self.assertEqual(a[0:5:], range(5, 10))
|
||||
self.assertEqual(a[4::-1], range(9, 4, -1))
|
||||
|
||||
def test_setslice_cint(self):
|
||||
a = (c_int * 100)(*xrange(1100, 1200))
|
||||
b = range(1100, 1200)
|
||||
|
||||
a[32:47] = range(32, 47)
|
||||
self.failUnlessEqual(a[32:47], range(32, 47))
|
||||
self.assertEqual(a[32:47], range(32, 47))
|
||||
a[32:47] = range(132, 147)
|
||||
self.failUnlessEqual(a[32:47:], range(132, 147))
|
||||
self.assertEqual(a[32:47:], range(132, 147))
|
||||
a[46:31:-1] = range(232, 247)
|
||||
self.failUnlessEqual(a[32:47:1], range(246, 231, -1))
|
||||
self.assertEqual(a[32:47:1], range(246, 231, -1))
|
||||
|
||||
a[32:47] = range(1132, 1147)
|
||||
self.failUnlessEqual(a[:], b)
|
||||
self.assertEqual(a[:], b)
|
||||
a[32:47:7] = range(3)
|
||||
b[32:47:7] = range(3)
|
||||
self.failUnlessEqual(a[:], b)
|
||||
self.assertEqual(a[:], b)
|
||||
a[33::-3] = range(12)
|
||||
b[33::-3] = range(12)
|
||||
self.failUnlessEqual(a[:], b)
|
||||
self.assertEqual(a[:], b)
|
||||
|
||||
from operator import setslice, setitem
|
||||
|
||||
|
@ -69,12 +69,12 @@ class SlicesTestCase(unittest.TestCase):
|
|||
dll.my_strdup.restype = POINTER(c_char)
|
||||
dll.my_free.restype = None
|
||||
res = dll.my_strdup(s)
|
||||
self.failUnlessEqual(res[:len(s)], s)
|
||||
self.failUnlessEqual(res[:3], s[:3])
|
||||
self.failUnlessEqual(res[:len(s):], s)
|
||||
self.failUnlessEqual(res[len(s)-1:-1:-1], s[::-1])
|
||||
self.failUnlessEqual(res[len(s)-1:5:-7], s[:5:-7])
|
||||
self.failUnlessEqual(res[0:-1:-1], s[0::-1])
|
||||
self.assertEqual(res[:len(s)], s)
|
||||
self.assertEqual(res[:3], s[:3])
|
||||
self.assertEqual(res[:len(s):], s)
|
||||
self.assertEqual(res[len(s)-1:-1:-1], s[::-1])
|
||||
self.assertEqual(res[len(s)-1:5:-7], s[:5:-7])
|
||||
self.assertEqual(res[0:-1:-1], s[0::-1])
|
||||
|
||||
import operator
|
||||
self.assertRaises(ValueError, operator.getitem,
|
||||
|
@ -94,8 +94,8 @@ class SlicesTestCase(unittest.TestCase):
|
|||
|
||||
dll.my_strdup.restype = POINTER(c_byte)
|
||||
res = dll.my_strdup(s)
|
||||
self.failUnlessEqual(res[:len(s)], range(ord("a"), ord("z")+1))
|
||||
self.failUnlessEqual(res[:len(s):], range(ord("a"), ord("z")+1))
|
||||
self.assertEqual(res[:len(s)], range(ord("a"), ord("z")+1))
|
||||
self.assertEqual(res[:len(s):], range(ord("a"), ord("z")+1))
|
||||
dll.my_free(res)
|
||||
|
||||
def test_char_ptr_with_free(self):
|
||||
|
@ -115,7 +115,7 @@ class SlicesTestCase(unittest.TestCase):
|
|||
dll.my_strdup.errcheck = errcheck
|
||||
try:
|
||||
res = dll.my_strdup(s)
|
||||
self.failUnlessEqual(res, s)
|
||||
self.assertEqual(res, s)
|
||||
finally:
|
||||
del dll.my_strdup.errcheck
|
||||
|
||||
|
@ -124,11 +124,11 @@ class SlicesTestCase(unittest.TestCase):
|
|||
s = "abcdefghijklmnopqrstuvwxyz\0"
|
||||
|
||||
p = (c_char * 27)(*s)
|
||||
self.failUnlessEqual(p[:], s)
|
||||
self.failUnlessEqual(p[::], s)
|
||||
self.failUnlessEqual(p[::-1], s[::-1])
|
||||
self.failUnlessEqual(p[5::-2], s[5::-2])
|
||||
self.failUnlessEqual(p[2:5:-3], s[2:5:-3])
|
||||
self.assertEqual(p[:], s)
|
||||
self.assertEqual(p[::], s)
|
||||
self.assertEqual(p[::-1], s[::-1])
|
||||
self.assertEqual(p[5::-2], s[5::-2])
|
||||
self.assertEqual(p[2:5:-3], s[2:5:-3])
|
||||
|
||||
|
||||
try:
|
||||
|
@ -144,10 +144,10 @@ class SlicesTestCase(unittest.TestCase):
|
|||
dll.my_wcsdup.argtypes = POINTER(c_wchar),
|
||||
dll.my_free.restype = None
|
||||
res = dll.my_wcsdup(s)
|
||||
self.failUnlessEqual(res[:len(s)], s)
|
||||
self.failUnlessEqual(res[:len(s):], s)
|
||||
self.failUnlessEqual(res[len(s)-1:-1:-1], s[::-1])
|
||||
self.failUnlessEqual(res[len(s)-1:5:-7], s[:5:-7])
|
||||
self.assertEqual(res[:len(s)], s)
|
||||
self.assertEqual(res[:len(s):], s)
|
||||
self.assertEqual(res[len(s)-1:-1:-1], s[::-1])
|
||||
self.assertEqual(res[len(s)-1:5:-7], s[:5:-7])
|
||||
|
||||
import operator
|
||||
self.assertRaises(TypeError, operator.setslice,
|
||||
|
@ -166,10 +166,10 @@ class SlicesTestCase(unittest.TestCase):
|
|||
return
|
||||
res = dll.my_wcsdup(s)
|
||||
tmpl = range(ord("a"), ord("z")+1)
|
||||
self.failUnlessEqual(res[:len(s)-1], tmpl)
|
||||
self.failUnlessEqual(res[:len(s)-1:], tmpl)
|
||||
self.failUnlessEqual(res[len(s)-2:-1:-1], tmpl[::-1])
|
||||
self.failUnlessEqual(res[len(s)-2:5:-7], tmpl[:5:-7])
|
||||
self.assertEqual(res[:len(s)-1], tmpl)
|
||||
self.assertEqual(res[:len(s)-1:], tmpl)
|
||||
self.assertEqual(res[len(s)-2:-1:-1], tmpl[::-1])
|
||||
self.assertEqual(res[len(s)-2:5:-7], tmpl[:5:-7])
|
||||
dll.my_free(res)
|
||||
|
||||
################################################################
|
||||
|
|
|
@ -16,14 +16,14 @@ class StringPtrTestCase(unittest.TestCase):
|
|||
self.assertRaises(ValueError, getattr, x.str, "contents")
|
||||
b = c_buffer("Hello, World")
|
||||
from sys import getrefcount as grc
|
||||
self.failUnlessEqual(grc(b), 2)
|
||||
self.assertEqual(grc(b), 2)
|
||||
x.str = b
|
||||
self.failUnlessEqual(grc(b), 3)
|
||||
self.assertEqual(grc(b), 3)
|
||||
|
||||
# POINTER(c_char) and Python string is NOT compatible
|
||||
# POINTER(c_char) and c_buffer() is compatible
|
||||
for i in range(len(b)):
|
||||
self.failUnlessEqual(b[i], x.str[i])
|
||||
self.assertEqual(b[i], x.str[i])
|
||||
|
||||
self.assertRaises(TypeError, setattr, x, "str", "Hello, World")
|
||||
|
||||
|
@ -34,11 +34,11 @@ class StringPtrTestCase(unittest.TestCase):
|
|||
|
||||
# c_char_p and Python string is compatible
|
||||
# c_char_p and c_buffer is NOT compatible
|
||||
self.failUnlessEqual(x.str, None)
|
||||
self.assertEqual(x.str, None)
|
||||
x.str = "Hello, World"
|
||||
self.failUnlessEqual(x.str, "Hello, World")
|
||||
self.assertEqual(x.str, "Hello, World")
|
||||
b = c_buffer("Hello, World")
|
||||
self.failUnlessRaises(TypeError, setattr, x, "str", b)
|
||||
self.assertRaises(TypeError, setattr, x, "str", b)
|
||||
|
||||
|
||||
def test_functions(self):
|
||||
|
@ -48,15 +48,15 @@ class StringPtrTestCase(unittest.TestCase):
|
|||
# c_char_p and Python string is compatible
|
||||
# c_char_p and c_buffer are now compatible
|
||||
strchr.argtypes = c_char_p, c_char
|
||||
self.failUnlessEqual(strchr("abcdef", "c"), "cdef")
|
||||
self.failUnlessEqual(strchr(c_buffer("abcdef"), "c"), "cdef")
|
||||
self.assertEqual(strchr("abcdef", "c"), "cdef")
|
||||
self.assertEqual(strchr(c_buffer("abcdef"), "c"), "cdef")
|
||||
|
||||
# POINTER(c_char) and Python string is NOT compatible
|
||||
# POINTER(c_char) and c_buffer() is compatible
|
||||
strchr.argtypes = POINTER(c_char), c_char
|
||||
buf = c_buffer("abcdef")
|
||||
self.failUnlessEqual(strchr(buf, "c"), "cdef")
|
||||
self.failUnlessEqual(strchr("abcdef", "c"), "cdef")
|
||||
self.assertEqual(strchr(buf, "c"), "cdef")
|
||||
self.assertEqual(strchr("abcdef", "c"), "cdef")
|
||||
|
||||
# XXX These calls are dangerous, because the first argument
|
||||
# to strchr is no longer valid after the function returns!
|
||||
|
@ -66,7 +66,7 @@ class StringPtrTestCase(unittest.TestCase):
|
|||
buf = c_buffer("abcdef")
|
||||
r = strchr(buf, "c")
|
||||
x = r[0], r[1], r[2], r[3], r[4]
|
||||
self.failUnlessEqual(x, ("c", "d", "e", "f", "\000"))
|
||||
self.assertEqual(x, ("c", "d", "e", "f", "\000"))
|
||||
del buf
|
||||
# x1 will NOT be the same as x, usually:
|
||||
x1 = r[0], r[1], r[2], r[3], r[4]
|
||||
|
|
|
@ -6,20 +6,20 @@ class StringArrayTestCase(unittest.TestCase):
|
|||
BUF = c_char * 4
|
||||
|
||||
buf = BUF("a", "b", "c")
|
||||
self.failUnlessEqual(buf.value, "abc")
|
||||
self.failUnlessEqual(buf.raw, "abc\000")
|
||||
self.assertEqual(buf.value, "abc")
|
||||
self.assertEqual(buf.raw, "abc\000")
|
||||
|
||||
buf.value = "ABCD"
|
||||
self.failUnlessEqual(buf.value, "ABCD")
|
||||
self.failUnlessEqual(buf.raw, "ABCD")
|
||||
self.assertEqual(buf.value, "ABCD")
|
||||
self.assertEqual(buf.raw, "ABCD")
|
||||
|
||||
buf.value = "x"
|
||||
self.failUnlessEqual(buf.value, "x")
|
||||
self.failUnlessEqual(buf.raw, "x\000CD")
|
||||
self.assertEqual(buf.value, "x")
|
||||
self.assertEqual(buf.raw, "x\000CD")
|
||||
|
||||
buf[1] = "Z"
|
||||
self.failUnlessEqual(buf.value, "xZCD")
|
||||
self.failUnlessEqual(buf.raw, "xZCD")
|
||||
self.assertEqual(buf.value, "xZCD")
|
||||
self.assertEqual(buf.raw, "xZCD")
|
||||
|
||||
self.assertRaises(ValueError, setattr, buf, "value", "aaaaaaaa")
|
||||
self.assertRaises(TypeError, setattr, buf, "value", 42)
|
||||
|
@ -28,9 +28,9 @@ class StringArrayTestCase(unittest.TestCase):
|
|||
buf = c_buffer(32)
|
||||
|
||||
buf.value = "Hello, World"
|
||||
self.failUnlessEqual(buf.value, "Hello, World")
|
||||
self.assertEqual(buf.value, "Hello, World")
|
||||
|
||||
self.failUnlessRaises(TypeError, setattr, buf, "value", buffer("Hello, World"))
|
||||
self.assertRaises(TypeError, setattr, buf, "value", buffer("Hello, World"))
|
||||
self.assertRaises(TypeError, setattr, buf, "value", buffer("abc"))
|
||||
self.assertRaises(ValueError, setattr, buf, "raw", buffer("x" * 100))
|
||||
|
||||
|
@ -38,7 +38,7 @@ class StringArrayTestCase(unittest.TestCase):
|
|||
buf = c_buffer(32)
|
||||
|
||||
buf.raw = buffer("Hello, World")
|
||||
self.failUnlessEqual(buf.value, "Hello, World")
|
||||
self.assertEqual(buf.value, "Hello, World")
|
||||
self.assertRaises(TypeError, setattr, buf, "value", buffer("abc"))
|
||||
self.assertRaises(ValueError, setattr, buf, "raw", buffer("x" * 100))
|
||||
|
||||
|
@ -63,16 +63,16 @@ else:
|
|||
BUF = c_wchar * 4
|
||||
|
||||
buf = BUF(u"a", u"b", u"c")
|
||||
self.failUnlessEqual(buf.value, u"abc")
|
||||
self.assertEqual(buf.value, u"abc")
|
||||
|
||||
buf.value = u"ABCD"
|
||||
self.failUnlessEqual(buf.value, u"ABCD")
|
||||
self.assertEqual(buf.value, u"ABCD")
|
||||
|
||||
buf.value = u"x"
|
||||
self.failUnlessEqual(buf.value, u"x")
|
||||
self.assertEqual(buf.value, u"x")
|
||||
|
||||
buf[1] = u"Z"
|
||||
self.failUnlessEqual(buf.value, u"xZCD")
|
||||
self.assertEqual(buf.value, u"xZCD")
|
||||
|
||||
class StringTestCase(unittest.TestCase):
|
||||
def XX_test_basic_strings(self):
|
||||
|
@ -80,24 +80,24 @@ class StringTestCase(unittest.TestCase):
|
|||
|
||||
# Cannot call len on a c_string any longer
|
||||
self.assertRaises(TypeError, len, cs)
|
||||
self.failUnlessEqual(sizeof(cs), 7)
|
||||
self.assertEqual(sizeof(cs), 7)
|
||||
|
||||
# The value property is the string up to the first terminating NUL.
|
||||
self.failUnlessEqual(cs.value, "abcdef")
|
||||
self.failUnlessEqual(c_string("abc\000def").value, "abc")
|
||||
self.assertEqual(cs.value, "abcdef")
|
||||
self.assertEqual(c_string("abc\000def").value, "abc")
|
||||
|
||||
# The raw property is the total buffer contents:
|
||||
self.failUnlessEqual(cs.raw, "abcdef\000")
|
||||
self.failUnlessEqual(c_string("abc\000def").raw, "abc\000def\000")
|
||||
self.assertEqual(cs.raw, "abcdef\000")
|
||||
self.assertEqual(c_string("abc\000def").raw, "abc\000def\000")
|
||||
|
||||
# We can change the value:
|
||||
cs.value = "ab"
|
||||
self.failUnlessEqual(cs.value, "ab")
|
||||
self.failUnlessEqual(cs.raw, "ab\000\000\000\000\000")
|
||||
self.assertEqual(cs.value, "ab")
|
||||
self.assertEqual(cs.raw, "ab\000\000\000\000\000")
|
||||
|
||||
cs.raw = "XY"
|
||||
self.failUnlessEqual(cs.value, "XY")
|
||||
self.failUnlessEqual(cs.raw, "XY\000\000\000\000\000")
|
||||
self.assertEqual(cs.value, "XY")
|
||||
self.assertEqual(cs.raw, "XY\000\000\000\000\000")
|
||||
|
||||
self.assertRaises(TypeError, c_string, u"123")
|
||||
|
||||
|
@ -108,24 +108,24 @@ class StringTestCase(unittest.TestCase):
|
|||
|
||||
# New in releases later than 0.4.0:
|
||||
# c_string(number) returns an empty string of size number
|
||||
self.failUnless(len(c_string(32).raw) == 32)
|
||||
self.assertTrue(len(c_string(32).raw) == 32)
|
||||
self.assertRaises(ValueError, c_string, -1)
|
||||
self.assertRaises(ValueError, c_string, 0)
|
||||
|
||||
# These tests fail, because it is no longer initialized
|
||||
## self.failUnless(c_string(2).value == "")
|
||||
## self.failUnless(c_string(2).raw == "\000\000")
|
||||
self.failUnless(c_string(2).raw[-1] == "\000")
|
||||
self.failUnless(len(c_string(2).raw) == 2)
|
||||
## self.assertTrue(c_string(2).value == "")
|
||||
## self.assertTrue(c_string(2).raw == "\000\000")
|
||||
self.assertTrue(c_string(2).raw[-1] == "\000")
|
||||
self.assertTrue(len(c_string(2).raw) == 2)
|
||||
|
||||
def XX_test_initialized_strings(self):
|
||||
|
||||
self.failUnless(c_string("ab", 4).raw[:2] == "ab")
|
||||
self.failUnless(c_string("ab", 4).raw[:2:] == "ab")
|
||||
self.failUnless(c_string("ab", 4).raw[:2:-1] == "ba")
|
||||
self.failUnless(c_string("ab", 4).raw[:2:2] == "a")
|
||||
self.failUnless(c_string("ab", 4).raw[-1] == "\000")
|
||||
self.failUnless(c_string("ab", 2).raw == "a\000")
|
||||
self.assertTrue(c_string("ab", 4).raw[:2] == "ab")
|
||||
self.assertTrue(c_string("ab", 4).raw[:2:] == "ab")
|
||||
self.assertTrue(c_string("ab", 4).raw[:2:-1] == "ba")
|
||||
self.assertTrue(c_string("ab", 4).raw[:2:2] == "a")
|
||||
self.assertTrue(c_string("ab", 4).raw[-1] == "\000")
|
||||
self.assertTrue(c_string("ab", 2).raw == "a\000")
|
||||
|
||||
def XX_test_toolong(self):
|
||||
cs = c_string("abcdef")
|
||||
|
@ -156,22 +156,22 @@ else:
|
|||
# XXX This behaviour is about to change:
|
||||
# len returns the size of the internal buffer in bytes.
|
||||
# This includes the terminating NUL character.
|
||||
self.failUnless(sizeof(cs) == 14)
|
||||
self.assertTrue(sizeof(cs) == 14)
|
||||
|
||||
# The value property is the string up to the first terminating NUL.
|
||||
self.failUnless(cs.value == u"abcdef")
|
||||
self.failUnless(c_wstring(u"abc\000def").value == u"abc")
|
||||
self.assertTrue(cs.value == u"abcdef")
|
||||
self.assertTrue(c_wstring(u"abc\000def").value == u"abc")
|
||||
|
||||
self.failUnless(c_wstring(u"abc\000def").value == u"abc")
|
||||
self.assertTrue(c_wstring(u"abc\000def").value == u"abc")
|
||||
|
||||
# The raw property is the total buffer contents:
|
||||
self.failUnless(cs.raw == u"abcdef\000")
|
||||
self.failUnless(c_wstring(u"abc\000def").raw == u"abc\000def\000")
|
||||
self.assertTrue(cs.raw == u"abcdef\000")
|
||||
self.assertTrue(c_wstring(u"abc\000def").raw == u"abc\000def\000")
|
||||
|
||||
# We can change the value:
|
||||
cs.value = u"ab"
|
||||
self.failUnless(cs.value == u"ab")
|
||||
self.failUnless(cs.raw == u"ab\000\000\000\000\000")
|
||||
self.assertTrue(cs.value == u"ab")
|
||||
self.assertTrue(cs.raw == u"ab\000\000\000\000\000")
|
||||
|
||||
self.assertRaises(TypeError, c_wstring, "123")
|
||||
self.assertRaises(ValueError, c_wstring, 0)
|
||||
|
|
|
@ -15,7 +15,7 @@ class StructFieldsTestCase(unittest.TestCase):
|
|||
def test_1_A(self):
|
||||
class X(Structure):
|
||||
pass
|
||||
self.failUnlessEqual(sizeof(X), 0) # not finalized
|
||||
self.assertEqual(sizeof(X), 0) # not finalized
|
||||
X._fields_ = [] # finalized
|
||||
self.assertRaises(AttributeError, setattr, X, "_fields_", [])
|
||||
|
||||
|
|
|
@ -13,33 +13,33 @@ class SubclassesTest(unittest.TestCase):
|
|||
class Z(X):
|
||||
pass
|
||||
|
||||
self.failUnlessEqual(sizeof(X), sizeof(c_int))
|
||||
self.failUnlessEqual(sizeof(Y), sizeof(c_int)*2)
|
||||
self.failUnlessEqual(sizeof(Z), sizeof(c_int))
|
||||
self.failUnlessEqual(X._fields_, [("a", c_int)])
|
||||
self.failUnlessEqual(Y._fields_, [("b", c_int)])
|
||||
self.failUnlessEqual(Z._fields_, [("a", c_int)])
|
||||
self.assertEqual(sizeof(X), sizeof(c_int))
|
||||
self.assertEqual(sizeof(Y), sizeof(c_int)*2)
|
||||
self.assertEqual(sizeof(Z), sizeof(c_int))
|
||||
self.assertEqual(X._fields_, [("a", c_int)])
|
||||
self.assertEqual(Y._fields_, [("b", c_int)])
|
||||
self.assertEqual(Z._fields_, [("a", c_int)])
|
||||
|
||||
def test_subclass_delayed(self):
|
||||
class X(Structure):
|
||||
pass
|
||||
self.failUnlessEqual(sizeof(X), 0)
|
||||
self.assertEqual(sizeof(X), 0)
|
||||
X._fields_ = [("a", c_int)]
|
||||
|
||||
class Y(X):
|
||||
pass
|
||||
self.failUnlessEqual(sizeof(Y), sizeof(X))
|
||||
self.assertEqual(sizeof(Y), sizeof(X))
|
||||
Y._fields_ = [("b", c_int)]
|
||||
|
||||
class Z(X):
|
||||
pass
|
||||
|
||||
self.failUnlessEqual(sizeof(X), sizeof(c_int))
|
||||
self.failUnlessEqual(sizeof(Y), sizeof(c_int)*2)
|
||||
self.failUnlessEqual(sizeof(Z), sizeof(c_int))
|
||||
self.failUnlessEqual(X._fields_, [("a", c_int)])
|
||||
self.failUnlessEqual(Y._fields_, [("b", c_int)])
|
||||
self.failUnlessEqual(Z._fields_, [("a", c_int)])
|
||||
self.assertEqual(sizeof(X), sizeof(c_int))
|
||||
self.assertEqual(sizeof(Y), sizeof(c_int)*2)
|
||||
self.assertEqual(sizeof(Z), sizeof(c_int))
|
||||
self.assertEqual(X._fields_, [("a", c_int)])
|
||||
self.assertEqual(Y._fields_, [("b", c_int)])
|
||||
self.assertEqual(Z._fields_, [("a", c_int)])
|
||||
|
||||
class StructureTestCase(unittest.TestCase):
|
||||
formats = {"c": c_char,
|
||||
|
@ -62,7 +62,7 @@ class StructureTestCase(unittest.TestCase):
|
|||
class X(Structure):
|
||||
_fields_ = [("x", c_char),
|
||||
("y", tp)]
|
||||
self.failUnlessEqual((sizeof(X), code),
|
||||
self.assertEqual((sizeof(X), code),
|
||||
(calcsize("c%c0%c" % (code, code)), code))
|
||||
|
||||
def test_unions(self):
|
||||
|
@ -70,39 +70,39 @@ class StructureTestCase(unittest.TestCase):
|
|||
class X(Union):
|
||||
_fields_ = [("x", c_char),
|
||||
("y", tp)]
|
||||
self.failUnlessEqual((sizeof(X), code),
|
||||
self.assertEqual((sizeof(X), code),
|
||||
(calcsize("%c" % (code)), code))
|
||||
|
||||
def test_struct_alignment(self):
|
||||
class X(Structure):
|
||||
_fields_ = [("x", c_char * 3)]
|
||||
self.failUnlessEqual(alignment(X), calcsize("s"))
|
||||
self.failUnlessEqual(sizeof(X), calcsize("3s"))
|
||||
self.assertEqual(alignment(X), calcsize("s"))
|
||||
self.assertEqual(sizeof(X), calcsize("3s"))
|
||||
|
||||
class Y(Structure):
|
||||
_fields_ = [("x", c_char * 3),
|
||||
("y", c_int)]
|
||||
self.failUnlessEqual(alignment(Y), calcsize("i"))
|
||||
self.failUnlessEqual(sizeof(Y), calcsize("3si"))
|
||||
self.assertEqual(alignment(Y), calcsize("i"))
|
||||
self.assertEqual(sizeof(Y), calcsize("3si"))
|
||||
|
||||
class SI(Structure):
|
||||
_fields_ = [("a", X),
|
||||
("b", Y)]
|
||||
self.failUnlessEqual(alignment(SI), max(alignment(Y), alignment(X)))
|
||||
self.failUnlessEqual(sizeof(SI), calcsize("3s0i 3si 0i"))
|
||||
self.assertEqual(alignment(SI), max(alignment(Y), alignment(X)))
|
||||
self.assertEqual(sizeof(SI), calcsize("3s0i 3si 0i"))
|
||||
|
||||
class IS(Structure):
|
||||
_fields_ = [("b", Y),
|
||||
("a", X)]
|
||||
|
||||
self.failUnlessEqual(alignment(SI), max(alignment(X), alignment(Y)))
|
||||
self.failUnlessEqual(sizeof(IS), calcsize("3si 3s 0i"))
|
||||
self.assertEqual(alignment(SI), max(alignment(X), alignment(Y)))
|
||||
self.assertEqual(sizeof(IS), calcsize("3si 3s 0i"))
|
||||
|
||||
class XX(Structure):
|
||||
_fields_ = [("a", X),
|
||||
("b", X)]
|
||||
self.failUnlessEqual(alignment(XX), alignment(X))
|
||||
self.failUnlessEqual(sizeof(XX), calcsize("3s 3s 0s"))
|
||||
self.assertEqual(alignment(XX), alignment(X))
|
||||
self.assertEqual(sizeof(XX), calcsize("3s 3s 0s"))
|
||||
|
||||
def test_emtpy(self):
|
||||
# I had problems with these
|
||||
|
@ -115,15 +115,15 @@ class StructureTestCase(unittest.TestCase):
|
|||
_fields_ = []
|
||||
|
||||
# Is this really the correct alignment, or should it be 0?
|
||||
self.failUnless(alignment(X) == alignment(Y) == 1)
|
||||
self.failUnless(sizeof(X) == sizeof(Y) == 0)
|
||||
self.assertTrue(alignment(X) == alignment(Y) == 1)
|
||||
self.assertTrue(sizeof(X) == sizeof(Y) == 0)
|
||||
|
||||
class XX(Structure):
|
||||
_fields_ = [("a", X),
|
||||
("b", X)]
|
||||
|
||||
self.failUnlessEqual(alignment(XX), 1)
|
||||
self.failUnlessEqual(sizeof(XX), 0)
|
||||
self.assertEqual(alignment(XX), 1)
|
||||
self.assertEqual(sizeof(XX), 0)
|
||||
|
||||
def test_fields(self):
|
||||
# test the offset and size attributes of Structure/Unoin fields.
|
||||
|
@ -131,11 +131,11 @@ class StructureTestCase(unittest.TestCase):
|
|||
_fields_ = [("x", c_int),
|
||||
("y", c_char)]
|
||||
|
||||
self.failUnlessEqual(X.x.offset, 0)
|
||||
self.failUnlessEqual(X.x.size, sizeof(c_int))
|
||||
self.assertEqual(X.x.offset, 0)
|
||||
self.assertEqual(X.x.size, sizeof(c_int))
|
||||
|
||||
self.failUnlessEqual(X.y.offset, sizeof(c_int))
|
||||
self.failUnlessEqual(X.y.size, sizeof(c_char))
|
||||
self.assertEqual(X.y.offset, sizeof(c_int))
|
||||
self.assertEqual(X.y.size, sizeof(c_char))
|
||||
|
||||
# readonly
|
||||
self.assertRaises((TypeError, AttributeError), setattr, X.x, "offset", 92)
|
||||
|
@ -145,11 +145,11 @@ class StructureTestCase(unittest.TestCase):
|
|||
_fields_ = [("x", c_int),
|
||||
("y", c_char)]
|
||||
|
||||
self.failUnlessEqual(X.x.offset, 0)
|
||||
self.failUnlessEqual(X.x.size, sizeof(c_int))
|
||||
self.assertEqual(X.x.offset, 0)
|
||||
self.assertEqual(X.x.size, sizeof(c_int))
|
||||
|
||||
self.failUnlessEqual(X.y.offset, 0)
|
||||
self.failUnlessEqual(X.y.size, sizeof(c_char))
|
||||
self.assertEqual(X.y.offset, 0)
|
||||
self.assertEqual(X.y.size, sizeof(c_char))
|
||||
|
||||
# readonly
|
||||
self.assertRaises((TypeError, AttributeError), setattr, X.x, "offset", 92)
|
||||
|
@ -164,22 +164,22 @@ class StructureTestCase(unittest.TestCase):
|
|||
("b", c_longlong)]
|
||||
_pack_ = 1
|
||||
|
||||
self.failUnlessEqual(sizeof(X), 9)
|
||||
self.failUnlessEqual(X.b.offset, 1)
|
||||
self.assertEqual(sizeof(X), 9)
|
||||
self.assertEqual(X.b.offset, 1)
|
||||
|
||||
class X(Structure):
|
||||
_fields_ = [("a", c_byte),
|
||||
("b", c_longlong)]
|
||||
_pack_ = 2
|
||||
self.failUnlessEqual(sizeof(X), 10)
|
||||
self.failUnlessEqual(X.b.offset, 2)
|
||||
self.assertEqual(sizeof(X), 10)
|
||||
self.assertEqual(X.b.offset, 2)
|
||||
|
||||
class X(Structure):
|
||||
_fields_ = [("a", c_byte),
|
||||
("b", c_longlong)]
|
||||
_pack_ = 4
|
||||
self.failUnlessEqual(sizeof(X), 12)
|
||||
self.failUnlessEqual(X.b.offset, 4)
|
||||
self.assertEqual(sizeof(X), 12)
|
||||
self.assertEqual(X.b.offset, 4)
|
||||
|
||||
import struct
|
||||
longlong_size = struct.calcsize("q")
|
||||
|
@ -190,8 +190,8 @@ class StructureTestCase(unittest.TestCase):
|
|||
("b", c_longlong)]
|
||||
_pack_ = 8
|
||||
|
||||
self.failUnlessEqual(sizeof(X), longlong_align + longlong_size)
|
||||
self.failUnlessEqual(X.b.offset, min(8, longlong_align))
|
||||
self.assertEqual(sizeof(X), longlong_align + longlong_size)
|
||||
self.assertEqual(X.b.offset, min(8, longlong_align))
|
||||
|
||||
|
||||
d = {"_fields_": [("a", "b"),
|
||||
|
@ -209,9 +209,9 @@ class StructureTestCase(unittest.TestCase):
|
|||
self.assertRaises(TypeError, Person, "Name", "HI")
|
||||
|
||||
# short enough
|
||||
self.failUnlessEqual(Person("12345", 5).name, "12345")
|
||||
self.assertEqual(Person("12345", 5).name, "12345")
|
||||
# exact fit
|
||||
self.failUnlessEqual(Person("123456", 5).name, "123456")
|
||||
self.assertEqual(Person("123456", 5).name, "123456")
|
||||
# too long
|
||||
self.assertRaises(ValueError, Person, "1234567", 5)
|
||||
|
||||
|
@ -229,10 +229,10 @@ class StructureTestCase(unittest.TestCase):
|
|||
class POINT(Structure):
|
||||
_fields_ = [("x", c_int), ("y", c_int)]
|
||||
pt = POINT(1, 2)
|
||||
self.failUnlessEqual((pt.x, pt.y), (1, 2))
|
||||
self.assertEqual((pt.x, pt.y), (1, 2))
|
||||
|
||||
pt = POINT(y=2, x=1)
|
||||
self.failUnlessEqual((pt.x, pt.y), (1, 2))
|
||||
self.assertEqual((pt.x, pt.y), (1, 2))
|
||||
|
||||
def test_invalid_field_types(self):
|
||||
class POINT(Structure):
|
||||
|
@ -244,14 +244,14 @@ class StructureTestCase(unittest.TestCase):
|
|||
_fields_ = [("a", c_int * 4)]
|
||||
|
||||
# can use tuple to initialize array (but not list!)
|
||||
self.failUnlessEqual(SomeInts((1, 2)).a[:], [1, 2, 0, 0])
|
||||
self.failUnlessEqual(SomeInts((1, 2)).a[::], [1, 2, 0, 0])
|
||||
self.failUnlessEqual(SomeInts((1, 2)).a[::-1], [0, 0, 2, 1])
|
||||
self.failUnlessEqual(SomeInts((1, 2)).a[::2], [1, 0])
|
||||
self.failUnlessEqual(SomeInts((1, 2)).a[1:5:6], [2])
|
||||
self.failUnlessEqual(SomeInts((1, 2)).a[6:4:-1], [])
|
||||
self.failUnlessEqual(SomeInts((1, 2, 3, 4)).a[:], [1, 2, 3, 4])
|
||||
self.failUnlessEqual(SomeInts((1, 2, 3, 4)).a[::], [1, 2, 3, 4])
|
||||
self.assertEqual(SomeInts((1, 2)).a[:], [1, 2, 0, 0])
|
||||
self.assertEqual(SomeInts((1, 2)).a[::], [1, 2, 0, 0])
|
||||
self.assertEqual(SomeInts((1, 2)).a[::-1], [0, 0, 2, 1])
|
||||
self.assertEqual(SomeInts((1, 2)).a[::2], [1, 0])
|
||||
self.assertEqual(SomeInts((1, 2)).a[1:5:6], [2])
|
||||
self.assertEqual(SomeInts((1, 2)).a[6:4:-1], [])
|
||||
self.assertEqual(SomeInts((1, 2, 3, 4)).a[:], [1, 2, 3, 4])
|
||||
self.assertEqual(SomeInts((1, 2, 3, 4)).a[::], [1, 2, 3, 4])
|
||||
# too long
|
||||
# XXX Should raise ValueError?, not RuntimeError
|
||||
self.assertRaises(RuntimeError, SomeInts, (1, 2, 3, 4, 5))
|
||||
|
@ -269,10 +269,10 @@ class StructureTestCase(unittest.TestCase):
|
|||
|
||||
p = Person("Someone", ("1234", "5678"), 5)
|
||||
|
||||
self.failUnlessEqual(p.name, "Someone")
|
||||
self.failUnlessEqual(p.phone.areacode, "1234")
|
||||
self.failUnlessEqual(p.phone.number, "5678")
|
||||
self.failUnlessEqual(p.age, 5)
|
||||
self.assertEqual(p.name, "Someone")
|
||||
self.assertEqual(p.phone.areacode, "1234")
|
||||
self.assertEqual(p.phone.number, "5678")
|
||||
self.assertEqual(p.age, 5)
|
||||
|
||||
def test_structures_with_wchar(self):
|
||||
try:
|
||||
|
@ -285,12 +285,12 @@ class StructureTestCase(unittest.TestCase):
|
|||
("age", c_int)]
|
||||
|
||||
p = PersonW(u"Someone")
|
||||
self.failUnlessEqual(p.name, "Someone")
|
||||
self.assertEqual(p.name, "Someone")
|
||||
|
||||
self.failUnlessEqual(PersonW(u"1234567890").name, u"1234567890")
|
||||
self.failUnlessEqual(PersonW(u"12345678901").name, u"12345678901")
|
||||
self.assertEqual(PersonW(u"1234567890").name, u"1234567890")
|
||||
self.assertEqual(PersonW(u"12345678901").name, u"12345678901")
|
||||
# exact fit
|
||||
self.failUnlessEqual(PersonW(u"123456789012").name, u"123456789012")
|
||||
self.assertEqual(PersonW(u"123456789012").name, u"123456789012")
|
||||
#too long
|
||||
self.assertRaises(ValueError, PersonW, u"1234567890123")
|
||||
|
||||
|
@ -305,24 +305,24 @@ class StructureTestCase(unittest.TestCase):
|
|||
("age", c_int)]
|
||||
|
||||
cls, msg = self.get_except(Person, "Someone", (1, 2))
|
||||
self.failUnlessEqual(cls, RuntimeError)
|
||||
self.assertEqual(cls, RuntimeError)
|
||||
# In Python 2.5, Exception is a new-style class, and the repr changed
|
||||
if issubclass(Exception, object):
|
||||
self.failUnlessEqual(msg,
|
||||
self.assertEqual(msg,
|
||||
"(Phone) <type 'exceptions.TypeError'>: "
|
||||
"expected string or Unicode object, int found")
|
||||
else:
|
||||
self.failUnlessEqual(msg,
|
||||
self.assertEqual(msg,
|
||||
"(Phone) exceptions.TypeError: "
|
||||
"expected string or Unicode object, int found")
|
||||
|
||||
cls, msg = self.get_except(Person, "Someone", ("a", "b", "c"))
|
||||
self.failUnlessEqual(cls, RuntimeError)
|
||||
self.assertEqual(cls, RuntimeError)
|
||||
if issubclass(Exception, object):
|
||||
self.failUnlessEqual(msg,
|
||||
self.assertEqual(msg,
|
||||
"(Phone) <type 'exceptions.TypeError'>: too many initializers")
|
||||
else:
|
||||
self.failUnlessEqual(msg, "(Phone) exceptions.TypeError: too many initializers")
|
||||
self.assertEqual(msg, "(Phone) exceptions.TypeError: too many initializers")
|
||||
|
||||
|
||||
def get_except(self, func, *args):
|
||||
|
@ -337,7 +337,7 @@ class StructureTestCase(unittest.TestCase):
|
|||
## # same as 'class X(Structure): pass'
|
||||
## # fails, since we need either a _fields_ or a _abstract_ attribute
|
||||
## cls, msg = self.get_except(meta, "X", (Structure,), {})
|
||||
## self.failUnlessEqual((cls, msg),
|
||||
## self.assertEqual((cls, msg),
|
||||
## (AttributeError, "class must define a '_fields_' attribute"))
|
||||
|
||||
def test_abstract_class(self):
|
||||
|
@ -345,15 +345,15 @@ class StructureTestCase(unittest.TestCase):
|
|||
_abstract_ = "something"
|
||||
# try 'X()'
|
||||
cls, msg = self.get_except(eval, "X()", locals())
|
||||
self.failUnlessEqual((cls, msg), (TypeError, "abstract class"))
|
||||
self.assertEqual((cls, msg), (TypeError, "abstract class"))
|
||||
|
||||
def test_methods(self):
|
||||
## class X(Structure):
|
||||
## _fields_ = []
|
||||
|
||||
self.failUnless("in_dll" in dir(type(Structure)))
|
||||
self.failUnless("from_address" in dir(type(Structure)))
|
||||
self.failUnless("in_dll" in dir(type(Structure)))
|
||||
self.assertTrue("in_dll" in dir(type(Structure)))
|
||||
self.assertTrue("from_address" in dir(type(Structure)))
|
||||
self.assertTrue("in_dll" in dir(type(Structure)))
|
||||
|
||||
class PointerMemberTestCase(unittest.TestCase):
|
||||
|
||||
|
@ -366,7 +366,7 @@ class PointerMemberTestCase(unittest.TestCase):
|
|||
# We can assign arrays of the correct type
|
||||
s.array = (c_int * 3)(1, 2, 3)
|
||||
items = [s.array[i] for i in range(3)]
|
||||
self.failUnlessEqual(items, [1, 2, 3])
|
||||
self.assertEqual(items, [1, 2, 3])
|
||||
|
||||
# The following are bugs, but are included here because the unittests
|
||||
# also describe the current behaviour.
|
||||
|
@ -377,14 +377,14 @@ class PointerMemberTestCase(unittest.TestCase):
|
|||
s.array[0] = 42
|
||||
|
||||
items = [s.array[i] for i in range(3)]
|
||||
self.failUnlessEqual(items, [42, 2, 3])
|
||||
self.assertEqual(items, [42, 2, 3])
|
||||
|
||||
s.array[0] = 1
|
||||
|
||||
## s.array[1] = 42
|
||||
|
||||
items = [s.array[i] for i in range(3)]
|
||||
self.failUnlessEqual(items, [1, 2, 3])
|
||||
self.assertEqual(items, [1, 2, 3])
|
||||
|
||||
def test_none_to_pointer_fields(self):
|
||||
class S(Structure):
|
||||
|
@ -394,7 +394,7 @@ class PointerMemberTestCase(unittest.TestCase):
|
|||
s = S()
|
||||
s.x = 12345678
|
||||
s.p = None
|
||||
self.failUnlessEqual(s.x, 12345678)
|
||||
self.assertEqual(s.x, 12345678)
|
||||
|
||||
class TestRecursiveStructure(unittest.TestCase):
|
||||
def test_contains_itself(self):
|
||||
|
@ -404,7 +404,7 @@ class TestRecursiveStructure(unittest.TestCase):
|
|||
try:
|
||||
Recursive._fields_ = [("next", Recursive)]
|
||||
except AttributeError, details:
|
||||
self.failUnless("Structure or union cannot contain itself" in
|
||||
self.assertTrue("Structure or union cannot contain itself" in
|
||||
str(details))
|
||||
else:
|
||||
self.fail("Structure or union cannot contain itself")
|
||||
|
@ -421,7 +421,7 @@ class TestRecursiveStructure(unittest.TestCase):
|
|||
try:
|
||||
Second._fields_ = [("first", First)]
|
||||
except AttributeError, details:
|
||||
self.failUnless("_fields_ is final" in
|
||||
self.assertTrue("_fields_ is final" in
|
||||
str(details))
|
||||
else:
|
||||
self.fail("AttributeError not raised")
|
||||
|
|
|
@ -28,18 +28,18 @@ class TestStructures(unittest.TestCase):
|
|||
def test_native(self):
|
||||
for typ in structures:
|
||||
## print typ.value
|
||||
self.failUnlessEqual(typ.value.offset, 1)
|
||||
self.assertEqual(typ.value.offset, 1)
|
||||
o = typ()
|
||||
o.value = 4
|
||||
self.failUnlessEqual(o.value, 4)
|
||||
self.assertEqual(o.value, 4)
|
||||
|
||||
def test_swapped(self):
|
||||
for typ in byteswapped_structures:
|
||||
## print >> sys.stderr, typ.value
|
||||
self.failUnlessEqual(typ.value.offset, 1)
|
||||
self.assertEqual(typ.value.offset, 1)
|
||||
o = typ()
|
||||
o.value = 4
|
||||
self.failUnlessEqual(o.value, 4)
|
||||
self.assertEqual(o.value, 4)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -23,55 +23,55 @@ else:
|
|||
def test_ascii_strict(self):
|
||||
ctypes.set_conversion_mode("ascii", "strict")
|
||||
# no conversions take place with unicode arguments
|
||||
self.failUnlessEqual(wcslen(u"abc"), 3)
|
||||
self.failUnlessEqual(wcslen(u"ab\u2070"), 3)
|
||||
self.assertEqual(wcslen(u"abc"), 3)
|
||||
self.assertEqual(wcslen(u"ab\u2070"), 3)
|
||||
# string args are converted
|
||||
self.failUnlessEqual(wcslen("abc"), 3)
|
||||
self.failUnlessRaises(ctypes.ArgumentError, wcslen, "abä")
|
||||
self.assertEqual(wcslen("abc"), 3)
|
||||
self.assertRaises(ctypes.ArgumentError, wcslen, "abä")
|
||||
|
||||
def test_ascii_replace(self):
|
||||
ctypes.set_conversion_mode("ascii", "replace")
|
||||
self.failUnlessEqual(wcslen(u"abc"), 3)
|
||||
self.failUnlessEqual(wcslen(u"ab\u2070"), 3)
|
||||
self.failUnlessEqual(wcslen("abc"), 3)
|
||||
self.failUnlessEqual(wcslen("abä"), 3)
|
||||
self.assertEqual(wcslen(u"abc"), 3)
|
||||
self.assertEqual(wcslen(u"ab\u2070"), 3)
|
||||
self.assertEqual(wcslen("abc"), 3)
|
||||
self.assertEqual(wcslen("abä"), 3)
|
||||
|
||||
def test_ascii_ignore(self):
|
||||
ctypes.set_conversion_mode("ascii", "ignore")
|
||||
self.failUnlessEqual(wcslen(u"abc"), 3)
|
||||
self.failUnlessEqual(wcslen(u"ab\u2070"), 3)
|
||||
self.assertEqual(wcslen(u"abc"), 3)
|
||||
self.assertEqual(wcslen(u"ab\u2070"), 3)
|
||||
# ignore error mode skips non-ascii characters
|
||||
self.failUnlessEqual(wcslen("abc"), 3)
|
||||
self.failUnlessEqual(wcslen("äöüß"), 0)
|
||||
self.assertEqual(wcslen("abc"), 3)
|
||||
self.assertEqual(wcslen("äöüß"), 0)
|
||||
|
||||
def test_latin1_strict(self):
|
||||
ctypes.set_conversion_mode("latin-1", "strict")
|
||||
self.failUnlessEqual(wcslen(u"abc"), 3)
|
||||
self.failUnlessEqual(wcslen(u"ab\u2070"), 3)
|
||||
self.failUnlessEqual(wcslen("abc"), 3)
|
||||
self.failUnlessEqual(wcslen("äöüß"), 4)
|
||||
self.assertEqual(wcslen(u"abc"), 3)
|
||||
self.assertEqual(wcslen(u"ab\u2070"), 3)
|
||||
self.assertEqual(wcslen("abc"), 3)
|
||||
self.assertEqual(wcslen("äöüß"), 4)
|
||||
|
||||
def test_buffers(self):
|
||||
ctypes.set_conversion_mode("ascii", "strict")
|
||||
buf = ctypes.create_unicode_buffer("abc")
|
||||
self.failUnlessEqual(len(buf), 3+1)
|
||||
self.assertEqual(len(buf), 3+1)
|
||||
|
||||
ctypes.set_conversion_mode("ascii", "replace")
|
||||
buf = ctypes.create_unicode_buffer("abäöü")
|
||||
self.failUnlessEqual(buf[:], u"ab\uFFFD\uFFFD\uFFFD\0")
|
||||
self.failUnlessEqual(buf[::], u"ab\uFFFD\uFFFD\uFFFD\0")
|
||||
self.failUnlessEqual(buf[::-1], u"\0\uFFFD\uFFFD\uFFFDba")
|
||||
self.failUnlessEqual(buf[::2], u"a\uFFFD\uFFFD")
|
||||
self.failUnlessEqual(buf[6:5:-1], u"")
|
||||
self.assertEqual(buf[:], u"ab\uFFFD\uFFFD\uFFFD\0")
|
||||
self.assertEqual(buf[::], u"ab\uFFFD\uFFFD\uFFFD\0")
|
||||
self.assertEqual(buf[::-1], u"\0\uFFFD\uFFFD\uFFFDba")
|
||||
self.assertEqual(buf[::2], u"a\uFFFD\uFFFD")
|
||||
self.assertEqual(buf[6:5:-1], u"")
|
||||
|
||||
ctypes.set_conversion_mode("ascii", "ignore")
|
||||
buf = ctypes.create_unicode_buffer("abäöü")
|
||||
# is that correct? not sure. But with 'ignore', you get what you pay for..
|
||||
self.failUnlessEqual(buf[:], u"ab\0\0\0\0")
|
||||
self.failUnlessEqual(buf[::], u"ab\0\0\0\0")
|
||||
self.failUnlessEqual(buf[::-1], u"\0\0\0\0ba")
|
||||
self.failUnlessEqual(buf[::2], u"a\0\0")
|
||||
self.failUnlessEqual(buf[6:5:-1], u"")
|
||||
self.assertEqual(buf[:], u"ab\0\0\0\0")
|
||||
self.assertEqual(buf[::], u"ab\0\0\0\0")
|
||||
self.assertEqual(buf[::-1], u"\0\0\0\0ba")
|
||||
self.assertEqual(buf[::2], u"a\0\0")
|
||||
self.assertEqual(buf[6:5:-1], u"")
|
||||
|
||||
import _ctypes_test
|
||||
func = ctypes.CDLL(_ctypes_test.__file__)._testfunc_p_p
|
||||
|
@ -89,41 +89,41 @@ else:
|
|||
|
||||
def test_ascii_replace(self):
|
||||
ctypes.set_conversion_mode("ascii", "strict")
|
||||
self.failUnlessEqual(func("abc"), "abc")
|
||||
self.failUnlessEqual(func(u"abc"), "abc")
|
||||
self.assertEqual(func("abc"), "abc")
|
||||
self.assertEqual(func(u"abc"), "abc")
|
||||
self.assertRaises(ctypes.ArgumentError, func, u"abä")
|
||||
|
||||
def test_ascii_ignore(self):
|
||||
ctypes.set_conversion_mode("ascii", "ignore")
|
||||
self.failUnlessEqual(func("abc"), "abc")
|
||||
self.failUnlessEqual(func(u"abc"), "abc")
|
||||
self.failUnlessEqual(func(u"äöüß"), "")
|
||||
self.assertEqual(func("abc"), "abc")
|
||||
self.assertEqual(func(u"abc"), "abc")
|
||||
self.assertEqual(func(u"äöüß"), "")
|
||||
|
||||
def test_ascii_replace(self):
|
||||
ctypes.set_conversion_mode("ascii", "replace")
|
||||
self.failUnlessEqual(func("abc"), "abc")
|
||||
self.failUnlessEqual(func(u"abc"), "abc")
|
||||
self.failUnlessEqual(func(u"äöüß"), "????")
|
||||
self.assertEqual(func("abc"), "abc")
|
||||
self.assertEqual(func(u"abc"), "abc")
|
||||
self.assertEqual(func(u"äöüß"), "????")
|
||||
|
||||
def test_buffers(self):
|
||||
ctypes.set_conversion_mode("ascii", "strict")
|
||||
buf = ctypes.create_string_buffer(u"abc")
|
||||
self.failUnlessEqual(len(buf), 3+1)
|
||||
self.assertEqual(len(buf), 3+1)
|
||||
|
||||
ctypes.set_conversion_mode("ascii", "replace")
|
||||
buf = ctypes.create_string_buffer(u"abäöü")
|
||||
self.failUnlessEqual(buf[:], "ab???\0")
|
||||
self.failUnlessEqual(buf[::], "ab???\0")
|
||||
self.failUnlessEqual(buf[::-1], "\0???ba")
|
||||
self.failUnlessEqual(buf[::2], "a??")
|
||||
self.failUnlessEqual(buf[6:5:-1], "")
|
||||
self.assertEqual(buf[:], "ab???\0")
|
||||
self.assertEqual(buf[::], "ab???\0")
|
||||
self.assertEqual(buf[::-1], "\0???ba")
|
||||
self.assertEqual(buf[::2], "a??")
|
||||
self.assertEqual(buf[6:5:-1], "")
|
||||
|
||||
ctypes.set_conversion_mode("ascii", "ignore")
|
||||
buf = ctypes.create_string_buffer(u"abäöü")
|
||||
# is that correct? not sure. But with 'ignore', you get what you pay for..
|
||||
self.failUnlessEqual(buf[:], "ab\0\0\0\0")
|
||||
self.failUnlessEqual(buf[::], "ab\0\0\0\0")
|
||||
self.failUnlessEqual(buf[::-1], "\0\0\0\0ba")
|
||||
self.assertEqual(buf[:], "ab\0\0\0\0")
|
||||
self.assertEqual(buf[::], "ab\0\0\0\0")
|
||||
self.assertEqual(buf[::-1], "\0\0\0\0ba")
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -13,9 +13,9 @@ class ValuesTestCase(unittest.TestCase):
|
|||
ctdll = CDLL(_ctypes_test.__file__)
|
||||
an_integer = c_int.in_dll(ctdll, "an_integer")
|
||||
x = an_integer.value
|
||||
self.failUnlessEqual(x, ctdll.get_an_integer())
|
||||
self.assertEqual(x, ctdll.get_an_integer())
|
||||
an_integer.value *= 2
|
||||
self.failUnlessEqual(x*2, ctdll.get_an_integer())
|
||||
self.assertEqual(x*2, ctdll.get_an_integer())
|
||||
|
||||
def test_undefined(self):
|
||||
ctdll = CDLL(_ctypes_test.__file__)
|
||||
|
@ -34,11 +34,11 @@ class ValuesTestCase(unittest.TestCase):
|
|||
# docstrings are also removed in the latter case.
|
||||
opt = c_int.in_dll(pydll, "Py_OptimizeFlag").value
|
||||
if __debug__:
|
||||
self.failUnlessEqual(opt, 0)
|
||||
self.assertEqual(opt, 0)
|
||||
elif ValuesTestCase.__doc__ is not None:
|
||||
self.failUnlessEqual(opt, 1)
|
||||
self.assertEqual(opt, 1)
|
||||
else:
|
||||
self.failUnlessEqual(opt, 2)
|
||||
self.assertEqual(opt, 2)
|
||||
|
||||
def test_frozentable(self):
|
||||
# Python exports a PyImport_FrozenModules symbol. This is a
|
||||
|
@ -70,7 +70,7 @@ class ValuesTestCase(unittest.TestCase):
|
|||
expected = [("__hello__", 104), ("__phello__", -104), ("__phello__.spam", 104)]
|
||||
else:
|
||||
expected = [("__hello__", 100), ("__phello__", -100), ("__phello__.spam", 100)]
|
||||
self.failUnlessEqual(items, expected)
|
||||
self.assertEqual(items, expected)
|
||||
|
||||
from ctypes import _pointer_type_cache
|
||||
del _pointer_type_cache[struct_frozen]
|
||||
|
|
|
@ -7,44 +7,44 @@ class VarSizeTest(unittest.TestCase):
|
|||
_fields_ = [("item", c_int),
|
||||
("array", c_int * 1)]
|
||||
|
||||
self.failUnlessEqual(sizeof(X), sizeof(c_int) * 2)
|
||||
self.assertEqual(sizeof(X), sizeof(c_int) * 2)
|
||||
x = X()
|
||||
x.item = 42
|
||||
x.array[0] = 100
|
||||
self.failUnlessEqual(sizeof(x), sizeof(c_int) * 2)
|
||||
self.assertEqual(sizeof(x), sizeof(c_int) * 2)
|
||||
|
||||
# make room for one additional item
|
||||
new_size = sizeof(X) + sizeof(c_int) * 1
|
||||
resize(x, new_size)
|
||||
self.failUnlessEqual(sizeof(x), new_size)
|
||||
self.failUnlessEqual((x.item, x.array[0]), (42, 100))
|
||||
self.assertEqual(sizeof(x), new_size)
|
||||
self.assertEqual((x.item, x.array[0]), (42, 100))
|
||||
|
||||
# make room for 10 additional items
|
||||
new_size = sizeof(X) + sizeof(c_int) * 9
|
||||
resize(x, new_size)
|
||||
self.failUnlessEqual(sizeof(x), new_size)
|
||||
self.failUnlessEqual((x.item, x.array[0]), (42, 100))
|
||||
self.assertEqual(sizeof(x), new_size)
|
||||
self.assertEqual((x.item, x.array[0]), (42, 100))
|
||||
|
||||
# make room for one additional item
|
||||
new_size = sizeof(X) + sizeof(c_int) * 1
|
||||
resize(x, new_size)
|
||||
self.failUnlessEqual(sizeof(x), new_size)
|
||||
self.failUnlessEqual((x.item, x.array[0]), (42, 100))
|
||||
self.assertEqual(sizeof(x), new_size)
|
||||
self.assertEqual((x.item, x.array[0]), (42, 100))
|
||||
|
||||
def test_array_invalid_length(self):
|
||||
# cannot create arrays with non-positive size
|
||||
self.failUnlessRaises(ValueError, lambda: c_int * -1)
|
||||
self.failUnlessRaises(ValueError, lambda: c_int * -3)
|
||||
self.assertRaises(ValueError, lambda: c_int * -1)
|
||||
self.assertRaises(ValueError, lambda: c_int * -3)
|
||||
|
||||
def test_zerosized_array(self):
|
||||
array = (c_int * 0)()
|
||||
# accessing elements of zero-sized arrays raise IndexError
|
||||
self.failUnlessRaises(IndexError, array.__setitem__, 0, None)
|
||||
self.failUnlessRaises(IndexError, array.__getitem__, 0)
|
||||
self.failUnlessRaises(IndexError, array.__setitem__, 1, None)
|
||||
self.failUnlessRaises(IndexError, array.__getitem__, 1)
|
||||
self.failUnlessRaises(IndexError, array.__setitem__, -1, None)
|
||||
self.failUnlessRaises(IndexError, array.__getitem__, -1)
|
||||
self.assertRaises(IndexError, array.__setitem__, 0, None)
|
||||
self.assertRaises(IndexError, array.__getitem__, 0)
|
||||
self.assertRaises(IndexError, array.__setitem__, 1, None)
|
||||
self.assertRaises(IndexError, array.__getitem__, 1)
|
||||
self.assertRaises(IndexError, array.__setitem__, -1, None)
|
||||
self.assertRaises(IndexError, array.__getitem__, -1)
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
|
@ -18,7 +18,7 @@ if sys.platform == "win32" and sizeof(c_void_p) == sizeof(c_int):
|
|||
self.assertRaises(ValueError, IsWindow)
|
||||
|
||||
# This one should succeeed...
|
||||
self.failUnlessEqual(0, IsWindow(0))
|
||||
self.assertEqual(0, IsWindow(0))
|
||||
|
||||
# ValueError: Procedure probably called with too many arguments (8 bytes in excess)
|
||||
self.assertRaises(ValueError, IsWindow, 0, 0, 0)
|
||||
|
@ -49,13 +49,13 @@ if sys.platform == "win32":
|
|||
class TestWintypes(unittest.TestCase):
|
||||
def test_HWND(self):
|
||||
from ctypes import wintypes
|
||||
self.failUnlessEqual(sizeof(wintypes.HWND), sizeof(c_void_p))
|
||||
self.assertEqual(sizeof(wintypes.HWND), sizeof(c_void_p))
|
||||
|
||||
def test_PARAM(self):
|
||||
from ctypes import wintypes
|
||||
self.failUnlessEqual(sizeof(wintypes.WPARAM),
|
||||
self.assertEqual(sizeof(wintypes.WPARAM),
|
||||
sizeof(c_void_p))
|
||||
self.failUnlessEqual(sizeof(wintypes.LPARAM),
|
||||
self.assertEqual(sizeof(wintypes.LPARAM),
|
||||
sizeof(c_void_p))
|
||||
|
||||
def test_COMError(self):
|
||||
|
@ -84,7 +84,7 @@ class Structures(unittest.TestCase):
|
|||
|
||||
pt = POINT(10, 10)
|
||||
rect = RECT(0, 0, 20, 20)
|
||||
self.failUnlessEqual(1, dll.PointInRect(byref(rect), pt))
|
||||
self.assertEqual(1, dll.PointInRect(byref(rect), pt))
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -47,7 +47,7 @@ class ArchiveUtilTestCase(support.TempdirManager,
|
|||
|
||||
# check if the compressed tarball was created
|
||||
tarball = base_name + '.tar.gz'
|
||||
self.assert_(os.path.exists(tarball))
|
||||
self.assertTrue(os.path.exists(tarball))
|
||||
|
||||
# trying an uncompressed one
|
||||
base_name = os.path.join(tmpdir2, 'archive')
|
||||
|
@ -58,7 +58,7 @@ class ArchiveUtilTestCase(support.TempdirManager,
|
|||
finally:
|
||||
os.chdir(old_dir)
|
||||
tarball = base_name + '.tar'
|
||||
self.assert_(os.path.exists(tarball))
|
||||
self.assertTrue(os.path.exists(tarball))
|
||||
|
||||
def _tarinfo(self, path):
|
||||
tar = tarfile.open(path)
|
||||
|
@ -96,7 +96,7 @@ class ArchiveUtilTestCase(support.TempdirManager,
|
|||
|
||||
# check if the compressed tarball was created
|
||||
tarball = base_name + '.tar.gz'
|
||||
self.assert_(os.path.exists(tarball))
|
||||
self.assertTrue(os.path.exists(tarball))
|
||||
|
||||
# now create another tarball using `tar`
|
||||
tarball2 = os.path.join(tmpdir, 'archive2.tar.gz')
|
||||
|
@ -110,7 +110,7 @@ class ArchiveUtilTestCase(support.TempdirManager,
|
|||
finally:
|
||||
os.chdir(old_dir)
|
||||
|
||||
self.assert_(os.path.exists(tarball2))
|
||||
self.assertTrue(os.path.exists(tarball2))
|
||||
# let's compare both tarballs
|
||||
self.assertEquals(self._tarinfo(tarball), self._tarinfo(tarball2))
|
||||
|
||||
|
@ -123,7 +123,7 @@ class ArchiveUtilTestCase(support.TempdirManager,
|
|||
finally:
|
||||
os.chdir(old_dir)
|
||||
tarball = base_name + '.tar'
|
||||
self.assert_(os.path.exists(tarball))
|
||||
self.assertTrue(os.path.exists(tarball))
|
||||
|
||||
# now for a dry_run
|
||||
base_name = os.path.join(tmpdir2, 'archive')
|
||||
|
@ -134,7 +134,7 @@ class ArchiveUtilTestCase(support.TempdirManager,
|
|||
finally:
|
||||
os.chdir(old_dir)
|
||||
tarball = base_name + '.tar'
|
||||
self.assert_(os.path.exists(tarball))
|
||||
self.assertTrue(os.path.exists(tarball))
|
||||
|
||||
@unittest.skipUnless(find_executable('compress'),
|
||||
'The compress program is required')
|
||||
|
@ -151,7 +151,7 @@ class ArchiveUtilTestCase(support.TempdirManager,
|
|||
finally:
|
||||
os.chdir(old_dir)
|
||||
tarball = base_name + '.tar.Z'
|
||||
self.assert_(os.path.exists(tarball))
|
||||
self.assertTrue(os.path.exists(tarball))
|
||||
self.assertEquals(len(w.warnings), 1)
|
||||
|
||||
# same test with dry_run
|
||||
|
@ -165,7 +165,7 @@ class ArchiveUtilTestCase(support.TempdirManager,
|
|||
dry_run=True)
|
||||
finally:
|
||||
os.chdir(old_dir)
|
||||
self.assert_(not os.path.exists(tarball))
|
||||
self.assertTrue(not os.path.exists(tarball))
|
||||
self.assertEquals(len(w.warnings), 1)
|
||||
|
||||
@unittest.skipUnless(ZIP_SUPPORT, 'Need zip support to run')
|
||||
|
|
|
@ -74,7 +74,7 @@ class BuildRpmTestCase(support.TempdirManager,
|
|||
cmd.run()
|
||||
|
||||
dist_created = os.listdir(os.path.join(pkg_dir, 'dist'))
|
||||
self.assert_('foo-0.1-1.noarch.rpm' in dist_created)
|
||||
self.assertTrue('foo-0.1-1.noarch.rpm' in dist_created)
|
||||
|
||||
def test_no_optimize_flag(self):
|
||||
|
||||
|
@ -114,7 +114,7 @@ class BuildRpmTestCase(support.TempdirManager,
|
|||
cmd.run()
|
||||
|
||||
dist_created = os.listdir(os.path.join(pkg_dir, 'dist'))
|
||||
self.assert_('foo-0.1-1.noarch.rpm' in dist_created)
|
||||
self.assertTrue('foo-0.1-1.noarch.rpm' in dist_created)
|
||||
os.remove(os.path.join(pkg_dir, 'dist', 'foo-0.1-1.noarch.rpm'))
|
||||
|
||||
def test_suite():
|
||||
|
|
|
@ -21,7 +21,7 @@ class BuildWinInstTestCase(support.TempdirManager,
|
|||
# and make sure it finds it and returns its content
|
||||
# no matter what platform we have
|
||||
exe_file = cmd.get_exe_bytes()
|
||||
self.assert_(len(exe_file) > 10)
|
||||
self.assertTrue(len(exe_file) > 10)
|
||||
|
||||
def test_suite():
|
||||
return unittest.makeSuite(BuildWinInstTestCase)
|
||||
|
|
|
@ -135,7 +135,7 @@ class BuildCLibTestCase(support.TempdirManager,
|
|||
cmd.run()
|
||||
|
||||
# let's check the result
|
||||
self.assert_('libfoo.a' in os.listdir(build_temp))
|
||||
self.assertTrue('libfoo.a' in os.listdir(build_temp))
|
||||
|
||||
def test_suite():
|
||||
return unittest.makeSuite(BuildCLibTestCase)
|
||||
|
|
|
@ -73,15 +73,15 @@ class BuildExtTestCase(support.TempdirManager,
|
|||
import xx
|
||||
|
||||
for attr in ('error', 'foo', 'new', 'roj'):
|
||||
self.assert_(hasattr(xx, attr))
|
||||
self.assertTrue(hasattr(xx, attr))
|
||||
|
||||
self.assertEquals(xx.foo(2, 5), 7)
|
||||
self.assertEquals(xx.foo(13,15), 28)
|
||||
self.assertEquals(xx.new().demo(), None)
|
||||
doc = 'This is a template module just for instruction.'
|
||||
self.assertEquals(xx.__doc__, doc)
|
||||
self.assert_(isinstance(xx.Null(), xx.Null))
|
||||
self.assert_(isinstance(xx.Str(), xx.Str))
|
||||
self.assertTrue(isinstance(xx.Null(), xx.Null))
|
||||
self.assertTrue(isinstance(xx.Str(), xx.Str))
|
||||
|
||||
def tearDown(self):
|
||||
# Get everything back to normal
|
||||
|
@ -114,7 +114,7 @@ class BuildExtTestCase(support.TempdirManager,
|
|||
_config_vars['Py_ENABLE_SHARED'] = old_var
|
||||
|
||||
# make sure we get some library dirs under solaris
|
||||
self.assert_(len(cmd.library_dirs) > 0)
|
||||
self.assertTrue(len(cmd.library_dirs) > 0)
|
||||
|
||||
def test_user_site(self):
|
||||
# site.USER_SITE was introduced in 2.6
|
||||
|
@ -128,7 +128,7 @@ class BuildExtTestCase(support.TempdirManager,
|
|||
# making sure the user option is there
|
||||
options = [name for name, short, lable in
|
||||
cmd.user_options]
|
||||
self.assert_('user' in options)
|
||||
self.assertTrue('user' in options)
|
||||
|
||||
# setting a value
|
||||
cmd.user = 1
|
||||
|
@ -144,9 +144,9 @@ class BuildExtTestCase(support.TempdirManager,
|
|||
|
||||
# see if include_dirs and library_dirs
|
||||
# were set
|
||||
self.assert_(lib in cmd.library_dirs)
|
||||
self.assert_(lib in cmd.rpath)
|
||||
self.assert_(incl in cmd.include_dirs)
|
||||
self.assertTrue(lib in cmd.library_dirs)
|
||||
self.assertTrue(lib in cmd.rpath)
|
||||
self.assertTrue(incl in cmd.include_dirs)
|
||||
|
||||
def test_optional_extension(self):
|
||||
|
||||
|
@ -175,10 +175,10 @@ class BuildExtTestCase(support.TempdirManager,
|
|||
|
||||
from distutils import sysconfig
|
||||
py_include = sysconfig.get_python_inc()
|
||||
self.assert_(py_include in cmd.include_dirs)
|
||||
self.assertTrue(py_include in cmd.include_dirs)
|
||||
|
||||
plat_py_include = sysconfig.get_python_inc(plat_specific=1)
|
||||
self.assert_(plat_py_include in cmd.include_dirs)
|
||||
self.assertTrue(plat_py_include in cmd.include_dirs)
|
||||
|
||||
# make sure cmd.libraries is turned into a list
|
||||
# if it's a string
|
||||
|
@ -192,7 +192,7 @@ class BuildExtTestCase(support.TempdirManager,
|
|||
cmd = build_ext(dist)
|
||||
cmd.library_dirs = 'my_lib_dir'
|
||||
cmd.finalize_options()
|
||||
self.assert_('my_lib_dir' in cmd.library_dirs)
|
||||
self.assertTrue('my_lib_dir' in cmd.library_dirs)
|
||||
|
||||
# make sure rpath is turned into a list
|
||||
# if it's a list of os.pathsep's paths
|
||||
|
@ -257,13 +257,13 @@ class BuildExtTestCase(support.TempdirManager,
|
|||
'some': 'bar'})]
|
||||
cmd.check_extensions_list(exts)
|
||||
ext = exts[0]
|
||||
self.assert_(isinstance(ext, Extension))
|
||||
self.assertTrue(isinstance(ext, Extension))
|
||||
|
||||
# check_extensions_list adds in ext the values passed
|
||||
# when they are in ('include_dirs', 'library_dirs', 'libraries'
|
||||
# 'extra_objects', 'extra_compile_args', 'extra_link_args')
|
||||
self.assertEquals(ext.libraries, 'foo')
|
||||
self.assert_(not hasattr(ext, 'some'))
|
||||
self.assertTrue(not hasattr(ext, 'some'))
|
||||
|
||||
# 'macros' element of build info dict must be 1- or 2-tuple
|
||||
exts = [('foo.bar', {'sources': [''], 'libraries': 'foo',
|
||||
|
@ -321,7 +321,7 @@ class BuildExtTestCase(support.TempdirManager,
|
|||
so_file = cmd.get_outputs()[0]
|
||||
finally:
|
||||
os.chdir(old_wd)
|
||||
self.assert_(os.path.exists(so_file))
|
||||
self.assertTrue(os.path.exists(so_file))
|
||||
self.assertEquals(os.path.splitext(so_file)[-1],
|
||||
sysconfig.get_config_var('SO'))
|
||||
so_dir = os.path.dirname(so_file)
|
||||
|
@ -330,7 +330,7 @@ class BuildExtTestCase(support.TempdirManager,
|
|||
cmd.inplace = 0
|
||||
cmd.run()
|
||||
so_file = cmd.get_outputs()[0]
|
||||
self.assert_(os.path.exists(so_file))
|
||||
self.assertTrue(os.path.exists(so_file))
|
||||
self.assertEquals(os.path.splitext(so_file)[-1],
|
||||
sysconfig.get_config_var('SO'))
|
||||
so_dir = os.path.dirname(so_file)
|
||||
|
|
|
@ -52,9 +52,9 @@ class BuildPyTestCase(support.TempdirManager,
|
|||
self.assertEqual(len(cmd.get_outputs()), 3)
|
||||
pkgdest = os.path.join(destination, "pkg")
|
||||
files = os.listdir(pkgdest)
|
||||
self.assert_("__init__.py" in files)
|
||||
self.assert_("__init__.pyc" in files)
|
||||
self.assert_("README.txt" in files)
|
||||
self.assertTrue("__init__.py" in files)
|
||||
self.assertTrue("__init__.pyc" in files)
|
||||
self.assertTrue("README.txt" in files)
|
||||
|
||||
def test_empty_package_dir (self):
|
||||
# See SF 1668596/1720897.
|
||||
|
|
|
@ -16,12 +16,12 @@ class BuildScriptsTestCase(support.TempdirManager,
|
|||
|
||||
def test_default_settings(self):
|
||||
cmd = self.get_build_scripts_cmd("/foo/bar", [])
|
||||
self.assert_(not cmd.force)
|
||||
self.assert_(cmd.build_dir is None)
|
||||
self.assertTrue(not cmd.force)
|
||||
self.assertTrue(cmd.build_dir is None)
|
||||
|
||||
cmd.finalize_options()
|
||||
|
||||
self.assert_(cmd.force)
|
||||
self.assertTrue(cmd.force)
|
||||
self.assertEqual(cmd.build_dir, "/foo/bar")
|
||||
|
||||
def test_build(self):
|
||||
|
@ -37,7 +37,7 @@ class BuildScriptsTestCase(support.TempdirManager,
|
|||
|
||||
built = os.listdir(target)
|
||||
for name in expected:
|
||||
self.assert_(name in built)
|
||||
self.assertTrue(name in built)
|
||||
|
||||
def get_build_scripts_cmd(self, target, scripts):
|
||||
import sys
|
||||
|
@ -100,7 +100,7 @@ class BuildScriptsTestCase(support.TempdirManager,
|
|||
|
||||
built = os.listdir(target)
|
||||
for name in expected:
|
||||
self.assert_(name in built)
|
||||
self.assertTrue(name in built)
|
||||
|
||||
def test_suite():
|
||||
return unittest.makeSuite(BuildScriptsTestCase)
|
||||
|
|
|
@ -35,7 +35,7 @@ class cleanTestCase(support.TempdirManager,
|
|||
|
||||
# make sure the files where removed
|
||||
for name, path in dirs:
|
||||
self.assert_(not os.path.exists(path),
|
||||
self.assertTrue(not os.path.exists(path),
|
||||
'%s was not removed' % path)
|
||||
|
||||
# let's run the command again (should spit warnings but suceed)
|
||||
|
|
|
@ -70,7 +70,7 @@ class CommandTestCase(unittest.TestCase):
|
|||
|
||||
cmd.option2 = None
|
||||
cmd.ensure_string('option2', 'xxx')
|
||||
self.assert_(hasattr(cmd, 'option2'))
|
||||
self.assertTrue(hasattr(cmd, 'option2'))
|
||||
|
||||
cmd.option3 = 1
|
||||
self.assertRaises(DistutilsOptionError, cmd.ensure_string, 'option3')
|
||||
|
|
|
@ -105,9 +105,9 @@ class PyPIRCCommandTestCase(support.TempdirManager,
|
|||
def test_server_empty_registration(self):
|
||||
cmd = self._cmd(self.dist)
|
||||
rc = cmd._get_rc_file()
|
||||
self.assert_(not os.path.exists(rc))
|
||||
self.assertTrue(not os.path.exists(rc))
|
||||
cmd._store_pypirc('tarek', 'xxx')
|
||||
self.assert_(os.path.exists(rc))
|
||||
self.assertTrue(os.path.exists(rc))
|
||||
content = open(rc).read()
|
||||
self.assertEquals(content, WANTED)
|
||||
|
||||
|
|
|
@ -73,14 +73,14 @@ class ConfigTestCase(support.LoggingSilencer,
|
|||
self.write_file(f2, 'xxx')
|
||||
|
||||
for f in (f1, f2):
|
||||
self.assert_(os.path.exists(f))
|
||||
self.assertTrue(os.path.exists(f))
|
||||
|
||||
pkg_dir, dist = self.create_dist()
|
||||
cmd = config(dist)
|
||||
cmd._clean(f1, f2)
|
||||
|
||||
for f in (f1, f2):
|
||||
self.assert_(not os.path.exists(f))
|
||||
self.assertTrue(not os.path.exists(f))
|
||||
|
||||
def test_suite():
|
||||
return unittest.makeSuite(ConfigTestCase)
|
||||
|
|
|
@ -73,7 +73,7 @@ class DistributionTestCase(support.TempdirManager,
|
|||
self.assertEqual(d.get_command_packages(),
|
||||
["distutils.command", "foo.bar", "distutils.tests"])
|
||||
cmd = d.get_command_obj("test_dist")
|
||||
self.assert_(isinstance(cmd, test_dist))
|
||||
self.assertTrue(isinstance(cmd, test_dist))
|
||||
self.assertEqual(cmd.sample_option, "sometext")
|
||||
|
||||
def test_command_packages_configfile(self):
|
||||
|
@ -204,10 +204,10 @@ class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
|
|||
"version": "1.0"}
|
||||
dist = Distribution(attrs)
|
||||
meta = self.format_metadata(dist)
|
||||
self.assert_("Metadata-Version: 1.0" in meta)
|
||||
self.assert_("provides:" not in meta.lower())
|
||||
self.assert_("requires:" not in meta.lower())
|
||||
self.assert_("obsoletes:" not in meta.lower())
|
||||
self.assertTrue("Metadata-Version: 1.0" in meta)
|
||||
self.assertTrue("provides:" not in meta.lower())
|
||||
self.assertTrue("requires:" not in meta.lower())
|
||||
self.assertTrue("obsoletes:" not in meta.lower())
|
||||
|
||||
def test_provides(self):
|
||||
attrs = {"name": "package",
|
||||
|
@ -219,9 +219,9 @@ class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
|
|||
self.assertEqual(dist.get_provides(),
|
||||
["package", "package.sub"])
|
||||
meta = self.format_metadata(dist)
|
||||
self.assert_("Metadata-Version: 1.1" in meta)
|
||||
self.assert_("requires:" not in meta.lower())
|
||||
self.assert_("obsoletes:" not in meta.lower())
|
||||
self.assertTrue("Metadata-Version: 1.1" in meta)
|
||||
self.assertTrue("requires:" not in meta.lower())
|
||||
self.assertTrue("obsoletes:" not in meta.lower())
|
||||
|
||||
def test_provides_illegal(self):
|
||||
self.assertRaises(ValueError, Distribution,
|
||||
|
@ -239,11 +239,11 @@ class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
|
|||
self.assertEqual(dist.get_requires(),
|
||||
["other", "another (==1.0)"])
|
||||
meta = self.format_metadata(dist)
|
||||
self.assert_("Metadata-Version: 1.1" in meta)
|
||||
self.assert_("provides:" not in meta.lower())
|
||||
self.assert_("Requires: other" in meta)
|
||||
self.assert_("Requires: another (==1.0)" in meta)
|
||||
self.assert_("obsoletes:" not in meta.lower())
|
||||
self.assertTrue("Metadata-Version: 1.1" in meta)
|
||||
self.assertTrue("provides:" not in meta.lower())
|
||||
self.assertTrue("Requires: other" in meta)
|
||||
self.assertTrue("Requires: another (==1.0)" in meta)
|
||||
self.assertTrue("obsoletes:" not in meta.lower())
|
||||
|
||||
def test_requires_illegal(self):
|
||||
self.assertRaises(ValueError, Distribution,
|
||||
|
@ -261,11 +261,11 @@ class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
|
|||
self.assertEqual(dist.get_obsoletes(),
|
||||
["other", "another (<1.0)"])
|
||||
meta = self.format_metadata(dist)
|
||||
self.assert_("Metadata-Version: 1.1" in meta)
|
||||
self.assert_("provides:" not in meta.lower())
|
||||
self.assert_("requires:" not in meta.lower())
|
||||
self.assert_("Obsoletes: other" in meta)
|
||||
self.assert_("Obsoletes: another (<1.0)" in meta)
|
||||
self.assertTrue("Metadata-Version: 1.1" in meta)
|
||||
self.assertTrue("provides:" not in meta.lower())
|
||||
self.assertTrue("requires:" not in meta.lower())
|
||||
self.assertTrue("Obsoletes: other" in meta)
|
||||
self.assertTrue("Obsoletes: another (<1.0)" in meta)
|
||||
|
||||
def test_obsoletes_illegal(self):
|
||||
self.assertRaises(ValueError, Distribution,
|
||||
|
@ -299,14 +299,14 @@ class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
|
|||
if sys.platform in ('linux', 'darwin'):
|
||||
self.environ['HOME'] = temp_dir
|
||||
files = dist.find_config_files()
|
||||
self.assert_(user_filename in files)
|
||||
self.assertTrue(user_filename in files)
|
||||
|
||||
# win32-style
|
||||
if sys.platform == 'win32':
|
||||
# home drive should be found
|
||||
self.environ['HOME'] = temp_dir
|
||||
files = dist.find_config_files()
|
||||
self.assert_(user_filename in files,
|
||||
self.assertTrue(user_filename in files,
|
||||
'%r not found in %r' % (user_filename, files))
|
||||
finally:
|
||||
os.remove(user_filename)
|
||||
|
@ -332,7 +332,7 @@ class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
|
|||
|
||||
output = [line for line in s.getvalue().split('\n')
|
||||
if line.strip() != '']
|
||||
self.assert_(len(output) > 0)
|
||||
self.assertTrue(len(output) > 0)
|
||||
|
||||
def test_suite():
|
||||
suite = unittest.TestSuite()
|
||||
|
|
|
@ -88,7 +88,7 @@ class InstallTestCase(support.TempdirManager,
|
|||
|
||||
def _test_user_site(self):
|
||||
for key in ('nt_user', 'unix_user', 'os2_home'):
|
||||
self.assert_(key in INSTALL_SCHEMES)
|
||||
self.assertTrue(key in INSTALL_SCHEMES)
|
||||
|
||||
dist = Distribution({'name': 'xx'})
|
||||
cmd = install(dist)
|
||||
|
@ -96,24 +96,24 @@ class InstallTestCase(support.TempdirManager,
|
|||
# making sure the user option is there
|
||||
options = [name for name, short, lable in
|
||||
cmd.user_options]
|
||||
self.assert_('user' in options)
|
||||
self.assertTrue('user' in options)
|
||||
|
||||
# setting a value
|
||||
cmd.user = 1
|
||||
|
||||
# user base and site shouldn't be created yet
|
||||
self.assert_(not os.path.exists(self.user_base))
|
||||
self.assert_(not os.path.exists(self.user_site))
|
||||
self.assertTrue(not os.path.exists(self.user_base))
|
||||
self.assertTrue(not os.path.exists(self.user_site))
|
||||
|
||||
# let's run finalize
|
||||
cmd.ensure_finalized()
|
||||
|
||||
# now they should
|
||||
self.assert_(os.path.exists(self.user_base))
|
||||
self.assert_(os.path.exists(self.user_site))
|
||||
self.assertTrue(os.path.exists(self.user_base))
|
||||
self.assertTrue(os.path.exists(self.user_site))
|
||||
|
||||
self.assert_('userbase' in cmd.config_vars)
|
||||
self.assert_('usersite' in cmd.config_vars)
|
||||
self.assertTrue('userbase' in cmd.config_vars)
|
||||
self.assertTrue('usersite' in cmd.config_vars)
|
||||
|
||||
def test_handle_extra_path(self):
|
||||
dist = Distribution({'name': 'xx', 'extra_path': 'path,dirs'})
|
||||
|
|
|
@ -35,9 +35,9 @@ class InstallDataTestCase(support.TempdirManager,
|
|||
# let's check the result
|
||||
self.assertEquals(len(cmd.get_outputs()), 2)
|
||||
rtwo = os.path.split(two)[-1]
|
||||
self.assert_(os.path.exists(os.path.join(inst2, rtwo)))
|
||||
self.assertTrue(os.path.exists(os.path.join(inst2, rtwo)))
|
||||
rone = os.path.split(one)[-1]
|
||||
self.assert_(os.path.exists(os.path.join(inst, rone)))
|
||||
self.assertTrue(os.path.exists(os.path.join(inst, rone)))
|
||||
cmd.outfiles = []
|
||||
|
||||
# let's try with warn_dir one
|
||||
|
@ -47,8 +47,8 @@ class InstallDataTestCase(support.TempdirManager,
|
|||
|
||||
# let's check the result
|
||||
self.assertEquals(len(cmd.get_outputs()), 2)
|
||||
self.assert_(os.path.exists(os.path.join(inst2, rtwo)))
|
||||
self.assert_(os.path.exists(os.path.join(inst, rone)))
|
||||
self.assertTrue(os.path.exists(os.path.join(inst2, rtwo)))
|
||||
self.assertTrue(os.path.exists(os.path.join(inst, rone)))
|
||||
cmd.outfiles = []
|
||||
|
||||
# now using root and empty dir
|
||||
|
@ -65,8 +65,8 @@ class InstallDataTestCase(support.TempdirManager,
|
|||
|
||||
# let's check the result
|
||||
self.assertEquals(len(cmd.get_outputs()), 4)
|
||||
self.assert_(os.path.exists(os.path.join(inst2, rtwo)))
|
||||
self.assert_(os.path.exists(os.path.join(inst, rone)))
|
||||
self.assertTrue(os.path.exists(os.path.join(inst2, rtwo)))
|
||||
self.assertTrue(os.path.exists(os.path.join(inst, rone)))
|
||||
|
||||
def test_suite():
|
||||
return unittest.makeSuite(InstallDataTestCase)
|
||||
|
|
|
@ -39,8 +39,8 @@ class InstallLibTestCase(support.TempdirManager,
|
|||
f = os.path.join(pkg_dir, 'foo.py')
|
||||
self.write_file(f, '# python file')
|
||||
cmd.byte_compile([f])
|
||||
self.assert_(os.path.exists(os.path.join(pkg_dir, 'foo.pyc')))
|
||||
self.assert_(os.path.exists(os.path.join(pkg_dir, 'foo.pyo')))
|
||||
self.assertTrue(os.path.exists(os.path.join(pkg_dir, 'foo.pyc')))
|
||||
self.assertTrue(os.path.exists(os.path.join(pkg_dir, 'foo.pyo')))
|
||||
|
||||
def test_get_outputs(self):
|
||||
pkg_dir, dist = self.create_dist()
|
||||
|
@ -57,7 +57,7 @@ class InstallLibTestCase(support.TempdirManager,
|
|||
cmd.distribution.script_name = 'setup.py'
|
||||
|
||||
# get_output should return 4 elements
|
||||
self.assert_(len(cmd.get_outputs()) >= 2)
|
||||
self.assertTrue(len(cmd.get_outputs()) >= 2)
|
||||
|
||||
def test_get_inputs(self):
|
||||
pkg_dir, dist = self.create_dist()
|
||||
|
|
|
@ -23,15 +23,15 @@ class InstallScriptsTestCase(support.TempdirManager,
|
|||
skip_build=1,
|
||||
)
|
||||
cmd = install_scripts(dist)
|
||||
self.assert_(not cmd.force)
|
||||
self.assert_(not cmd.skip_build)
|
||||
self.assert_(cmd.build_dir is None)
|
||||
self.assert_(cmd.install_dir is None)
|
||||
self.assertTrue(not cmd.force)
|
||||
self.assertTrue(not cmd.skip_build)
|
||||
self.assertTrue(cmd.build_dir is None)
|
||||
self.assertTrue(cmd.install_dir is None)
|
||||
|
||||
cmd.finalize_options()
|
||||
|
||||
self.assert_(cmd.force)
|
||||
self.assert_(cmd.skip_build)
|
||||
self.assertTrue(cmd.force)
|
||||
self.assertTrue(cmd.skip_build)
|
||||
self.assertEqual(cmd.build_dir, "/foo/bar")
|
||||
self.assertEqual(cmd.install_dir, "/splat/funk")
|
||||
|
||||
|
@ -69,7 +69,7 @@ class InstallScriptsTestCase(support.TempdirManager,
|
|||
|
||||
installed = os.listdir(target)
|
||||
for name in expected:
|
||||
self.assert_(name in installed)
|
||||
self.assertTrue(name in installed)
|
||||
|
||||
|
||||
def test_suite():
|
||||
|
|
|
@ -46,7 +46,7 @@ class msvc9compilerTestCase(unittest.TestCase):
|
|||
# windows registeries versions.
|
||||
path = r'Software\Microsoft\Notepad'
|
||||
v = Reg.get_value(path, u"lfitalic")
|
||||
self.assert_(v in (0, 1))
|
||||
self.assertTrue(v in (0, 1))
|
||||
|
||||
import _winreg
|
||||
HKCU = _winreg.HKEY_CURRENT_USER
|
||||
|
@ -54,7 +54,7 @@ class msvc9compilerTestCase(unittest.TestCase):
|
|||
self.assertEquals(keys, None)
|
||||
|
||||
keys = Reg.read_keys(HKCU, r'Software\Microsoft')
|
||||
self.assert_('Notepad' in keys)
|
||||
self.assertTrue('Notepad' in keys)
|
||||
|
||||
def test_suite():
|
||||
return unittest.makeSuite(msvc9compilerTestCase)
|
||||
|
|
|
@ -96,7 +96,7 @@ class RegisterTestCase(PyPIRCCommandTestCase):
|
|||
cmd = self._get_cmd()
|
||||
|
||||
# we shouldn't have a .pypirc file yet
|
||||
self.assert_(not os.path.exists(self.rc))
|
||||
self.assertTrue(not os.path.exists(self.rc))
|
||||
|
||||
# patching raw_input and getpass.getpass
|
||||
# so register gets happy
|
||||
|
@ -115,7 +115,7 @@ class RegisterTestCase(PyPIRCCommandTestCase):
|
|||
del register_module.raw_input
|
||||
|
||||
# we should have a brand new .pypirc file
|
||||
self.assert_(os.path.exists(self.rc))
|
||||
self.assertTrue(os.path.exists(self.rc))
|
||||
|
||||
# with the content similar to WANTED_PYPIRC
|
||||
content = open(self.rc).read()
|
||||
|
@ -133,13 +133,13 @@ class RegisterTestCase(PyPIRCCommandTestCase):
|
|||
|
||||
# let's see what the server received : we should
|
||||
# have 2 similar requests
|
||||
self.assert_(self.conn.reqs, 2)
|
||||
self.assertTrue(self.conn.reqs, 2)
|
||||
req1 = dict(self.conn.reqs[0].headers)
|
||||
req2 = dict(self.conn.reqs[1].headers)
|
||||
|
||||
self.assertEquals(req1['Content-length'], '1374')
|
||||
self.assertEquals(req2['Content-length'], '1374')
|
||||
self.assert_('xxx' in self.conn.reqs[1].data)
|
||||
self.assertTrue('xxx' in self.conn.reqs[1].data)
|
||||
|
||||
def test_password_not_in_file(self):
|
||||
|
||||
|
@ -165,11 +165,11 @@ class RegisterTestCase(PyPIRCCommandTestCase):
|
|||
del register_module.raw_input
|
||||
|
||||
# we should have send a request
|
||||
self.assert_(self.conn.reqs, 1)
|
||||
self.assertTrue(self.conn.reqs, 1)
|
||||
req = self.conn.reqs[0]
|
||||
headers = dict(req.headers)
|
||||
self.assertEquals(headers['Content-length'], '608')
|
||||
self.assert_('tarek' in req.data)
|
||||
self.assertTrue('tarek' in req.data)
|
||||
|
||||
def test_password_reset(self):
|
||||
# this test runs choice 3
|
||||
|
@ -183,11 +183,11 @@ class RegisterTestCase(PyPIRCCommandTestCase):
|
|||
del register_module.raw_input
|
||||
|
||||
# we should have send a request
|
||||
self.assert_(self.conn.reqs, 1)
|
||||
self.assertTrue(self.conn.reqs, 1)
|
||||
req = self.conn.reqs[0]
|
||||
headers = dict(req.headers)
|
||||
self.assertEquals(headers['Content-length'], '290')
|
||||
self.assert_('tarek' in req.data)
|
||||
self.assertTrue('tarek' in req.data)
|
||||
|
||||
def test_strict(self):
|
||||
# testing the script option
|
||||
|
|
|
@ -21,12 +21,12 @@ class SysconfigTestCase(support.EnvironGuard,
|
|||
|
||||
def test_get_config_h_filename(self):
|
||||
config_h = sysconfig.get_config_h_filename()
|
||||
self.assert_(os.path.isfile(config_h), config_h)
|
||||
self.assertTrue(os.path.isfile(config_h), config_h)
|
||||
|
||||
def test_get_python_lib(self):
|
||||
lib_dir = sysconfig.get_python_lib()
|
||||
# XXX doesn't work on Linux when Python was never installed before
|
||||
#self.assert_(os.path.isdir(lib_dir), lib_dir)
|
||||
#self.assertTrue(os.path.isdir(lib_dir), lib_dir)
|
||||
# test for pythonxx.lib?
|
||||
self.assertNotEqual(sysconfig.get_python_lib(),
|
||||
sysconfig.get_python_lib(prefix=TESTFN))
|
||||
|
@ -36,14 +36,14 @@ class SysconfigTestCase(support.EnvironGuard,
|
|||
# This is not much of a test. We make sure Python.h exists
|
||||
# in the directory returned by get_python_inc() but we don't know
|
||||
# it is the correct file.
|
||||
self.assert_(os.path.isdir(inc_dir), inc_dir)
|
||||
self.assertTrue(os.path.isdir(inc_dir), inc_dir)
|
||||
python_h = os.path.join(inc_dir, "Python.h")
|
||||
self.assert_(os.path.isfile(python_h), python_h)
|
||||
self.assertTrue(os.path.isfile(python_h), python_h)
|
||||
|
||||
def test_get_config_vars(self):
|
||||
cvars = sysconfig.get_config_vars()
|
||||
self.assert_(isinstance(cvars, dict))
|
||||
self.assert_(cvars)
|
||||
self.assertTrue(isinstance(cvars, dict))
|
||||
self.assertTrue(cvars)
|
||||
|
||||
def test_customize_compiler(self):
|
||||
|
||||
|
|
|
@ -96,11 +96,11 @@ class uploadTestCase(PyPIRCCommandTestCase):
|
|||
# what did we send ?
|
||||
headers = dict(self.last_open.req.headers)
|
||||
self.assertEquals(headers['Content-length'], '2086')
|
||||
self.assert_(headers['Content-type'].startswith('multipart/form-data'))
|
||||
self.assertTrue(headers['Content-type'].startswith('multipart/form-data'))
|
||||
self.assertEquals(self.last_open.req.get_method(), 'POST')
|
||||
self.assertEquals(self.last_open.req.get_full_url(),
|
||||
'http://pypi.python.org/pypi')
|
||||
self.assert_('xxx' in self.last_open.req.data)
|
||||
self.assertTrue('xxx' in self.last_open.req.data)
|
||||
|
||||
def test_suite():
|
||||
return unittest.makeSuite(uploadTestCase)
|
||||
|
|
|
@ -225,10 +225,10 @@ class UtilTestCase(support.EnvironGuard, unittest.TestCase):
|
|||
no = ('n', 'no', 'f', 'false', 'off', '0', 'Off', 'No', 'N')
|
||||
|
||||
for y in yes:
|
||||
self.assert_(strtobool(y))
|
||||
self.assertTrue(strtobool(y))
|
||||
|
||||
for n in no:
|
||||
self.assert_(not strtobool(n))
|
||||
self.assertTrue(not strtobool(n))
|
||||
|
||||
def test_rfc822_escape(self):
|
||||
header = 'I am a\npoor\nlonesome\nheader\n'
|
||||
|
|
|
@ -50,7 +50,7 @@ def openfile(filename, mode='r'):
|
|||
# Base test class
|
||||
class TestEmailBase(unittest.TestCase):
|
||||
def ndiffAssertEqual(self, first, second):
|
||||
"""Like failUnlessEqual except use ndiff for readable output."""
|
||||
"""Like assertEqual except use ndiff for readable output."""
|
||||
if first <> second:
|
||||
sfirst = str(first)
|
||||
ssecond = str(second)
|
||||
|
@ -239,12 +239,12 @@ class TestMessageAPI(TestEmailBase):
|
|||
msg['From'] = 'Me'
|
||||
msg['to'] = 'You'
|
||||
# Check for case insensitivity
|
||||
self.failUnless('from' in msg)
|
||||
self.failUnless('From' in msg)
|
||||
self.failUnless('FROM' in msg)
|
||||
self.failUnless('to' in msg)
|
||||
self.failUnless('To' in msg)
|
||||
self.failUnless('TO' in msg)
|
||||
self.assertTrue('from' in msg)
|
||||
self.assertTrue('From' in msg)
|
||||
self.assertTrue('FROM' in msg)
|
||||
self.assertTrue('to' in msg)
|
||||
self.assertTrue('To' in msg)
|
||||
self.assertTrue('TO' in msg)
|
||||
|
||||
def test_as_string(self):
|
||||
eq = self.assertEqual
|
||||
|
@ -266,7 +266,7 @@ class TestMessageAPI(TestEmailBase):
|
|||
eq(text, msg.as_string())
|
||||
fullrepr = str(msg)
|
||||
lines = fullrepr.split('\n')
|
||||
self.failUnless(lines[0].startswith('From '))
|
||||
self.assertTrue(lines[0].startswith('From '))
|
||||
eq(text, NL.join(lines[1:]))
|
||||
|
||||
def test_bad_param(self):
|
||||
|
@ -337,10 +337,10 @@ class TestMessageAPI(TestEmailBase):
|
|||
|
||||
def test_has_key(self):
|
||||
msg = email.message_from_string('Header: exists')
|
||||
self.failUnless(msg.has_key('header'))
|
||||
self.failUnless(msg.has_key('Header'))
|
||||
self.failUnless(msg.has_key('HEADER'))
|
||||
self.failIf(msg.has_key('headeri'))
|
||||
self.assertTrue(msg.has_key('header'))
|
||||
self.assertTrue(msg.has_key('Header'))
|
||||
self.assertTrue(msg.has_key('HEADER'))
|
||||
self.assertFalse(msg.has_key('headeri'))
|
||||
|
||||
def test_set_param(self):
|
||||
eq = self.assertEqual
|
||||
|
@ -931,7 +931,7 @@ class TestMIMEAudio(unittest.TestCase):
|
|||
|
||||
def test_add_header(self):
|
||||
eq = self.assertEqual
|
||||
unless = self.failUnless
|
||||
unless = self.assertTrue
|
||||
self._au.add_header('Content-Disposition', 'attachment',
|
||||
filename='audiotest.au')
|
||||
eq(self._au['content-disposition'],
|
||||
|
@ -974,7 +974,7 @@ class TestMIMEImage(unittest.TestCase):
|
|||
|
||||
def test_add_header(self):
|
||||
eq = self.assertEqual
|
||||
unless = self.failUnless
|
||||
unless = self.assertTrue
|
||||
self._im.add_header('Content-Disposition', 'attachment',
|
||||
filename='dingusfish.gif')
|
||||
eq(self._im['content-disposition'],
|
||||
|
@ -1001,7 +1001,7 @@ class TestMIMEText(unittest.TestCase):
|
|||
|
||||
def test_types(self):
|
||||
eq = self.assertEqual
|
||||
unless = self.failUnless
|
||||
unless = self.assertTrue
|
||||
eq(self._msg.get_content_type(), 'text/plain')
|
||||
eq(self._msg.get_param('charset'), 'us-ascii')
|
||||
missing = []
|
||||
|
@ -1011,7 +1011,7 @@ class TestMIMEText(unittest.TestCase):
|
|||
|
||||
def test_payload(self):
|
||||
self.assertEqual(self._msg.get_payload(), 'hello there')
|
||||
self.failUnless(not self._msg.is_multipart())
|
||||
self.assertTrue(not self._msg.is_multipart())
|
||||
|
||||
def test_charset(self):
|
||||
eq = self.assertEqual
|
||||
|
@ -1066,7 +1066,7 @@ This is the dingus fish.
|
|||
def test_hierarchy(self):
|
||||
# convenience
|
||||
eq = self.assertEqual
|
||||
unless = self.failUnless
|
||||
unless = self.assertTrue
|
||||
raises = self.assertRaises
|
||||
# tests
|
||||
m = self._msg
|
||||
|
@ -1380,7 +1380,7 @@ Content-Type: text/plain
|
|||
|
||||
-- XXXX--
|
||||
''')
|
||||
self.failUnless(msg.is_multipart())
|
||||
self.assertTrue(msg.is_multipart())
|
||||
eq(msg.get_boundary(), ' XXXX')
|
||||
eq(len(msg.get_payload()), 2)
|
||||
|
||||
|
@ -1410,7 +1410,7 @@ class TestNonConformant(TestEmailBase):
|
|||
eq(msg.get_content_subtype(), 'plain')
|
||||
|
||||
def test_same_boundary_inner_outer(self):
|
||||
unless = self.failUnless
|
||||
unless = self.assertTrue
|
||||
msg = self._msgobj('msg_15.txt')
|
||||
# XXX We can probably eventually do better
|
||||
inner = msg.get_payload(0)
|
||||
|
@ -1420,7 +1420,7 @@ class TestNonConformant(TestEmailBase):
|
|||
Errors.StartBoundaryNotFoundDefect))
|
||||
|
||||
def test_multipart_no_boundary(self):
|
||||
unless = self.failUnless
|
||||
unless = self.assertTrue
|
||||
msg = self._msgobj('msg_25.txt')
|
||||
unless(isinstance(msg.get_payload(), str))
|
||||
self.assertEqual(len(msg.defects), 2)
|
||||
|
@ -1478,7 +1478,7 @@ counter to RFC 2822, there's no separating newline here
|
|||
""")
|
||||
|
||||
def test_lying_multipart(self):
|
||||
unless = self.failUnless
|
||||
unless = self.assertTrue
|
||||
msg = self._msgobj('msg_41.txt')
|
||||
unless(hasattr(msg, 'defects'))
|
||||
self.assertEqual(len(msg.defects), 2)
|
||||
|
@ -1498,7 +1498,7 @@ counter to RFC 2822, there's no separating newline here
|
|||
# [*] This message is missing its start boundary
|
||||
bad = outer.get_payload(1).get_payload(0)
|
||||
self.assertEqual(len(bad.defects), 1)
|
||||
self.failUnless(isinstance(bad.defects[0],
|
||||
self.assertTrue(isinstance(bad.defects[0],
|
||||
Errors.StartBoundaryNotFoundDefect))
|
||||
|
||||
def test_first_line_is_continuation_header(self):
|
||||
|
@ -1508,7 +1508,7 @@ counter to RFC 2822, there's no separating newline here
|
|||
eq(msg.keys(), [])
|
||||
eq(msg.get_payload(), 'Line 2\nLine 3')
|
||||
eq(len(msg.defects), 1)
|
||||
self.failUnless(isinstance(msg.defects[0],
|
||||
self.assertTrue(isinstance(msg.defects[0],
|
||||
Errors.FirstHeaderLineIsContinuationDefect))
|
||||
eq(msg.defects[0].line, ' Line 1\n')
|
||||
|
||||
|
@ -1576,7 +1576,7 @@ class TestMIMEMessage(TestEmailBase):
|
|||
|
||||
def test_valid_argument(self):
|
||||
eq = self.assertEqual
|
||||
unless = self.failUnless
|
||||
unless = self.assertTrue
|
||||
subject = 'A sub-message'
|
||||
m = Message()
|
||||
m['Subject'] = subject
|
||||
|
@ -1620,20 +1620,20 @@ Here is the body of the message.
|
|||
|
||||
def test_parse_message_rfc822(self):
|
||||
eq = self.assertEqual
|
||||
unless = self.failUnless
|
||||
unless = self.assertTrue
|
||||
msg = self._msgobj('msg_11.txt')
|
||||
eq(msg.get_content_type(), 'message/rfc822')
|
||||
payload = msg.get_payload()
|
||||
unless(isinstance(payload, list))
|
||||
eq(len(payload), 1)
|
||||
submsg = payload[0]
|
||||
self.failUnless(isinstance(submsg, Message))
|
||||
self.assertTrue(isinstance(submsg, Message))
|
||||
eq(submsg['subject'], 'An enclosed message')
|
||||
eq(submsg.get_payload(), 'Here is the body of the message.\n')
|
||||
|
||||
def test_dsn(self):
|
||||
eq = self.assertEqual
|
||||
unless = self.failUnless
|
||||
unless = self.assertTrue
|
||||
# msg 16 is a Delivery Status Notification, see RFC 1894
|
||||
msg = self._msgobj('msg_16.txt')
|
||||
eq(msg.get_content_type(), 'multipart/report')
|
||||
|
@ -1983,7 +1983,7 @@ class TestIdempotent(TestEmailBase):
|
|||
|
||||
def test_content_type(self):
|
||||
eq = self.assertEquals
|
||||
unless = self.failUnless
|
||||
unless = self.assertTrue
|
||||
# Get a message object and reset the seek pointer for other tests
|
||||
msg, text = self._msgobj('msg_05.txt')
|
||||
eq(msg.get_content_type(), 'multipart/report')
|
||||
|
@ -2005,7 +2005,7 @@ class TestIdempotent(TestEmailBase):
|
|||
eq(msg2.get_payload(), 'Yadda yadda yadda\n')
|
||||
msg3 = msg.get_payload(2)
|
||||
eq(msg3.get_content_type(), 'message/rfc822')
|
||||
self.failUnless(isinstance(msg3, Message))
|
||||
self.assertTrue(isinstance(msg3, Message))
|
||||
payload = msg3.get_payload()
|
||||
unless(isinstance(payload, list))
|
||||
eq(len(payload), 1)
|
||||
|
@ -2015,7 +2015,7 @@ class TestIdempotent(TestEmailBase):
|
|||
|
||||
def test_parser(self):
|
||||
eq = self.assertEquals
|
||||
unless = self.failUnless
|
||||
unless = self.assertTrue
|
||||
msg, text = self._msgobj('msg_06.txt')
|
||||
# Check some of the outer headers
|
||||
eq(msg.get_content_type(), 'message/rfc822')
|
||||
|
@ -2025,9 +2025,9 @@ class TestIdempotent(TestEmailBase):
|
|||
unless(isinstance(payload, list))
|
||||
eq(len(payload), 1)
|
||||
msg1 = payload[0]
|
||||
self.failUnless(isinstance(msg1, Message))
|
||||
self.assertTrue(isinstance(msg1, Message))
|
||||
eq(msg1.get_content_type(), 'text/plain')
|
||||
self.failUnless(isinstance(msg1.get_payload(), str))
|
||||
self.assertTrue(isinstance(msg1.get_payload(), str))
|
||||
eq(msg1.get_payload(), '\n')
|
||||
|
||||
|
||||
|
@ -2064,7 +2064,7 @@ class TestMiscellaneous(TestEmailBase):
|
|||
fp.close()
|
||||
|
||||
def test_message_from_string_with_class(self):
|
||||
unless = self.failUnless
|
||||
unless = self.assertTrue
|
||||
fp = openfile('msg_01.txt')
|
||||
try:
|
||||
text = fp.read()
|
||||
|
@ -2087,7 +2087,7 @@ class TestMiscellaneous(TestEmailBase):
|
|||
unless(isinstance(subpart, MyMessage))
|
||||
|
||||
def test_message_from_file_with_class(self):
|
||||
unless = self.failUnless
|
||||
unless = self.assertTrue
|
||||
# Create a subclass
|
||||
class MyMessage(Message):
|
||||
pass
|
||||
|
@ -2229,7 +2229,7 @@ Foo
|
|||
|
||||
def test_charset_richcomparisons(self):
|
||||
eq = self.assertEqual
|
||||
ne = self.failIfEqual
|
||||
ne = self.assertNotEqual
|
||||
cset1 = Charset()
|
||||
cset2 = Charset()
|
||||
eq(cset1, 'us-ascii')
|
||||
|
@ -2428,8 +2428,8 @@ class TestParsers(TestEmailBase):
|
|||
eq(msg['from'], 'ppp-request@zzz.org')
|
||||
eq(msg['to'], 'ppp@zzz.org')
|
||||
eq(msg.get_content_type(), 'multipart/mixed')
|
||||
self.failIf(msg.is_multipart())
|
||||
self.failUnless(isinstance(msg.get_payload(), str))
|
||||
self.assertFalse(msg.is_multipart())
|
||||
self.assertTrue(isinstance(msg.get_payload(), str))
|
||||
|
||||
def test_whitespace_continuation(self):
|
||||
eq = self.assertEqual
|
||||
|
@ -2648,15 +2648,15 @@ class TestQuopri(unittest.TestCase):
|
|||
|
||||
def test_header_quopri_check(self):
|
||||
for c in self.hlit:
|
||||
self.failIf(quopriMIME.header_quopri_check(c))
|
||||
self.assertFalse(quopriMIME.header_quopri_check(c))
|
||||
for c in self.hnon:
|
||||
self.failUnless(quopriMIME.header_quopri_check(c))
|
||||
self.assertTrue(quopriMIME.header_quopri_check(c))
|
||||
|
||||
def test_body_quopri_check(self):
|
||||
for c in self.blit:
|
||||
self.failIf(quopriMIME.body_quopri_check(c))
|
||||
self.assertFalse(quopriMIME.body_quopri_check(c))
|
||||
for c in self.bnon:
|
||||
self.failUnless(quopriMIME.body_quopri_check(c))
|
||||
self.assertTrue(quopriMIME.body_quopri_check(c))
|
||||
|
||||
def test_header_quopri_len(self):
|
||||
eq = self.assertEqual
|
||||
|
@ -2825,7 +2825,7 @@ class TestHeader(TestEmailBase):
|
|||
h = Header("I am the very model of a modern Major-General; I've information vegetable, animal, and mineral; I know the kings of England, and I quote the fights historical from Marathon to Waterloo, in order categorical; I'm very well acquainted, too, with matters mathematical; I understand equations, both the simple and quadratical; about binomial theorem I'm teeming with a lot o' news, with many cheerful facts about the square of the hypotenuse.",
|
||||
maxlinelen=76)
|
||||
for l in h.encode(splitchars=' ').split('\n '):
|
||||
self.failUnless(len(l) <= 76)
|
||||
self.assertTrue(len(l) <= 76)
|
||||
|
||||
def test_multilingual(self):
|
||||
eq = self.ndiffAssertEqual
|
||||
|
@ -3055,7 +3055,7 @@ Content-Type: text/html; NAME*0=file____C__DOCUMENTS_20AND_20SETTINGS_FABIEN_LOC
|
|||
'''
|
||||
msg = email.message_from_string(m)
|
||||
param = msg.get_param('NAME')
|
||||
self.failIf(isinstance(param, tuple))
|
||||
self.assertFalse(isinstance(param, tuple))
|
||||
self.assertEqual(
|
||||
param,
|
||||
'file____C__DOCUMENTS_20AND_20SETTINGS_FABIEN_LOCAL_20SETTINGS_TEMP_nsmail.htm')
|
||||
|
@ -3208,7 +3208,7 @@ Content-Type: application/x-foo; name*0=\"Frank's\"; name*1=\" Document\"
|
|||
"""
|
||||
msg = email.message_from_string(m)
|
||||
param = msg.get_param('name')
|
||||
self.failIf(isinstance(param, tuple))
|
||||
self.assertFalse(isinstance(param, tuple))
|
||||
self.assertEqual(param, "Frank's Document")
|
||||
|
||||
def test_rfc2231_tick_attack_extended(self):
|
||||
|
@ -3232,7 +3232,7 @@ Content-Type: application/x-foo;
|
|||
"""
|
||||
msg = email.message_from_string(m)
|
||||
param = msg.get_param('name')
|
||||
self.failIf(isinstance(param, tuple))
|
||||
self.assertFalse(isinstance(param, tuple))
|
||||
self.assertEqual(param, "us-ascii'en-us'Frank's Document")
|
||||
|
||||
def test_rfc2231_no_extended_values(self):
|
||||
|
|
|
@ -51,7 +51,7 @@ def openfile(filename, mode='r'):
|
|||
# Base test class
|
||||
class TestEmailBase(unittest.TestCase):
|
||||
def ndiffAssertEqual(self, first, second):
|
||||
"""Like failUnlessEqual except use ndiff for readable output."""
|
||||
"""Like assertEqual except use ndiff for readable output."""
|
||||
if first <> second:
|
||||
sfirst = str(first)
|
||||
ssecond = str(second)
|
||||
|
@ -227,12 +227,12 @@ class TestMessageAPI(TestEmailBase):
|
|||
msg['From'] = 'Me'
|
||||
msg['to'] = 'You'
|
||||
# Check for case insensitivity
|
||||
self.failUnless('from' in msg)
|
||||
self.failUnless('From' in msg)
|
||||
self.failUnless('FROM' in msg)
|
||||
self.failUnless('to' in msg)
|
||||
self.failUnless('To' in msg)
|
||||
self.failUnless('TO' in msg)
|
||||
self.assertTrue('from' in msg)
|
||||
self.assertTrue('From' in msg)
|
||||
self.assertTrue('FROM' in msg)
|
||||
self.assertTrue('to' in msg)
|
||||
self.assertTrue('To' in msg)
|
||||
self.assertTrue('TO' in msg)
|
||||
|
||||
def test_as_string(self):
|
||||
eq = self.assertEqual
|
||||
|
@ -254,7 +254,7 @@ class TestMessageAPI(TestEmailBase):
|
|||
self.ndiffAssertEqual(text, msg.as_string())
|
||||
fullrepr = str(msg)
|
||||
lines = fullrepr.split('\n')
|
||||
self.failUnless(lines[0].startswith('From '))
|
||||
self.assertTrue(lines[0].startswith('From '))
|
||||
eq(text, NL.join(lines[1:]))
|
||||
|
||||
def test_bad_param(self):
|
||||
|
@ -325,10 +325,10 @@ class TestMessageAPI(TestEmailBase):
|
|||
|
||||
def test_has_key(self):
|
||||
msg = email.message_from_string('Header: exists')
|
||||
self.failUnless(msg.has_key('header'))
|
||||
self.failUnless(msg.has_key('Header'))
|
||||
self.failUnless(msg.has_key('HEADER'))
|
||||
self.failIf(msg.has_key('headeri'))
|
||||
self.assertTrue(msg.has_key('header'))
|
||||
self.assertTrue(msg.has_key('Header'))
|
||||
self.assertTrue(msg.has_key('HEADER'))
|
||||
self.assertFalse(msg.has_key('headeri'))
|
||||
|
||||
def test_set_param(self):
|
||||
eq = self.assertEqual
|
||||
|
@ -912,7 +912,7 @@ class TestMIMEAudio(unittest.TestCase):
|
|||
|
||||
def test_add_header(self):
|
||||
eq = self.assertEqual
|
||||
unless = self.failUnless
|
||||
unless = self.assertTrue
|
||||
self._au.add_header('Content-Disposition', 'attachment',
|
||||
filename='audiotest.au')
|
||||
eq(self._au['content-disposition'],
|
||||
|
@ -955,7 +955,7 @@ class TestMIMEImage(unittest.TestCase):
|
|||
|
||||
def test_add_header(self):
|
||||
eq = self.assertEqual
|
||||
unless = self.failUnless
|
||||
unless = self.assertTrue
|
||||
self._im.add_header('Content-Disposition', 'attachment',
|
||||
filename='dingusfish.gif')
|
||||
eq(self._im['content-disposition'],
|
||||
|
@ -999,7 +999,7 @@ class TestMIMEText(unittest.TestCase):
|
|||
|
||||
def test_types(self):
|
||||
eq = self.assertEqual
|
||||
unless = self.failUnless
|
||||
unless = self.assertTrue
|
||||
eq(self._msg.get_content_type(), 'text/plain')
|
||||
eq(self._msg.get_param('charset'), 'us-ascii')
|
||||
missing = []
|
||||
|
@ -1009,7 +1009,7 @@ class TestMIMEText(unittest.TestCase):
|
|||
|
||||
def test_payload(self):
|
||||
self.assertEqual(self._msg.get_payload(), 'hello there')
|
||||
self.failUnless(not self._msg.is_multipart())
|
||||
self.assertTrue(not self._msg.is_multipart())
|
||||
|
||||
def test_charset(self):
|
||||
eq = self.assertEqual
|
||||
|
@ -1064,7 +1064,7 @@ This is the dingus fish.
|
|||
def test_hierarchy(self):
|
||||
# convenience
|
||||
eq = self.assertEqual
|
||||
unless = self.failUnless
|
||||
unless = self.assertTrue
|
||||
raises = self.assertRaises
|
||||
# tests
|
||||
m = self._msg
|
||||
|
@ -1378,7 +1378,7 @@ Content-Type: text/plain
|
|||
|
||||
-- XXXX--
|
||||
''')
|
||||
self.failUnless(msg.is_multipart())
|
||||
self.assertTrue(msg.is_multipart())
|
||||
eq(msg.get_boundary(), ' XXXX')
|
||||
eq(len(msg.get_payload()), 2)
|
||||
|
||||
|
@ -1408,7 +1408,7 @@ class TestNonConformant(TestEmailBase):
|
|||
eq(msg.get_content_subtype(), 'plain')
|
||||
|
||||
def test_same_boundary_inner_outer(self):
|
||||
unless = self.failUnless
|
||||
unless = self.assertTrue
|
||||
msg = self._msgobj('msg_15.txt')
|
||||
# XXX We can probably eventually do better
|
||||
inner = msg.get_payload(0)
|
||||
|
@ -1418,7 +1418,7 @@ class TestNonConformant(TestEmailBase):
|
|||
errors.StartBoundaryNotFoundDefect))
|
||||
|
||||
def test_multipart_no_boundary(self):
|
||||
unless = self.failUnless
|
||||
unless = self.assertTrue
|
||||
msg = self._msgobj('msg_25.txt')
|
||||
unless(isinstance(msg.get_payload(), str))
|
||||
self.assertEqual(len(msg.defects), 2)
|
||||
|
@ -1476,7 +1476,7 @@ counter to RFC 2822, there's no separating newline here
|
|||
""")
|
||||
|
||||
def test_lying_multipart(self):
|
||||
unless = self.failUnless
|
||||
unless = self.assertTrue
|
||||
msg = self._msgobj('msg_41.txt')
|
||||
unless(hasattr(msg, 'defects'))
|
||||
self.assertEqual(len(msg.defects), 2)
|
||||
|
@ -1496,7 +1496,7 @@ counter to RFC 2822, there's no separating newline here
|
|||
# [*] This message is missing its start boundary
|
||||
bad = outer.get_payload(1).get_payload(0)
|
||||
self.assertEqual(len(bad.defects), 1)
|
||||
self.failUnless(isinstance(bad.defects[0],
|
||||
self.assertTrue(isinstance(bad.defects[0],
|
||||
errors.StartBoundaryNotFoundDefect))
|
||||
|
||||
def test_first_line_is_continuation_header(self):
|
||||
|
@ -1506,7 +1506,7 @@ counter to RFC 2822, there's no separating newline here
|
|||
eq(msg.keys(), [])
|
||||
eq(msg.get_payload(), 'Line 2\nLine 3')
|
||||
eq(len(msg.defects), 1)
|
||||
self.failUnless(isinstance(msg.defects[0],
|
||||
self.assertTrue(isinstance(msg.defects[0],
|
||||
errors.FirstHeaderLineIsContinuationDefect))
|
||||
eq(msg.defects[0].line, ' Line 1\n')
|
||||
|
||||
|
@ -1573,7 +1573,7 @@ class TestMIMEMessage(TestEmailBase):
|
|||
|
||||
def test_valid_argument(self):
|
||||
eq = self.assertEqual
|
||||
unless = self.failUnless
|
||||
unless = self.assertTrue
|
||||
subject = 'A sub-message'
|
||||
m = Message()
|
||||
m['Subject'] = subject
|
||||
|
@ -1617,20 +1617,20 @@ Here is the body of the message.
|
|||
|
||||
def test_parse_message_rfc822(self):
|
||||
eq = self.assertEqual
|
||||
unless = self.failUnless
|
||||
unless = self.assertTrue
|
||||
msg = self._msgobj('msg_11.txt')
|
||||
eq(msg.get_content_type(), 'message/rfc822')
|
||||
payload = msg.get_payload()
|
||||
unless(isinstance(payload, list))
|
||||
eq(len(payload), 1)
|
||||
submsg = payload[0]
|
||||
self.failUnless(isinstance(submsg, Message))
|
||||
self.assertTrue(isinstance(submsg, Message))
|
||||
eq(submsg['subject'], 'An enclosed message')
|
||||
eq(submsg.get_payload(), 'Here is the body of the message.\n')
|
||||
|
||||
def test_dsn(self):
|
||||
eq = self.assertEqual
|
||||
unless = self.failUnless
|
||||
unless = self.assertTrue
|
||||
# msg 16 is a Delivery Status Notification, see RFC 1894
|
||||
msg = self._msgobj('msg_16.txt')
|
||||
eq(msg.get_content_type(), 'multipart/report')
|
||||
|
@ -1977,7 +1977,7 @@ class TestIdempotent(TestEmailBase):
|
|||
|
||||
def test_content_type(self):
|
||||
eq = self.assertEquals
|
||||
unless = self.failUnless
|
||||
unless = self.assertTrue
|
||||
# Get a message object and reset the seek pointer for other tests
|
||||
msg, text = self._msgobj('msg_05.txt')
|
||||
eq(msg.get_content_type(), 'multipart/report')
|
||||
|
@ -1999,7 +1999,7 @@ class TestIdempotent(TestEmailBase):
|
|||
eq(msg2.get_payload(), 'Yadda yadda yadda\n')
|
||||
msg3 = msg.get_payload(2)
|
||||
eq(msg3.get_content_type(), 'message/rfc822')
|
||||
self.failUnless(isinstance(msg3, Message))
|
||||
self.assertTrue(isinstance(msg3, Message))
|
||||
payload = msg3.get_payload()
|
||||
unless(isinstance(payload, list))
|
||||
eq(len(payload), 1)
|
||||
|
@ -2009,7 +2009,7 @@ class TestIdempotent(TestEmailBase):
|
|||
|
||||
def test_parser(self):
|
||||
eq = self.assertEquals
|
||||
unless = self.failUnless
|
||||
unless = self.assertTrue
|
||||
msg, text = self._msgobj('msg_06.txt')
|
||||
# Check some of the outer headers
|
||||
eq(msg.get_content_type(), 'message/rfc822')
|
||||
|
@ -2019,9 +2019,9 @@ class TestIdempotent(TestEmailBase):
|
|||
unless(isinstance(payload, list))
|
||||
eq(len(payload), 1)
|
||||
msg1 = payload[0]
|
||||
self.failUnless(isinstance(msg1, Message))
|
||||
self.assertTrue(isinstance(msg1, Message))
|
||||
eq(msg1.get_content_type(), 'text/plain')
|
||||
self.failUnless(isinstance(msg1.get_payload(), str))
|
||||
self.assertTrue(isinstance(msg1.get_payload(), str))
|
||||
eq(msg1.get_payload(), '\n')
|
||||
|
||||
|
||||
|
@ -2058,7 +2058,7 @@ class TestMiscellaneous(TestEmailBase):
|
|||
fp.close()
|
||||
|
||||
def test_message_from_string_with_class(self):
|
||||
unless = self.failUnless
|
||||
unless = self.assertTrue
|
||||
fp = openfile('msg_01.txt')
|
||||
try:
|
||||
text = fp.read()
|
||||
|
@ -2081,7 +2081,7 @@ class TestMiscellaneous(TestEmailBase):
|
|||
unless(isinstance(subpart, MyMessage))
|
||||
|
||||
def test_message_from_file_with_class(self):
|
||||
unless = self.failUnless
|
||||
unless = self.assertTrue
|
||||
# Create a subclass
|
||||
class MyMessage(Message):
|
||||
pass
|
||||
|
@ -2224,7 +2224,7 @@ Foo
|
|||
|
||||
def test_charset_richcomparisons(self):
|
||||
eq = self.assertEqual
|
||||
ne = self.failIfEqual
|
||||
ne = self.assertNotEqual
|
||||
cset1 = Charset()
|
||||
cset2 = Charset()
|
||||
eq(cset1, 'us-ascii')
|
||||
|
@ -2423,8 +2423,8 @@ class TestParsers(TestEmailBase):
|
|||
eq(msg['from'], 'ppp-request@zzz.org')
|
||||
eq(msg['to'], 'ppp@zzz.org')
|
||||
eq(msg.get_content_type(), 'multipart/mixed')
|
||||
self.failIf(msg.is_multipart())
|
||||
self.failUnless(isinstance(msg.get_payload(), str))
|
||||
self.assertFalse(msg.is_multipart())
|
||||
self.assertTrue(isinstance(msg.get_payload(), str))
|
||||
|
||||
def test_whitespace_continuation(self):
|
||||
eq = self.assertEqual
|
||||
|
@ -2643,15 +2643,15 @@ class TestQuopri(unittest.TestCase):
|
|||
|
||||
def test_header_quopri_check(self):
|
||||
for c in self.hlit:
|
||||
self.failIf(quoprimime.header_quopri_check(c))
|
||||
self.assertFalse(quoprimime.header_quopri_check(c))
|
||||
for c in self.hnon:
|
||||
self.failUnless(quoprimime.header_quopri_check(c))
|
||||
self.assertTrue(quoprimime.header_quopri_check(c))
|
||||
|
||||
def test_body_quopri_check(self):
|
||||
for c in self.blit:
|
||||
self.failIf(quoprimime.body_quopri_check(c))
|
||||
self.assertFalse(quoprimime.body_quopri_check(c))
|
||||
for c in self.bnon:
|
||||
self.failUnless(quoprimime.body_quopri_check(c))
|
||||
self.assertTrue(quoprimime.body_quopri_check(c))
|
||||
|
||||
def test_header_quopri_len(self):
|
||||
eq = self.assertEqual
|
||||
|
@ -2820,7 +2820,7 @@ class TestHeader(TestEmailBase):
|
|||
h = Header("I am the very model of a modern Major-General; I've information vegetable, animal, and mineral; I know the kings of England, and I quote the fights historical from Marathon to Waterloo, in order categorical; I'm very well acquainted, too, with matters mathematical; I understand equations, both the simple and quadratical; about binomial theorem I'm teeming with a lot o' news, with many cheerful facts about the square of the hypotenuse.",
|
||||
maxlinelen=76)
|
||||
for l in h.encode(splitchars=' ').split('\n '):
|
||||
self.failUnless(len(l) <= 76)
|
||||
self.assertTrue(len(l) <= 76)
|
||||
|
||||
def test_multilingual(self):
|
||||
eq = self.ndiffAssertEqual
|
||||
|
@ -3050,7 +3050,7 @@ Content-Type: text/html; NAME*0=file____C__DOCUMENTS_20AND_20SETTINGS_FABIEN_LOC
|
|||
'''
|
||||
msg = email.message_from_string(m)
|
||||
param = msg.get_param('NAME')
|
||||
self.failIf(isinstance(param, tuple))
|
||||
self.assertFalse(isinstance(param, tuple))
|
||||
self.assertEqual(
|
||||
param,
|
||||
'file____C__DOCUMENTS_20AND_20SETTINGS_FABIEN_LOCAL_20SETTINGS_TEMP_nsmail.htm')
|
||||
|
@ -3203,7 +3203,7 @@ Content-Type: application/x-foo; name*0=\"Frank's\"; name*1=\" Document\"
|
|||
"""
|
||||
msg = email.message_from_string(m)
|
||||
param = msg.get_param('name')
|
||||
self.failIf(isinstance(param, tuple))
|
||||
self.assertFalse(isinstance(param, tuple))
|
||||
self.assertEqual(param, "Frank's Document")
|
||||
|
||||
def test_rfc2231_tick_attack_extended(self):
|
||||
|
@ -3227,7 +3227,7 @@ Content-Type: application/x-foo;
|
|||
"""
|
||||
msg = email.message_from_string(m)
|
||||
param = msg.get_param('name')
|
||||
self.failIf(isinstance(param, tuple))
|
||||
self.assertFalse(isinstance(param, tuple))
|
||||
self.assertEqual(param, "us-ascii'en-us'Frank's Document")
|
||||
|
||||
def test_rfc2231_no_extended_values(self):
|
||||
|
|
|
@ -8,12 +8,12 @@ from collections import OrderedDict
|
|||
class TestDecode(TestCase):
|
||||
def test_decimal(self):
|
||||
rval = json.loads('1.1', parse_float=decimal.Decimal)
|
||||
self.assert_(isinstance(rval, decimal.Decimal))
|
||||
self.assertTrue(isinstance(rval, decimal.Decimal))
|
||||
self.assertEquals(rval, decimal.Decimal('1.1'))
|
||||
|
||||
def test_float(self):
|
||||
rval = json.loads('1', parse_int=float)
|
||||
self.assert_(isinstance(rval, float))
|
||||
self.assertTrue(isinstance(rval, float))
|
||||
self.assertEquals(rval, 1.0)
|
||||
|
||||
def test_decoder_optimizations(self):
|
||||
|
|
|
@ -7,9 +7,9 @@ from json import encoder
|
|||
class TestSpeedups(TestCase):
|
||||
def test_scanstring(self):
|
||||
self.assertEquals(decoder.scanstring.__module__, "_json")
|
||||
self.assert_(decoder.scanstring is decoder.c_scanstring)
|
||||
self.assertTrue(decoder.scanstring is decoder.c_scanstring)
|
||||
|
||||
def test_encode_basestring_ascii(self):
|
||||
self.assertEquals(encoder.encode_basestring_ascii.__module__, "_json")
|
||||
self.assert_(encoder.encode_basestring_ascii is
|
||||
self.assertTrue(encoder.encode_basestring_ascii is
|
||||
encoder.c_encode_basestring_ascii)
|
||||
|
|
|
@ -19,18 +19,18 @@ class TextTest(unittest.TestCase):
|
|||
text = self.text
|
||||
|
||||
# pattern and index are obligatory arguments.
|
||||
self.failUnlessRaises(Tkinter.TclError, text.search, None, '1.0')
|
||||
self.failUnlessRaises(Tkinter.TclError, text.search, 'a', None)
|
||||
self.failUnlessRaises(Tkinter.TclError, text.search, None, None)
|
||||
self.assertRaises(Tkinter.TclError, text.search, None, '1.0')
|
||||
self.assertRaises(Tkinter.TclError, text.search, 'a', None)
|
||||
self.assertRaises(Tkinter.TclError, text.search, None, None)
|
||||
|
||||
# Invalid text index.
|
||||
self.failUnlessRaises(Tkinter.TclError, text.search, '', 0)
|
||||
self.assertRaises(Tkinter.TclError, text.search, '', 0)
|
||||
|
||||
# Check if we are getting the indices as strings -- you are likely
|
||||
# to get Tcl_Obj under Tk 8.5 if Tkinter doesn't convert it.
|
||||
text.insert('1.0', 'hi-test')
|
||||
self.failUnlessEqual(text.search('-test', '1.0', 'end'), '1.2')
|
||||
self.failUnlessEqual(text.search('test', '1.0', 'end'), '1.3')
|
||||
self.assertEqual(text.search('-test', '1.0', 'end'), '1.2')
|
||||
self.assertEqual(text.search('test', '1.0', 'end'), '1.3')
|
||||
|
||||
|
||||
tests_gui = (TextTest, )
|
||||
|
|
|
@ -22,16 +22,16 @@ class LabeledScaleTest(unittest.TestCase):
|
|||
x = ttk.LabeledScale()
|
||||
var = x._variable._name
|
||||
x.destroy()
|
||||
self.failUnlessRaises(Tkinter.TclError, x.tk.globalgetvar, var)
|
||||
self.assertRaises(Tkinter.TclError, x.tk.globalgetvar, var)
|
||||
|
||||
# manually created variable
|
||||
myvar = Tkinter.DoubleVar()
|
||||
name = myvar._name
|
||||
x = ttk.LabeledScale(variable=myvar)
|
||||
x.destroy()
|
||||
self.failUnlessEqual(x.tk.globalgetvar(name), myvar.get())
|
||||
self.assertEqual(x.tk.globalgetvar(name), myvar.get())
|
||||
del myvar
|
||||
self.failUnlessRaises(Tkinter.TclError, x.tk.globalgetvar, name)
|
||||
self.assertRaises(Tkinter.TclError, x.tk.globalgetvar, name)
|
||||
|
||||
# checking that the tracing callback is properly removed
|
||||
myvar = Tkinter.IntVar()
|
||||
|
@ -45,17 +45,17 @@ class LabeledScaleTest(unittest.TestCase):
|
|||
# it tries calling instance attributes not yet defined.
|
||||
ttk.LabeledScale(variable=myvar)
|
||||
if hasattr(sys, 'last_type'):
|
||||
self.failIf(sys.last_type == Tkinter.TclError)
|
||||
self.assertFalse(sys.last_type == Tkinter.TclError)
|
||||
|
||||
|
||||
def test_initialization(self):
|
||||
# master passing
|
||||
x = ttk.LabeledScale()
|
||||
self.failUnlessEqual(x.master, Tkinter._default_root)
|
||||
self.assertEqual(x.master, Tkinter._default_root)
|
||||
x.destroy()
|
||||
master = Tkinter.Frame()
|
||||
x = ttk.LabeledScale(master)
|
||||
self.failUnlessEqual(x.master, master)
|
||||
self.assertEqual(x.master, master)
|
||||
x.destroy()
|
||||
|
||||
# variable initialization/passing
|
||||
|
@ -63,29 +63,29 @@ class LabeledScaleTest(unittest.TestCase):
|
|||
(-1, -1), (sys.maxint + 1, sys.maxint + 1))
|
||||
for pair in passed_expected:
|
||||
x = ttk.LabeledScale(from_=pair[0])
|
||||
self.failUnlessEqual(x.value, pair[1])
|
||||
self.assertEqual(x.value, pair[1])
|
||||
x.destroy()
|
||||
x = ttk.LabeledScale(from_='2.5')
|
||||
self.failUnlessRaises(ValueError, x._variable.get)
|
||||
self.assertRaises(ValueError, x._variable.get)
|
||||
x.destroy()
|
||||
x = ttk.LabeledScale(from_=None)
|
||||
self.failUnlessRaises(ValueError, x._variable.get)
|
||||
self.assertRaises(ValueError, x._variable.get)
|
||||
x.destroy()
|
||||
# variable should have its default value set to the from_ value
|
||||
myvar = Tkinter.DoubleVar(value=20)
|
||||
x = ttk.LabeledScale(variable=myvar)
|
||||
self.failUnlessEqual(x.value, 0)
|
||||
self.assertEqual(x.value, 0)
|
||||
x.destroy()
|
||||
# check that it is really using a DoubleVar
|
||||
x = ttk.LabeledScale(variable=myvar, from_=0.5)
|
||||
self.failUnlessEqual(x.value, 0.5)
|
||||
self.failUnlessEqual(x._variable._name, myvar._name)
|
||||
self.assertEqual(x.value, 0.5)
|
||||
self.assertEqual(x._variable._name, myvar._name)
|
||||
x.destroy()
|
||||
|
||||
# widget positionment
|
||||
def check_positions(scale, scale_pos, label, label_pos):
|
||||
self.failUnlessEqual(scale.pack_info()['side'], scale_pos)
|
||||
self.failUnlessEqual(label.place_info()['anchor'], label_pos)
|
||||
self.assertEqual(scale.pack_info()['side'], scale_pos)
|
||||
self.assertEqual(label.place_info()['anchor'], label_pos)
|
||||
x = ttk.LabeledScale(compound='top')
|
||||
check_positions(x.scale, 'bottom', x.label, 'n')
|
||||
x.destroy()
|
||||
|
@ -100,7 +100,7 @@ class LabeledScaleTest(unittest.TestCase):
|
|||
x.destroy()
|
||||
|
||||
# extra, and invalid, kwargs
|
||||
self.failUnlessRaises(Tkinter.TclError, ttk.LabeledScale, a='b')
|
||||
self.assertRaises(Tkinter.TclError, ttk.LabeledScale, a='b')
|
||||
|
||||
|
||||
def test_horizontal_range(self):
|
||||
|
@ -111,7 +111,7 @@ class LabeledScaleTest(unittest.TestCase):
|
|||
|
||||
linfo_1 = lscale.label.place_info()
|
||||
prev_xcoord = lscale.scale.coords()[0]
|
||||
self.failUnlessEqual(prev_xcoord, int(linfo_1['x']))
|
||||
self.assertEqual(prev_xcoord, int(linfo_1['x']))
|
||||
# change range to: from -5 to 5. This should change the x coord of
|
||||
# the scale widget, since 0 is at the middle of the new
|
||||
# range.
|
||||
|
@ -120,15 +120,15 @@ class LabeledScaleTest(unittest.TestCase):
|
|||
# at the same time this shouldn't affect test outcome
|
||||
lscale.update()
|
||||
curr_xcoord = lscale.scale.coords()[0]
|
||||
self.failUnless(prev_xcoord != curr_xcoord)
|
||||
self.assertTrue(prev_xcoord != curr_xcoord)
|
||||
# the label widget should have been repositioned too
|
||||
linfo_2 = lscale.label.place_info()
|
||||
self.failUnlessEqual(lscale.label['text'], 0)
|
||||
self.failUnlessEqual(curr_xcoord, int(linfo_2['x']))
|
||||
self.assertEqual(lscale.label['text'], 0)
|
||||
self.assertEqual(curr_xcoord, int(linfo_2['x']))
|
||||
# change the range back
|
||||
lscale.scale.configure(from_=0, to=10)
|
||||
self.failUnless(prev_xcoord != curr_xcoord)
|
||||
self.failUnlessEqual(prev_xcoord, int(linfo_1['x']))
|
||||
self.assertTrue(prev_xcoord != curr_xcoord)
|
||||
self.assertEqual(prev_xcoord, int(linfo_1['x']))
|
||||
|
||||
lscale.destroy()
|
||||
|
||||
|
@ -145,16 +145,16 @@ class LabeledScaleTest(unittest.TestCase):
|
|||
# The following update is needed since the test doesn't use mainloop,
|
||||
# at the same time this shouldn't affect test outcome
|
||||
x.update()
|
||||
self.failUnlessEqual(x.label['text'], newval)
|
||||
self.failUnless(x.scale.coords()[0] > curr_xcoord)
|
||||
self.failUnlessEqual(x.scale.coords()[0],
|
||||
self.assertEqual(x.label['text'], newval)
|
||||
self.assertTrue(x.scale.coords()[0] > curr_xcoord)
|
||||
self.assertEqual(x.scale.coords()[0],
|
||||
int(x.label.place_info()['x']))
|
||||
|
||||
# value outside range
|
||||
x.value = x.scale['to'] + 1 # no changes shouldn't happen
|
||||
x.update()
|
||||
self.failUnlessEqual(x.label['text'], newval)
|
||||
self.failUnlessEqual(x.scale.coords()[0],
|
||||
self.assertEqual(x.label['text'], newval)
|
||||
self.assertEqual(x.scale.coords()[0],
|
||||
int(x.label.place_info()['x']))
|
||||
|
||||
x.destroy()
|
||||
|
@ -172,7 +172,7 @@ class LabeledScaleTest(unittest.TestCase):
|
|||
x.value = 3
|
||||
x.update()
|
||||
x.master.wm_geometry("%dx%d" % (width_new, height_new))
|
||||
self.failUnlessEqual(int(x.label.place_info()['x']),
|
||||
self.assertEqual(int(x.label.place_info()['x']),
|
||||
x.scale.coords()[0])
|
||||
|
||||
# Reset geometry
|
||||
|
@ -197,20 +197,20 @@ class OptionMenuTest(unittest.TestCase):
|
|||
name = var._name
|
||||
optmenu.update_idletasks()
|
||||
optmenu.destroy()
|
||||
self.failUnlessEqual(optmenu.tk.globalgetvar(name), var.get())
|
||||
self.assertEqual(optmenu.tk.globalgetvar(name), var.get())
|
||||
del var
|
||||
self.failUnlessRaises(Tkinter.TclError, optmenu.tk.globalgetvar, name)
|
||||
self.assertRaises(Tkinter.TclError, optmenu.tk.globalgetvar, name)
|
||||
|
||||
|
||||
def test_initialization(self):
|
||||
self.failUnlessRaises(Tkinter.TclError,
|
||||
self.assertRaises(Tkinter.TclError,
|
||||
ttk.OptionMenu, None, self.textvar, invalid='thing')
|
||||
|
||||
optmenu = ttk.OptionMenu(None, self.textvar, 'b', 'a', 'b')
|
||||
self.failUnlessEqual(optmenu._variable.get(), 'b')
|
||||
self.assertEqual(optmenu._variable.get(), 'b')
|
||||
|
||||
self.failUnless(optmenu['menu'])
|
||||
self.failUnless(optmenu['textvariable'])
|
||||
self.assertTrue(optmenu['menu'])
|
||||
self.assertTrue(optmenu['textvariable'])
|
||||
|
||||
optmenu.destroy()
|
||||
|
||||
|
@ -222,10 +222,10 @@ class OptionMenuTest(unittest.TestCase):
|
|||
found_default = False
|
||||
for i in range(len(items)):
|
||||
value = optmenu['menu'].entrycget(i, 'value')
|
||||
self.failUnlessEqual(value, items[i])
|
||||
self.assertEqual(value, items[i])
|
||||
if value == default:
|
||||
found_default = True
|
||||
self.failUnless(found_default)
|
||||
self.assertTrue(found_default)
|
||||
optmenu.destroy()
|
||||
|
||||
# default shouldn't be in menu if it is not part of values
|
||||
|
@ -238,26 +238,26 @@ class OptionMenuTest(unittest.TestCase):
|
|||
if last == curr:
|
||||
# no more menu entries
|
||||
break
|
||||
self.failIf(curr == default)
|
||||
self.assertFalse(curr == default)
|
||||
i += 1
|
||||
self.failUnlessEqual(i, len(items))
|
||||
self.assertEqual(i, len(items))
|
||||
|
||||
# check that variable is updated correctly
|
||||
optmenu.pack()
|
||||
optmenu.wait_visibility()
|
||||
optmenu['menu'].invoke(0)
|
||||
self.failUnlessEqual(optmenu._variable.get(), items[0])
|
||||
self.assertEqual(optmenu._variable.get(), items[0])
|
||||
|
||||
# changing to an invalid index shouldn't change the variable
|
||||
self.failUnlessRaises(Tkinter.TclError, optmenu['menu'].invoke, -1)
|
||||
self.failUnlessEqual(optmenu._variable.get(), items[0])
|
||||
self.assertRaises(Tkinter.TclError, optmenu['menu'].invoke, -1)
|
||||
self.assertEqual(optmenu._variable.get(), items[0])
|
||||
|
||||
optmenu.destroy()
|
||||
|
||||
# specifying a callback
|
||||
success = []
|
||||
def cb_test(item):
|
||||
self.failUnlessEqual(item, items[1])
|
||||
self.assertEqual(item, items[1])
|
||||
success.append(True)
|
||||
optmenu = ttk.OptionMenu(None, self.textvar, 'a', command=cb_test,
|
||||
*items)
|
||||
|
|
|
@ -28,12 +28,12 @@ class InternalFunctionsTest(unittest.TestCase):
|
|||
def test_format_optdict(self):
|
||||
def check_against(fmt_opts, result):
|
||||
for i in range(0, len(fmt_opts), 2):
|
||||
self.failUnlessEqual(result.pop(fmt_opts[i]), fmt_opts[i + 1])
|
||||
self.assertEqual(result.pop(fmt_opts[i]), fmt_opts[i + 1])
|
||||
if result:
|
||||
self.fail("result still got elements: %s" % result)
|
||||
|
||||
# passing an empty dict should return an empty object (tuple here)
|
||||
self.failIf(ttk._format_optdict({}))
|
||||
self.assertFalse(ttk._format_optdict({}))
|
||||
|
||||
# check list formatting
|
||||
check_against(
|
||||
|
@ -63,7 +63,7 @@ class InternalFunctionsTest(unittest.TestCase):
|
|||
# check if giving unicode keys is fine
|
||||
check_against(ttk._format_optdict(opts), {u'-αβγ': True, u'-á': False})
|
||||
# opts should remain unchanged
|
||||
self.failUnlessEqual(opts, orig_opts)
|
||||
self.assertEqual(opts, orig_opts)
|
||||
|
||||
# passing values with spaces inside a tuple/list
|
||||
check_against(
|
||||
|
@ -73,113 +73,113 @@ class InternalFunctionsTest(unittest.TestCase):
|
|||
|
||||
# ignore an option
|
||||
amount_opts = len(ttk._format_optdict(opts, ignore=(u'á'))) / 2
|
||||
self.failUnlessEqual(amount_opts, len(opts) - 1)
|
||||
self.assertEqual(amount_opts, len(opts) - 1)
|
||||
|
||||
# ignore non-existing options
|
||||
amount_opts = len(ttk._format_optdict(opts, ignore=(u'á', 'b'))) / 2
|
||||
self.failUnlessEqual(amount_opts, len(opts) - 1)
|
||||
self.assertEqual(amount_opts, len(opts) - 1)
|
||||
|
||||
# ignore every option
|
||||
self.failIf(ttk._format_optdict(opts, ignore=opts.keys()))
|
||||
self.assertFalse(ttk._format_optdict(opts, ignore=opts.keys()))
|
||||
|
||||
|
||||
def test_format_mapdict(self):
|
||||
opts = {'a': [('b', 'c', 'val'), ('d', 'otherval'), ('', 'single')]}
|
||||
result = ttk._format_mapdict(opts)
|
||||
self.failUnlessEqual(len(result), len(opts.keys()) * 2)
|
||||
self.failUnlessEqual(result, ('-a', '{b c} val d otherval {} single'))
|
||||
self.failUnlessEqual(ttk._format_mapdict(opts, script=True),
|
||||
self.assertEqual(len(result), len(opts.keys()) * 2)
|
||||
self.assertEqual(result, ('-a', '{b c} val d otherval {} single'))
|
||||
self.assertEqual(ttk._format_mapdict(opts, script=True),
|
||||
('-a', '{{b c} val d otherval {} single}'))
|
||||
|
||||
self.failUnlessEqual(ttk._format_mapdict({2: []}), ('-2', ''))
|
||||
self.assertEqual(ttk._format_mapdict({2: []}), ('-2', ''))
|
||||
|
||||
opts = {u'üñíćódè': [(u'á', u'vãl')]}
|
||||
result = ttk._format_mapdict(opts)
|
||||
self.failUnlessEqual(result, (u'-üñíćódè', u'á vãl'))
|
||||
self.assertEqual(result, (u'-üñíćódè', u'á vãl'))
|
||||
|
||||
# empty states
|
||||
valid = {'opt': [('', u'', 'hi')]}
|
||||
self.failUnlessEqual(ttk._format_mapdict(valid), ('-opt', '{ } hi'))
|
||||
self.assertEqual(ttk._format_mapdict(valid), ('-opt', '{ } hi'))
|
||||
|
||||
# when passing multiple states, they all must be strings
|
||||
invalid = {'opt': [(1, 2, 'valid val')]}
|
||||
self.failUnlessRaises(TypeError, ttk._format_mapdict, invalid)
|
||||
self.assertRaises(TypeError, ttk._format_mapdict, invalid)
|
||||
invalid = {'opt': [([1], '2', 'valid val')]}
|
||||
self.failUnlessRaises(TypeError, ttk._format_mapdict, invalid)
|
||||
self.assertRaises(TypeError, ttk._format_mapdict, invalid)
|
||||
# but when passing a single state, it can be anything
|
||||
valid = {'opt': [[1, 'value']]}
|
||||
self.failUnlessEqual(ttk._format_mapdict(valid), ('-opt', '1 value'))
|
||||
self.assertEqual(ttk._format_mapdict(valid), ('-opt', '1 value'))
|
||||
# special attention to single states which evalute to False
|
||||
for stateval in (None, 0, False, '', set()): # just some samples
|
||||
valid = {'opt': [(stateval, 'value')]}
|
||||
self.failUnlessEqual(ttk._format_mapdict(valid),
|
||||
self.assertEqual(ttk._format_mapdict(valid),
|
||||
('-opt', '{} value'))
|
||||
|
||||
# values must be iterable
|
||||
opts = {'a': None}
|
||||
self.failUnlessRaises(TypeError, ttk._format_mapdict, opts)
|
||||
self.assertRaises(TypeError, ttk._format_mapdict, opts)
|
||||
|
||||
# items in the value must have size >= 2
|
||||
self.failUnlessRaises(IndexError, ttk._format_mapdict,
|
||||
self.assertRaises(IndexError, ttk._format_mapdict,
|
||||
{'a': [('invalid', )]})
|
||||
|
||||
|
||||
def test_format_elemcreate(self):
|
||||
self.failUnless(ttk._format_elemcreate(None), (None, ()))
|
||||
self.assertTrue(ttk._format_elemcreate(None), (None, ()))
|
||||
|
||||
## Testing type = image
|
||||
# image type expects at least an image name, so this should raise
|
||||
# IndexError since it tries to access the index 0 of an empty tuple
|
||||
self.failUnlessRaises(IndexError, ttk._format_elemcreate, 'image')
|
||||
self.assertRaises(IndexError, ttk._format_elemcreate, 'image')
|
||||
|
||||
# don't format returned values as a tcl script
|
||||
# minimum acceptable for image type
|
||||
self.failUnlessEqual(ttk._format_elemcreate('image', False, 'test'),
|
||||
self.assertEqual(ttk._format_elemcreate('image', False, 'test'),
|
||||
("test ", ()))
|
||||
# specifiyng a state spec
|
||||
self.failUnlessEqual(ttk._format_elemcreate('image', False, 'test',
|
||||
self.assertEqual(ttk._format_elemcreate('image', False, 'test',
|
||||
('', 'a')), ("test {} a", ()))
|
||||
# state spec with multiple states
|
||||
self.failUnlessEqual(ttk._format_elemcreate('image', False, 'test',
|
||||
self.assertEqual(ttk._format_elemcreate('image', False, 'test',
|
||||
('a', 'b', 'c')), ("test {a b} c", ()))
|
||||
# state spec and options
|
||||
self.failUnlessEqual(ttk._format_elemcreate('image', False, 'test',
|
||||
self.assertEqual(ttk._format_elemcreate('image', False, 'test',
|
||||
('a', 'b'), a='x', b='y'), ("test a b", ("-a", "x", "-b", "y")))
|
||||
# format returned values as a tcl script
|
||||
# state spec with multiple states and an option with a multivalue
|
||||
self.failUnlessEqual(ttk._format_elemcreate('image', True, 'test',
|
||||
self.assertEqual(ttk._format_elemcreate('image', True, 'test',
|
||||
('a', 'b', 'c', 'd'), x=[2, 3]), ("{test {a b c} d}", "-x {2 3}"))
|
||||
|
||||
## Testing type = vsapi
|
||||
# vsapi type expects at least a class name and a part_id, so this
|
||||
# should raise an ValueError since it tries to get two elements from
|
||||
# an empty tuple
|
||||
self.failUnlessRaises(ValueError, ttk._format_elemcreate, 'vsapi')
|
||||
self.assertRaises(ValueError, ttk._format_elemcreate, 'vsapi')
|
||||
|
||||
# don't format returned values as a tcl script
|
||||
# minimum acceptable for vsapi
|
||||
self.failUnlessEqual(ttk._format_elemcreate('vsapi', False, 'a', 'b'),
|
||||
self.assertEqual(ttk._format_elemcreate('vsapi', False, 'a', 'b'),
|
||||
("a b ", ()))
|
||||
# now with a state spec with multiple states
|
||||
self.failUnlessEqual(ttk._format_elemcreate('vsapi', False, 'a', 'b',
|
||||
self.assertEqual(ttk._format_elemcreate('vsapi', False, 'a', 'b',
|
||||
('a', 'b', 'c')), ("a b {a b} c", ()))
|
||||
# state spec and option
|
||||
self.failUnlessEqual(ttk._format_elemcreate('vsapi', False, 'a', 'b',
|
||||
self.assertEqual(ttk._format_elemcreate('vsapi', False, 'a', 'b',
|
||||
('a', 'b'), opt='x'), ("a b a b", ("-opt", "x")))
|
||||
# format returned values as a tcl script
|
||||
# state spec with a multivalue and an option
|
||||
self.failUnlessEqual(ttk._format_elemcreate('vsapi', True, 'a', 'b',
|
||||
self.assertEqual(ttk._format_elemcreate('vsapi', True, 'a', 'b',
|
||||
('a', 'b', [1, 2]), opt='x'), ("{a b {a b} {1 2}}", "-opt x"))
|
||||
|
||||
# Testing type = from
|
||||
# from type expects at least a type name
|
||||
self.failUnlessRaises(IndexError, ttk._format_elemcreate, 'from')
|
||||
self.assertRaises(IndexError, ttk._format_elemcreate, 'from')
|
||||
|
||||
self.failUnlessEqual(ttk._format_elemcreate('from', False, 'a'),
|
||||
self.assertEqual(ttk._format_elemcreate('from', False, 'a'),
|
||||
('a', ()))
|
||||
self.failUnlessEqual(ttk._format_elemcreate('from', False, 'a', 'b'),
|
||||
self.assertEqual(ttk._format_elemcreate('from', False, 'a', 'b'),
|
||||
('a', ('b', )))
|
||||
self.failUnlessEqual(ttk._format_elemcreate('from', True, 'a', 'b'),
|
||||
self.assertEqual(ttk._format_elemcreate('from', True, 'a', 'b'),
|
||||
('{a}', 'b'))
|
||||
|
||||
|
||||
|
@ -208,75 +208,75 @@ class InternalFunctionsTest(unittest.TestCase):
|
|||
spaces(2 * indent_size), spaces(indent_size), spaces()))
|
||||
|
||||
# empty layout
|
||||
self.failUnlessEqual(ttk._format_layoutlist([])[0], '')
|
||||
self.assertEqual(ttk._format_layoutlist([])[0], '')
|
||||
|
||||
# smallest (after an empty one) acceptable layout
|
||||
smallest = ttk._format_layoutlist([('a', None)], indent=0)
|
||||
self.failUnlessEqual(smallest,
|
||||
self.assertEqual(smallest,
|
||||
ttk._format_layoutlist([('a', '')], indent=0))
|
||||
self.failUnlessEqual(smallest[0], 'a')
|
||||
self.assertEqual(smallest[0], 'a')
|
||||
|
||||
# testing indentation levels
|
||||
self.failUnlessEqual(sample(), sample_expected())
|
||||
self.assertEqual(sample(), sample_expected())
|
||||
for i in range(4):
|
||||
self.failUnlessEqual(sample(i), sample_expected(i))
|
||||
self.failUnlessEqual(sample(i, i), sample_expected(i, i))
|
||||
self.assertEqual(sample(i), sample_expected(i))
|
||||
self.assertEqual(sample(i, i), sample_expected(i, i))
|
||||
|
||||
# invalid layout format, different kind of exceptions will be
|
||||
# raised
|
||||
|
||||
# plain wrong format
|
||||
self.failUnlessRaises(ValueError, ttk._format_layoutlist,
|
||||
self.assertRaises(ValueError, ttk._format_layoutlist,
|
||||
['bad', 'format'])
|
||||
self.failUnlessRaises(TypeError, ttk._format_layoutlist, None)
|
||||
self.assertRaises(TypeError, ttk._format_layoutlist, None)
|
||||
# _format_layoutlist always expects the second item (in every item)
|
||||
# to act like a dict (except when the value evalutes to False).
|
||||
self.failUnlessRaises(AttributeError,
|
||||
self.assertRaises(AttributeError,
|
||||
ttk._format_layoutlist, [('a', 'b')])
|
||||
# bad children formatting
|
||||
self.failUnlessRaises(ValueError, ttk._format_layoutlist,
|
||||
self.assertRaises(ValueError, ttk._format_layoutlist,
|
||||
[('name', {'children': {'a': None}})])
|
||||
|
||||
|
||||
def test_script_from_settings(self):
|
||||
# empty options
|
||||
self.failIf(ttk._script_from_settings({'name':
|
||||
self.assertFalse(ttk._script_from_settings({'name':
|
||||
{'configure': None, 'map': None, 'element create': None}}))
|
||||
|
||||
# empty layout
|
||||
self.failUnlessEqual(
|
||||
self.assertEqual(
|
||||
ttk._script_from_settings({'name': {'layout': None}}),
|
||||
"ttk::style layout name {\nnull\n}")
|
||||
|
||||
configdict = {u'αβγ': True, u'á': False}
|
||||
self.failUnless(
|
||||
self.assertTrue(
|
||||
ttk._script_from_settings({'name': {'configure': configdict}}))
|
||||
|
||||
mapdict = {u'üñíćódè': [(u'á', u'vãl')]}
|
||||
self.failUnless(
|
||||
self.assertTrue(
|
||||
ttk._script_from_settings({'name': {'map': mapdict}}))
|
||||
|
||||
# invalid image element
|
||||
self.failUnlessRaises(IndexError,
|
||||
self.assertRaises(IndexError,
|
||||
ttk._script_from_settings, {'name': {'element create': ['image']}})
|
||||
|
||||
# minimal valid image
|
||||
self.failUnless(ttk._script_from_settings({'name':
|
||||
self.assertTrue(ttk._script_from_settings({'name':
|
||||
{'element create': ['image', 'name']}}))
|
||||
|
||||
image = {'thing': {'element create':
|
||||
['image', 'name', ('state1', 'state2', 'val')]}}
|
||||
self.failUnlessEqual(ttk._script_from_settings(image),
|
||||
self.assertEqual(ttk._script_from_settings(image),
|
||||
"ttk::style element create thing image {name {state1 state2} val} ")
|
||||
|
||||
image['thing']['element create'].append({'opt': 30})
|
||||
self.failUnlessEqual(ttk._script_from_settings(image),
|
||||
self.assertEqual(ttk._script_from_settings(image),
|
||||
"ttk::style element create thing image {name {state1 state2} val} "
|
||||
"-opt 30")
|
||||
|
||||
image['thing']['element create'][-1]['opt'] = [MockTclObj(3),
|
||||
MockTclObj('2m')]
|
||||
self.failUnlessEqual(ttk._script_from_settings(image),
|
||||
self.assertEqual(ttk._script_from_settings(image),
|
||||
"ttk::style element create thing image {name {state1 state2} val} "
|
||||
"-opt {3 2m}")
|
||||
|
||||
|
@ -284,28 +284,28 @@ class InternalFunctionsTest(unittest.TestCase):
|
|||
def test_dict_from_tcltuple(self):
|
||||
fakettuple = ('-a', '{1 2 3}', '-something', 'foo')
|
||||
|
||||
self.failUnlessEqual(ttk._dict_from_tcltuple(fakettuple, False),
|
||||
self.assertEqual(ttk._dict_from_tcltuple(fakettuple, False),
|
||||
{'-a': '{1 2 3}', '-something': 'foo'})
|
||||
|
||||
self.failUnlessEqual(ttk._dict_from_tcltuple(fakettuple),
|
||||
self.assertEqual(ttk._dict_from_tcltuple(fakettuple),
|
||||
{'a': '{1 2 3}', 'something': 'foo'})
|
||||
|
||||
# passing a tuple with a single item should return an empty dict,
|
||||
# since it tries to break the tuple by pairs.
|
||||
self.failIf(ttk._dict_from_tcltuple(('single', )))
|
||||
self.assertFalse(ttk._dict_from_tcltuple(('single', )))
|
||||
|
||||
sspec = MockStateSpec('a', 'b')
|
||||
self.failUnlessEqual(ttk._dict_from_tcltuple(('-a', (sspec, 'val'))),
|
||||
self.assertEqual(ttk._dict_from_tcltuple(('-a', (sspec, 'val'))),
|
||||
{'a': [('a', 'b', 'val')]})
|
||||
|
||||
self.failUnlessEqual(ttk._dict_from_tcltuple((MockTclObj('-padding'),
|
||||
self.assertEqual(ttk._dict_from_tcltuple((MockTclObj('-padding'),
|
||||
[MockTclObj('1'), 2, MockTclObj('3m')])),
|
||||
{'padding': [1, 2, '3m']})
|
||||
|
||||
|
||||
def test_list_from_statespec(self):
|
||||
def test_it(sspec, value, res_value, states):
|
||||
self.failUnlessEqual(ttk._list_from_statespec(
|
||||
self.assertEqual(ttk._list_from_statespec(
|
||||
(sspec, value)), [states + (res_value, )])
|
||||
|
||||
states_even = tuple('state%d' % i for i in range(6))
|
||||
|
@ -322,19 +322,19 @@ class InternalFunctionsTest(unittest.TestCase):
|
|||
|
||||
def test_list_from_layouttuple(self):
|
||||
# empty layout tuple
|
||||
self.failIf(ttk._list_from_layouttuple(()))
|
||||
self.assertFalse(ttk._list_from_layouttuple(()))
|
||||
|
||||
# shortest layout tuple
|
||||
self.failUnlessEqual(ttk._list_from_layouttuple(('name', )),
|
||||
self.assertEqual(ttk._list_from_layouttuple(('name', )),
|
||||
[('name', {})])
|
||||
|
||||
# not so interesting ltuple
|
||||
sample_ltuple = ('name', '-option', 'value')
|
||||
self.failUnlessEqual(ttk._list_from_layouttuple(sample_ltuple),
|
||||
self.assertEqual(ttk._list_from_layouttuple(sample_ltuple),
|
||||
[('name', {'option': 'value'})])
|
||||
|
||||
# empty children
|
||||
self.failUnlessEqual(ttk._list_from_layouttuple(
|
||||
self.assertEqual(ttk._list_from_layouttuple(
|
||||
('something', '-children', ())),
|
||||
[('something', {'children': []})]
|
||||
)
|
||||
|
@ -347,7 +347,7 @@ class InternalFunctionsTest(unittest.TestCase):
|
|||
)
|
||||
)
|
||||
)
|
||||
self.failUnlessEqual(ttk._list_from_layouttuple(ltuple),
|
||||
self.assertEqual(ttk._list_from_layouttuple(ltuple),
|
||||
[('name', {'option': 'niceone', 'children':
|
||||
[('otherone', {'otheropt': 'othervalue', 'children':
|
||||
[('child', {})]
|
||||
|
@ -356,13 +356,13 @@ class InternalFunctionsTest(unittest.TestCase):
|
|||
)
|
||||
|
||||
# bad tuples
|
||||
self.failUnlessRaises(ValueError, ttk._list_from_layouttuple,
|
||||
self.assertRaises(ValueError, ttk._list_from_layouttuple,
|
||||
('name', 'no_minus'))
|
||||
self.failUnlessRaises(ValueError, ttk._list_from_layouttuple,
|
||||
self.assertRaises(ValueError, ttk._list_from_layouttuple,
|
||||
('name', 'no_minus', 'value'))
|
||||
self.failUnlessRaises(ValueError, ttk._list_from_layouttuple,
|
||||
self.assertRaises(ValueError, ttk._list_from_layouttuple,
|
||||
('something', '-children')) # no children
|
||||
self.failUnlessRaises(ValueError, ttk._list_from_layouttuple,
|
||||
self.assertRaises(ValueError, ttk._list_from_layouttuple,
|
||||
('something', '-children', 'value')) # invalid children
|
||||
|
||||
|
||||
|
@ -373,10 +373,10 @@ class InternalFunctionsTest(unittest.TestCase):
|
|||
return (opt, val)
|
||||
|
||||
options = {'test': None}
|
||||
self.failUnlessEqual(ttk._val_or_dict(options, func), "test val")
|
||||
self.assertEqual(ttk._val_or_dict(options, func), "test val")
|
||||
|
||||
options = {'test': 3}
|
||||
self.failUnlessEqual(ttk._val_or_dict(options, func), options)
|
||||
self.assertEqual(ttk._val_or_dict(options, func), options)
|
||||
|
||||
|
||||
def test_convert_stringval(self):
|
||||
|
@ -385,10 +385,10 @@ class InternalFunctionsTest(unittest.TestCase):
|
|||
(None, 'None')
|
||||
)
|
||||
for orig, expected in tests:
|
||||
self.failUnlessEqual(ttk._convert_stringval(orig), expected)
|
||||
self.assertEqual(ttk._convert_stringval(orig), expected)
|
||||
|
||||
if sys.getdefaultencoding() == 'ascii':
|
||||
self.failUnlessRaises(UnicodeDecodeError,
|
||||
self.assertRaises(UnicodeDecodeError,
|
||||
ttk._convert_stringval, 'á')
|
||||
|
||||
|
||||
|
@ -396,27 +396,27 @@ class TclObjsToPyTest(unittest.TestCase):
|
|||
|
||||
def test_unicode(self):
|
||||
adict = {'opt': u'välúè'}
|
||||
self.failUnlessEqual(ttk.tclobjs_to_py(adict), {'opt': u'välúè'})
|
||||
self.assertEqual(ttk.tclobjs_to_py(adict), {'opt': u'välúè'})
|
||||
|
||||
adict['opt'] = MockTclObj(adict['opt'])
|
||||
self.failUnlessEqual(ttk.tclobjs_to_py(adict), {'opt': u'välúè'})
|
||||
self.assertEqual(ttk.tclobjs_to_py(adict), {'opt': u'välúè'})
|
||||
|
||||
def test_multivalues(self):
|
||||
adict = {'opt': [1, 2, 3, 4]}
|
||||
self.failUnlessEqual(ttk.tclobjs_to_py(adict), {'opt': [1, 2, 3, 4]})
|
||||
self.assertEqual(ttk.tclobjs_to_py(adict), {'opt': [1, 2, 3, 4]})
|
||||
|
||||
adict['opt'] = [1, 'xm', 3]
|
||||
self.failUnlessEqual(ttk.tclobjs_to_py(adict), {'opt': [1, 'xm', 3]})
|
||||
self.assertEqual(ttk.tclobjs_to_py(adict), {'opt': [1, 'xm', 3]})
|
||||
|
||||
adict['opt'] = (MockStateSpec('a', 'b'), u'válũè')
|
||||
self.failUnlessEqual(ttk.tclobjs_to_py(adict),
|
||||
self.assertEqual(ttk.tclobjs_to_py(adict),
|
||||
{'opt': [('a', 'b', u'válũè')]})
|
||||
|
||||
self.failUnlessEqual(ttk.tclobjs_to_py({'x': ['y z']}),
|
||||
self.assertEqual(ttk.tclobjs_to_py({'x': ['y z']}),
|
||||
{'x': ['y z']})
|
||||
|
||||
def test_nosplit(self):
|
||||
self.failUnlessEqual(ttk.tclobjs_to_py({'text': 'some text'}),
|
||||
self.assertEqual(ttk.tclobjs_to_py({'text': 'some text'}),
|
||||
{'text': 'some text'})
|
||||
|
||||
tests_nogui = (InternalFunctionsTest, TclObjsToPyTest)
|
||||
|
|
|
@ -16,17 +16,17 @@ class StyleTest(unittest.TestCase):
|
|||
def test_configure(self):
|
||||
style = self.style
|
||||
style.configure('TButton', background='yellow')
|
||||
self.failUnlessEqual(style.configure('TButton', 'background'),
|
||||
self.assertEqual(style.configure('TButton', 'background'),
|
||||
'yellow')
|
||||
self.failUnless(isinstance(style.configure('TButton'), dict))
|
||||
self.assertTrue(isinstance(style.configure('TButton'), dict))
|
||||
|
||||
|
||||
def test_map(self):
|
||||
style = self.style
|
||||
style.map('TButton', background=[('active', 'background', 'blue')])
|
||||
self.failUnlessEqual(style.map('TButton', 'background'),
|
||||
self.assertEqual(style.map('TButton', 'background'),
|
||||
[('active', 'background', 'blue')])
|
||||
self.failUnless(isinstance(style.map('TButton'), dict))
|
||||
self.assertTrue(isinstance(style.map('TButton'), dict))
|
||||
|
||||
|
||||
def test_lookup(self):
|
||||
|
@ -34,38 +34,38 @@ class StyleTest(unittest.TestCase):
|
|||
style.configure('TButton', background='yellow')
|
||||
style.map('TButton', background=[('active', 'background', 'blue')])
|
||||
|
||||
self.failUnlessEqual(style.lookup('TButton', 'background'), 'yellow')
|
||||
self.failUnlessEqual(style.lookup('TButton', 'background',
|
||||
self.assertEqual(style.lookup('TButton', 'background'), 'yellow')
|
||||
self.assertEqual(style.lookup('TButton', 'background',
|
||||
['active', 'background']), 'blue')
|
||||
self.failUnlessEqual(style.lookup('TButton', 'optionnotdefined',
|
||||
self.assertEqual(style.lookup('TButton', 'optionnotdefined',
|
||||
default='iknewit'), 'iknewit')
|
||||
|
||||
|
||||
def test_layout(self):
|
||||
style = self.style
|
||||
self.failUnlessRaises(Tkinter.TclError, style.layout, 'NotALayout')
|
||||
self.assertRaises(Tkinter.TclError, style.layout, 'NotALayout')
|
||||
tv_style = style.layout('Treeview')
|
||||
|
||||
# "erase" Treeview layout
|
||||
style.layout('Treeview', '')
|
||||
self.failUnlessEqual(style.layout('Treeview'),
|
||||
self.assertEqual(style.layout('Treeview'),
|
||||
[('null', {'sticky': 'nswe'})]
|
||||
)
|
||||
|
||||
# restore layout
|
||||
style.layout('Treeview', tv_style)
|
||||
self.failUnlessEqual(style.layout('Treeview'), tv_style)
|
||||
self.assertEqual(style.layout('Treeview'), tv_style)
|
||||
|
||||
# should return a list
|
||||
self.failUnless(isinstance(style.layout('TButton'), list))
|
||||
self.assertTrue(isinstance(style.layout('TButton'), list))
|
||||
|
||||
# correct layout, but "option" doesn't exist as option
|
||||
self.failUnlessRaises(Tkinter.TclError, style.layout, 'Treeview',
|
||||
self.assertRaises(Tkinter.TclError, style.layout, 'Treeview',
|
||||
[('name', {'option': 'inexistent'})])
|
||||
|
||||
|
||||
def test_theme_use(self):
|
||||
self.failUnlessRaises(Tkinter.TclError, self.style.theme_use,
|
||||
self.assertRaises(Tkinter.TclError, self.style.theme_use,
|
||||
'nonexistingname')
|
||||
|
||||
curr_theme = self.style.theme_use()
|
||||
|
@ -79,8 +79,8 @@ class StyleTest(unittest.TestCase):
|
|||
# just one theme available, can't go on with tests
|
||||
return
|
||||
|
||||
self.failIf(curr_theme == new_theme)
|
||||
self.failIf(new_theme != self.style.theme_use())
|
||||
self.assertFalse(curr_theme == new_theme)
|
||||
self.assertFalse(new_theme != self.style.theme_use())
|
||||
|
||||
self.style.theme_use(curr_theme)
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -50,17 +50,17 @@ class BasicTestMappingProtocol(unittest.TestCase):
|
|||
for key, value in self.reference.items():
|
||||
self.assertEqual(d[key], value)
|
||||
knownkey = self.other.keys()[0]
|
||||
self.failUnlessRaises(KeyError, lambda:d[knownkey])
|
||||
self.assertRaises(KeyError, lambda:d[knownkey])
|
||||
#len
|
||||
self.assertEqual(len(p), 0)
|
||||
self.assertEqual(len(d), len(self.reference))
|
||||
#has_key
|
||||
for k in self.reference:
|
||||
self.assert_(d.has_key(k))
|
||||
self.assert_(k in d)
|
||||
self.assertTrue(d.has_key(k))
|
||||
self.assertTrue(k in d)
|
||||
for k in self.other:
|
||||
self.failIf(d.has_key(k))
|
||||
self.failIf(k in d)
|
||||
self.assertFalse(d.has_key(k))
|
||||
self.assertFalse(k in d)
|
||||
#cmp
|
||||
self.assertEqual(cmp(p,p), 0)
|
||||
self.assertEqual(cmp(d,d), 0)
|
||||
|
@ -71,10 +71,10 @@ class BasicTestMappingProtocol(unittest.TestCase):
|
|||
if not d: self.fail("Full mapping must compare to True")
|
||||
# keys(), items(), iterkeys() ...
|
||||
def check_iterandlist(iter, lst, ref):
|
||||
self.assert_(hasattr(iter, 'next'))
|
||||
self.assert_(hasattr(iter, '__iter__'))
|
||||
self.assertTrue(hasattr(iter, 'next'))
|
||||
self.assertTrue(hasattr(iter, '__iter__'))
|
||||
x = list(iter)
|
||||
self.assert_(set(x)==set(lst)==set(ref))
|
||||
self.assertTrue(set(x)==set(lst)==set(ref))
|
||||
check_iterandlist(d.iterkeys(), d.keys(), self.reference.keys())
|
||||
check_iterandlist(iter(d), d.keys(), self.reference.keys())
|
||||
check_iterandlist(d.itervalues(), d.values(), self.reference.values())
|
||||
|
@ -84,7 +84,7 @@ class BasicTestMappingProtocol(unittest.TestCase):
|
|||
knownkey, knownvalue = self.other.iteritems().next()
|
||||
self.assertEqual(d.get(key, knownvalue), value)
|
||||
self.assertEqual(d.get(knownkey, knownvalue), knownvalue)
|
||||
self.failIf(knownkey in d)
|
||||
self.assertFalse(knownkey in d)
|
||||
|
||||
def test_write(self):
|
||||
# Test for write operations on mapping
|
||||
|
@ -95,7 +95,7 @@ class BasicTestMappingProtocol(unittest.TestCase):
|
|||
self.assertEqual(p[key], value)
|
||||
for key in self.reference.keys():
|
||||
del p[key]
|
||||
self.failUnlessRaises(KeyError, lambda:p[key])
|
||||
self.assertRaises(KeyError, lambda:p[key])
|
||||
p = self._empty_mapping()
|
||||
#update
|
||||
p.update(self.reference)
|
||||
|
@ -114,16 +114,16 @@ class BasicTestMappingProtocol(unittest.TestCase):
|
|||
self.assertEqual(d[knownkey], knownvalue)
|
||||
#pop
|
||||
self.assertEqual(d.pop(knownkey), knownvalue)
|
||||
self.failIf(knownkey in d)
|
||||
self.assertFalse(knownkey in d)
|
||||
self.assertRaises(KeyError, d.pop, knownkey)
|
||||
default = 909
|
||||
d[knownkey] = knownvalue
|
||||
self.assertEqual(d.pop(knownkey, default), knownvalue)
|
||||
self.failIf(knownkey in d)
|
||||
self.assertFalse(knownkey in d)
|
||||
self.assertEqual(d.pop(knownkey, default), default)
|
||||
#popitem
|
||||
key, value = d.popitem()
|
||||
self.failIf(key in d)
|
||||
self.assertFalse(key in d)
|
||||
self.assertEqual(value, self.reference[key])
|
||||
p=self._empty_mapping()
|
||||
self.assertRaises(KeyError, p.popitem)
|
||||
|
@ -132,17 +132,17 @@ class BasicTestMappingProtocol(unittest.TestCase):
|
|||
self.assertEqual(self._empty_mapping(), self._empty_mapping())
|
||||
|
||||
def test_bool(self):
|
||||
self.assert_(not self._empty_mapping())
|
||||
self.assert_(self.reference)
|
||||
self.assert_(bool(self._empty_mapping()) is False)
|
||||
self.assert_(bool(self.reference) is True)
|
||||
self.assertTrue(not self._empty_mapping())
|
||||
self.assertTrue(self.reference)
|
||||
self.assertTrue(bool(self._empty_mapping()) is False)
|
||||
self.assertTrue(bool(self.reference) is True)
|
||||
|
||||
def test_keys(self):
|
||||
d = self._empty_mapping()
|
||||
self.assertEqual(d.keys(), [])
|
||||
d = self.reference
|
||||
self.assert_(self.inmapping.keys()[0] in d.keys())
|
||||
self.assert_(self.other.keys()[0] not in d.keys())
|
||||
self.assertTrue(self.inmapping.keys()[0] in d.keys())
|
||||
self.assertTrue(self.other.keys()[0] not in d.keys())
|
||||
self.assertRaises(TypeError, d.keys, None)
|
||||
|
||||
def test_values(self):
|
||||
|
@ -268,10 +268,10 @@ class BasicTestMappingProtocol(unittest.TestCase):
|
|||
|
||||
def test_get(self):
|
||||
d = self._empty_mapping()
|
||||
self.assert_(d.get(self.other.keys()[0]) is None)
|
||||
self.assertTrue(d.get(self.other.keys()[0]) is None)
|
||||
self.assertEqual(d.get(self.other.keys()[0], 3), 3)
|
||||
d = self.reference
|
||||
self.assert_(d.get(self.other.keys()[0]) is None)
|
||||
self.assertTrue(d.get(self.other.keys()[0]) is None)
|
||||
self.assertEqual(d.get(self.other.keys()[0], 3), 3)
|
||||
self.assertEqual(d.get(self.inmapping.keys()[0]), self.inmapping.values()[0])
|
||||
self.assertEqual(d.get(self.inmapping.keys()[0], 3), self.inmapping.values()[0])
|
||||
|
@ -302,15 +302,15 @@ class BasicTestMappingProtocol(unittest.TestCase):
|
|||
class TestMappingProtocol(BasicTestMappingProtocol):
|
||||
def test_constructor(self):
|
||||
BasicTestMappingProtocol.test_constructor(self)
|
||||
self.assert_(self._empty_mapping() is not self._empty_mapping())
|
||||
self.assertTrue(self._empty_mapping() is not self._empty_mapping())
|
||||
self.assertEqual(self.type2test(x=1, y=2), {"x": 1, "y": 2})
|
||||
|
||||
def test_bool(self):
|
||||
BasicTestMappingProtocol.test_bool(self)
|
||||
self.assert_(not self._empty_mapping())
|
||||
self.assert_(self._full_mapping({"x": "y"}))
|
||||
self.assert_(bool(self._empty_mapping()) is False)
|
||||
self.assert_(bool(self._full_mapping({"x": "y"})) is True)
|
||||
self.assertTrue(not self._empty_mapping())
|
||||
self.assertTrue(self._full_mapping({"x": "y"}))
|
||||
self.assertTrue(bool(self._empty_mapping()) is False)
|
||||
self.assertTrue(bool(self._full_mapping({"x": "y"})) is True)
|
||||
|
||||
def test_keys(self):
|
||||
BasicTestMappingProtocol.test_keys(self)
|
||||
|
@ -318,9 +318,9 @@ class TestMappingProtocol(BasicTestMappingProtocol):
|
|||
self.assertEqual(d.keys(), [])
|
||||
d = self._full_mapping({'a': 1, 'b': 2})
|
||||
k = d.keys()
|
||||
self.assert_('a' in k)
|
||||
self.assert_('b' in k)
|
||||
self.assert_('c' not in k)
|
||||
self.assertTrue('a' in k)
|
||||
self.assertTrue('b' in k)
|
||||
self.assertTrue('c' not in k)
|
||||
|
||||
def test_values(self):
|
||||
BasicTestMappingProtocol.test_values(self)
|
||||
|
@ -335,7 +335,7 @@ class TestMappingProtocol(BasicTestMappingProtocol):
|
|||
|
||||
def test_has_key(self):
|
||||
d = self._empty_mapping()
|
||||
self.assert_(not d.has_key('a'))
|
||||
self.assertTrue(not d.has_key('a'))
|
||||
d = self._full_mapping({'a': 1, 'b': 2})
|
||||
k = d.keys()
|
||||
k.sort()
|
||||
|
@ -345,12 +345,12 @@ class TestMappingProtocol(BasicTestMappingProtocol):
|
|||
|
||||
def test_contains(self):
|
||||
d = self._empty_mapping()
|
||||
self.assert_(not ('a' in d))
|
||||
self.assert_('a' not in d)
|
||||
self.assertTrue(not ('a' in d))
|
||||
self.assertTrue('a' not in d)
|
||||
d = self._full_mapping({'a': 1, 'b': 2})
|
||||
self.assert_('a' in d)
|
||||
self.assert_('b' in d)
|
||||
self.assert_('c' not in d)
|
||||
self.assertTrue('a' in d)
|
||||
self.assertTrue('b' in d)
|
||||
self.assertTrue('c' not in d)
|
||||
|
||||
self.assertRaises(TypeError, d.__contains__)
|
||||
|
||||
|
@ -429,7 +429,7 @@ class TestMappingProtocol(BasicTestMappingProtocol):
|
|||
def test_fromkeys(self):
|
||||
self.assertEqual(self.type2test.fromkeys('abc'), {'a':None, 'b':None, 'c':None})
|
||||
d = self._empty_mapping()
|
||||
self.assert_(not(d.fromkeys('abc') is d))
|
||||
self.assertTrue(not(d.fromkeys('abc') is d))
|
||||
self.assertEqual(d.fromkeys('abc'), {'a':None, 'b':None, 'c':None})
|
||||
self.assertEqual(d.fromkeys((4,5),0), {4:0, 5:0})
|
||||
self.assertEqual(d.fromkeys([]), {})
|
||||
|
@ -440,17 +440,17 @@ class TestMappingProtocol(BasicTestMappingProtocol):
|
|||
class dictlike(self.type2test): pass
|
||||
self.assertEqual(dictlike.fromkeys('a'), {'a':None})
|
||||
self.assertEqual(dictlike().fromkeys('a'), {'a':None})
|
||||
self.assert_(dictlike.fromkeys('a').__class__ is dictlike)
|
||||
self.assert_(dictlike().fromkeys('a').__class__ is dictlike)
|
||||
self.assertTrue(dictlike.fromkeys('a').__class__ is dictlike)
|
||||
self.assertTrue(dictlike().fromkeys('a').__class__ is dictlike)
|
||||
# FIXME: the following won't work with UserDict, because it's an old style class
|
||||
# self.assert_(type(dictlike.fromkeys('a')) is dictlike)
|
||||
# self.assertTrue(type(dictlike.fromkeys('a')) is dictlike)
|
||||
class mydict(self.type2test):
|
||||
def __new__(cls):
|
||||
return UserDict.UserDict()
|
||||
ud = mydict.fromkeys('ab')
|
||||
self.assertEqual(ud, {'a':None, 'b':None})
|
||||
# FIXME: the following won't work with UserDict, because it's an old style class
|
||||
# self.assert_(isinstance(ud, UserDict.UserDict))
|
||||
# self.assertTrue(isinstance(ud, UserDict.UserDict))
|
||||
self.assertRaises(TypeError, dict.fromkeys)
|
||||
|
||||
class Exc(Exception): pass
|
||||
|
@ -480,16 +480,16 @@ class TestMappingProtocol(BasicTestMappingProtocol):
|
|||
self.assertEqual(d.copy(), {1:1, 2:2, 3:3})
|
||||
d = self._empty_mapping()
|
||||
self.assertEqual(d.copy(), d)
|
||||
self.assert_(isinstance(d.copy(), d.__class__))
|
||||
self.assertTrue(isinstance(d.copy(), d.__class__))
|
||||
self.assertRaises(TypeError, d.copy, None)
|
||||
|
||||
def test_get(self):
|
||||
BasicTestMappingProtocol.test_get(self)
|
||||
d = self._empty_mapping()
|
||||
self.assert_(d.get('c') is None)
|
||||
self.assertTrue(d.get('c') is None)
|
||||
self.assertEqual(d.get('c', 3), 3)
|
||||
d = self._full_mapping({'a' : 1, 'b' : 2})
|
||||
self.assert_(d.get('c') is None)
|
||||
self.assertTrue(d.get('c') is None)
|
||||
self.assertEqual(d.get('c', 3), 3)
|
||||
self.assertEqual(d.get('a'), 1)
|
||||
self.assertEqual(d.get('a', 3), 1)
|
||||
|
@ -497,9 +497,9 @@ class TestMappingProtocol(BasicTestMappingProtocol):
|
|||
def test_setdefault(self):
|
||||
BasicTestMappingProtocol.test_setdefault(self)
|
||||
d = self._empty_mapping()
|
||||
self.assert_(d.setdefault('key0') is None)
|
||||
self.assertTrue(d.setdefault('key0') is None)
|
||||
d.setdefault('key0', [])
|
||||
self.assert_(d.setdefault('key0') is None)
|
||||
self.assertTrue(d.setdefault('key0') is None)
|
||||
d.setdefault('key', []).append(3)
|
||||
self.assertEqual(d['key'][0], 3)
|
||||
d.setdefault('key', []).append(4)
|
||||
|
@ -525,9 +525,9 @@ class TestMappingProtocol(BasicTestMappingProtocol):
|
|||
self.assertEqual(va, int(ka))
|
||||
kb, vb = tb = b.popitem()
|
||||
self.assertEqual(vb, int(kb))
|
||||
self.assert_(not(copymode < 0 and ta != tb))
|
||||
self.assert_(not a)
|
||||
self.assert_(not b)
|
||||
self.assertTrue(not(copymode < 0 and ta != tb))
|
||||
self.assertTrue(not a)
|
||||
self.assertTrue(not b)
|
||||
|
||||
def test_pop(self):
|
||||
BasicTestMappingProtocol.test_pop(self)
|
||||
|
@ -585,7 +585,7 @@ class TestHashMappingProtocol(TestMappingProtocol):
|
|||
return UserDict.UserDict()
|
||||
ud = mydict.fromkeys('ab')
|
||||
self.assertEqual(ud, {'a':None, 'b':None})
|
||||
self.assert_(isinstance(ud, UserDict.UserDict))
|
||||
self.assertTrue(isinstance(ud, UserDict.UserDict))
|
||||
|
||||
def test_pop(self):
|
||||
TestMappingProtocol.test_pop(self)
|
||||
|
@ -636,8 +636,8 @@ class TestHashMappingProtocol(TestMappingProtocol):
|
|||
self.assertRaises(Exc, repr, d)
|
||||
|
||||
def test_le(self):
|
||||
self.assert_(not (self._empty_mapping() < self._empty_mapping()))
|
||||
self.assert_(not (self._full_mapping({1: 2}) < self._full_mapping({1L: 2L})))
|
||||
self.assertTrue(not (self._empty_mapping() < self._empty_mapping()))
|
||||
self.assertTrue(not (self._full_mapping({1: 2}) < self._full_mapping({1L: 2L})))
|
||||
|
||||
class Exc(Exception): pass
|
||||
|
||||
|
|
|
@ -461,7 +461,7 @@ class AbstractPickleTests(unittest.TestCase):
|
|||
s = self.dumps(l, proto)
|
||||
x = self.loads(s)
|
||||
self.assertEqual(len(x), 1)
|
||||
self.assert_(x is x[0])
|
||||
self.assertTrue(x is x[0])
|
||||
|
||||
def test_recursive_tuple(self):
|
||||
t = ([],)
|
||||
|
@ -471,7 +471,7 @@ class AbstractPickleTests(unittest.TestCase):
|
|||
x = self.loads(s)
|
||||
self.assertEqual(len(x), 1)
|
||||
self.assertEqual(len(x[0]), 1)
|
||||
self.assert_(x is x[0][0])
|
||||
self.assertTrue(x is x[0][0])
|
||||
|
||||
def test_recursive_dict(self):
|
||||
d = {}
|
||||
|
@ -480,7 +480,7 @@ class AbstractPickleTests(unittest.TestCase):
|
|||
s = self.dumps(d, proto)
|
||||
x = self.loads(s)
|
||||
self.assertEqual(x.keys(), [1])
|
||||
self.assert_(x[1] is x)
|
||||
self.assertTrue(x[1] is x)
|
||||
|
||||
def test_recursive_inst(self):
|
||||
i = C()
|
||||
|
@ -489,7 +489,7 @@ class AbstractPickleTests(unittest.TestCase):
|
|||
s = self.dumps(i, 2)
|
||||
x = self.loads(s)
|
||||
self.assertEqual(dir(x), dir(i))
|
||||
self.assert_(x.attr is x)
|
||||
self.assertTrue(x.attr is x)
|
||||
|
||||
def test_recursive_multi(self):
|
||||
l = []
|
||||
|
@ -503,7 +503,7 @@ class AbstractPickleTests(unittest.TestCase):
|
|||
self.assertEqual(len(x), 1)
|
||||
self.assertEqual(dir(x[0]), dir(i))
|
||||
self.assertEqual(x[0].attr.keys(), [1])
|
||||
self.assert_(x[0].attr[1] is x)
|
||||
self.assertTrue(x[0].attr[1] is x)
|
||||
|
||||
def test_garyp(self):
|
||||
self.assertRaises(self.error, self.loads, 'garyp')
|
||||
|
@ -644,7 +644,7 @@ class AbstractPickleTests(unittest.TestCase):
|
|||
try:
|
||||
self.loads(badpickle)
|
||||
except ValueError, detail:
|
||||
self.failUnless(str(detail).startswith(
|
||||
self.assertTrue(str(detail).startswith(
|
||||
"unsupported pickle protocol"))
|
||||
else:
|
||||
self.fail("expected bad protocol number to raise ValueError")
|
||||
|
@ -716,7 +716,7 @@ class AbstractPickleTests(unittest.TestCase):
|
|||
for x in None, False, True:
|
||||
s = self.dumps(x, proto)
|
||||
y = self.loads(s)
|
||||
self.assert_(x is y, (proto, x, s, y))
|
||||
self.assertTrue(x is y, (proto, x, s, y))
|
||||
expected = expected_opcode[proto, x]
|
||||
self.assertEqual(opcode_in_pickle(expected, s), True)
|
||||
|
||||
|
@ -766,8 +766,8 @@ class AbstractPickleTests(unittest.TestCase):
|
|||
|
||||
# Dump using protocol 1 for comparison.
|
||||
s1 = self.dumps(x, 1)
|
||||
self.assert_(__name__ in s1)
|
||||
self.assert_("MyList" in s1)
|
||||
self.assertTrue(__name__ in s1)
|
||||
self.assertTrue("MyList" in s1)
|
||||
self.assertEqual(opcode_in_pickle(opcode, s1), False)
|
||||
|
||||
y = self.loads(s1)
|
||||
|
@ -776,8 +776,8 @@ class AbstractPickleTests(unittest.TestCase):
|
|||
|
||||
# Dump using protocol 2 for test.
|
||||
s2 = self.dumps(x, 2)
|
||||
self.assert_(__name__ not in s2)
|
||||
self.assert_("MyList" not in s2)
|
||||
self.assertTrue(__name__ not in s2)
|
||||
self.assertTrue("MyList" not in s2)
|
||||
self.assertEqual(opcode_in_pickle(opcode, s2), True)
|
||||
|
||||
y = self.loads(s2)
|
||||
|
@ -821,7 +821,7 @@ class AbstractPickleTests(unittest.TestCase):
|
|||
if proto == 0:
|
||||
self.assertEqual(num_appends, 0)
|
||||
else:
|
||||
self.failUnless(num_appends >= 2)
|
||||
self.assertTrue(num_appends >= 2)
|
||||
|
||||
def test_dict_chunking(self):
|
||||
n = 10 # too small to chunk
|
||||
|
@ -843,7 +843,7 @@ class AbstractPickleTests(unittest.TestCase):
|
|||
if proto == 0:
|
||||
self.assertEqual(num_setitems, 0)
|
||||
else:
|
||||
self.failUnless(num_setitems >= 2)
|
||||
self.assertTrue(num_setitems >= 2)
|
||||
|
||||
def test_simple_newobj(self):
|
||||
x = object.__new__(SimpleNewObj) # avoid __init__
|
||||
|
|
|
@ -85,7 +85,7 @@ class TestGenericStringIO(unittest.TestCase):
|
|||
|
||||
def test_iterator(self):
|
||||
eq = self.assertEqual
|
||||
unless = self.failUnless
|
||||
unless = self.assertTrue
|
||||
eq(iter(self._fp), self._fp)
|
||||
# Does this object support the iteration protocol?
|
||||
unless(hasattr(self._fp, '__iter__'))
|
||||
|
|
|
@ -18,7 +18,7 @@ class AllTest(unittest.TestCase):
|
|||
# Silent fail here seems the best route since some modules
|
||||
# may not be available in all environments.
|
||||
return
|
||||
self.failUnless(hasattr(sys.modules[modname], "__all__"),
|
||||
self.assertTrue(hasattr(sys.modules[modname], "__all__"),
|
||||
"%s has no __all__ attribute" % modname)
|
||||
names = {}
|
||||
exec "from %s import *" % modname in names
|
||||
|
|
|
@ -15,7 +15,7 @@ class FutureTest(unittest.TestCase):
|
|||
for name in dir(__future__):
|
||||
obj = getattr(__future__, name, None)
|
||||
if obj is not None and isinstance(obj, __future__._Feature):
|
||||
self.assert_(
|
||||
self.assertTrue(
|
||||
name in given_feature_names,
|
||||
"%r should have been in all_feature_names" % name
|
||||
)
|
||||
|
@ -30,7 +30,7 @@ class FutureTest(unittest.TestCase):
|
|||
optional = value.getOptionalRelease()
|
||||
mandatory = value.getMandatoryRelease()
|
||||
|
||||
a = self.assert_
|
||||
a = self.assertTrue
|
||||
e = self.assertEqual
|
||||
def check(t, name):
|
||||
a(isinstance(t, tuple), "%s isn't tuple" % name)
|
||||
|
|
|
@ -44,23 +44,23 @@ class TestABC(unittest.TestCase):
|
|||
def bar(self): pass # concrete
|
||||
self.assertEqual(C.__abstractmethods__, set(["foo"]))
|
||||
self.assertRaises(TypeError, C) # because foo is abstract
|
||||
self.assert_(isabstract(C))
|
||||
self.assertTrue(isabstract(C))
|
||||
class D(C):
|
||||
def bar(self): pass # concrete override of concrete
|
||||
self.assertEqual(D.__abstractmethods__, set(["foo"]))
|
||||
self.assertRaises(TypeError, D) # because foo is still abstract
|
||||
self.assert_(isabstract(D))
|
||||
self.assertTrue(isabstract(D))
|
||||
class E(D):
|
||||
def foo(self): pass
|
||||
self.assertEqual(E.__abstractmethods__, set())
|
||||
E() # now foo is concrete, too
|
||||
self.failIf(isabstract(E))
|
||||
self.assertFalse(isabstract(E))
|
||||
class F(E):
|
||||
@abstractthing
|
||||
def bar(self): pass # abstract override of concrete
|
||||
self.assertEqual(F.__abstractmethods__, set(["bar"]))
|
||||
self.assertRaises(TypeError, F) # because bar is abstract now
|
||||
self.assert_(isabstract(F))
|
||||
self.assertTrue(isabstract(F))
|
||||
|
||||
def test_subclass_oldstyle_class(self):
|
||||
class A:
|
||||
|
@ -152,41 +152,41 @@ class TestABC(unittest.TestCase):
|
|||
def test_registration_transitiveness(self):
|
||||
class A:
|
||||
__metaclass__ = abc.ABCMeta
|
||||
self.failUnless(issubclass(A, A))
|
||||
self.failUnless(issubclass(A, (A,)))
|
||||
self.assertTrue(issubclass(A, A))
|
||||
self.assertTrue(issubclass(A, (A,)))
|
||||
class B:
|
||||
__metaclass__ = abc.ABCMeta
|
||||
self.failIf(issubclass(A, B))
|
||||
self.failIf(issubclass(A, (B,)))
|
||||
self.failIf(issubclass(B, A))
|
||||
self.failIf(issubclass(B, (A,)))
|
||||
self.assertFalse(issubclass(A, B))
|
||||
self.assertFalse(issubclass(A, (B,)))
|
||||
self.assertFalse(issubclass(B, A))
|
||||
self.assertFalse(issubclass(B, (A,)))
|
||||
class C:
|
||||
__metaclass__ = abc.ABCMeta
|
||||
A.register(B)
|
||||
class B1(B):
|
||||
pass
|
||||
self.failUnless(issubclass(B1, A))
|
||||
self.failUnless(issubclass(B1, (A,)))
|
||||
self.assertTrue(issubclass(B1, A))
|
||||
self.assertTrue(issubclass(B1, (A,)))
|
||||
class C1(C):
|
||||
pass
|
||||
B1.register(C1)
|
||||
self.failIf(issubclass(C, B))
|
||||
self.failIf(issubclass(C, (B,)))
|
||||
self.failIf(issubclass(C, B1))
|
||||
self.failIf(issubclass(C, (B1,)))
|
||||
self.failUnless(issubclass(C1, A))
|
||||
self.failUnless(issubclass(C1, (A,)))
|
||||
self.failUnless(issubclass(C1, B))
|
||||
self.failUnless(issubclass(C1, (B,)))
|
||||
self.failUnless(issubclass(C1, B1))
|
||||
self.failUnless(issubclass(C1, (B1,)))
|
||||
self.assertFalse(issubclass(C, B))
|
||||
self.assertFalse(issubclass(C, (B,)))
|
||||
self.assertFalse(issubclass(C, B1))
|
||||
self.assertFalse(issubclass(C, (B1,)))
|
||||
self.assertTrue(issubclass(C1, A))
|
||||
self.assertTrue(issubclass(C1, (A,)))
|
||||
self.assertTrue(issubclass(C1, B))
|
||||
self.assertTrue(issubclass(C1, (B,)))
|
||||
self.assertTrue(issubclass(C1, B1))
|
||||
self.assertTrue(issubclass(C1, (B1,)))
|
||||
C1.register(int)
|
||||
class MyInt(int):
|
||||
pass
|
||||
self.failUnless(issubclass(MyInt, A))
|
||||
self.failUnless(issubclass(MyInt, (A,)))
|
||||
self.failUnless(isinstance(42, A))
|
||||
self.failUnless(isinstance(42, (A,)))
|
||||
self.assertTrue(issubclass(MyInt, A))
|
||||
self.assertTrue(issubclass(MyInt, (A,)))
|
||||
self.assertTrue(isinstance(42, A))
|
||||
self.assertTrue(isinstance(42, (A,)))
|
||||
|
||||
def test_all_new_methods_are_called(self):
|
||||
class A:
|
||||
|
|
|
@ -9,8 +9,8 @@ from test import test_support
|
|||
|
||||
class TestNumbers(unittest.TestCase):
|
||||
def test_int(self):
|
||||
self.failUnless(issubclass(int, Integral))
|
||||
self.failUnless(issubclass(int, Complex))
|
||||
self.assertTrue(issubclass(int, Integral))
|
||||
self.assertTrue(issubclass(int, Complex))
|
||||
|
||||
self.assertEqual(7, int(7).real)
|
||||
self.assertEqual(0, int(7).imag)
|
||||
|
@ -19,8 +19,8 @@ class TestNumbers(unittest.TestCase):
|
|||
self.assertEqual(1, int(7).denominator)
|
||||
|
||||
def test_long(self):
|
||||
self.failUnless(issubclass(long, Integral))
|
||||
self.failUnless(issubclass(long, Complex))
|
||||
self.assertTrue(issubclass(long, Integral))
|
||||
self.assertTrue(issubclass(long, Complex))
|
||||
|
||||
self.assertEqual(7, long(7).real)
|
||||
self.assertEqual(0, long(7).imag)
|
||||
|
@ -29,16 +29,16 @@ class TestNumbers(unittest.TestCase):
|
|||
self.assertEqual(1, long(7).denominator)
|
||||
|
||||
def test_float(self):
|
||||
self.failIf(issubclass(float, Rational))
|
||||
self.failUnless(issubclass(float, Real))
|
||||
self.assertFalse(issubclass(float, Rational))
|
||||
self.assertTrue(issubclass(float, Real))
|
||||
|
||||
self.assertEqual(7.3, float(7.3).real)
|
||||
self.assertEqual(0, float(7.3).imag)
|
||||
self.assertEqual(7.3, float(7.3).conjugate())
|
||||
|
||||
def test_complex(self):
|
||||
self.failIf(issubclass(complex, Real))
|
||||
self.failUnless(issubclass(complex, Complex))
|
||||
self.assertFalse(issubclass(complex, Real))
|
||||
self.assertTrue(issubclass(complex, Complex))
|
||||
|
||||
c1, c2 = complex(3, 2), complex(4,1)
|
||||
# XXX: This is not ideal, but see the comment in math_trunc().
|
||||
|
|
|
@ -48,7 +48,7 @@ class BaseTest(unittest.TestCase):
|
|||
def test_constructor(self):
|
||||
a = array.array(self.typecode)
|
||||
self.assertEqual(a.typecode, self.typecode)
|
||||
self.assert_(a.itemsize>=self.minitemsize)
|
||||
self.assertTrue(a.itemsize>=self.minitemsize)
|
||||
self.assertRaises(TypeError, array.array, self.typecode, None)
|
||||
|
||||
def test_len(self):
|
||||
|
@ -63,10 +63,10 @@ class BaseTest(unittest.TestCase):
|
|||
a = array.array(self.typecode, self.example)
|
||||
self.assertRaises(TypeError, a.buffer_info, 42)
|
||||
bi = a.buffer_info()
|
||||
self.assert_(isinstance(bi, tuple))
|
||||
self.assertTrue(isinstance(bi, tuple))
|
||||
self.assertEqual(len(bi), 2)
|
||||
self.assert_(isinstance(bi[0], (int, long)))
|
||||
self.assert_(isinstance(bi[1], int))
|
||||
self.assertTrue(isinstance(bi[0], (int, long)))
|
||||
self.assertTrue(isinstance(bi[1], int))
|
||||
self.assertEqual(bi[1], len(a))
|
||||
|
||||
def test_byteswap(self):
|
||||
|
@ -222,39 +222,39 @@ class BaseTest(unittest.TestCase):
|
|||
|
||||
def test_cmp(self):
|
||||
a = array.array(self.typecode, self.example)
|
||||
self.assert_((a == 42) is False)
|
||||
self.assert_((a != 42) is True)
|
||||
self.assertTrue((a == 42) is False)
|
||||
self.assertTrue((a != 42) is True)
|
||||
|
||||
self.assert_((a == a) is True)
|
||||
self.assert_((a != a) is False)
|
||||
self.assert_((a < a) is False)
|
||||
self.assert_((a <= a) is True)
|
||||
self.assert_((a > a) is False)
|
||||
self.assert_((a >= a) is True)
|
||||
self.assertTrue((a == a) is True)
|
||||
self.assertTrue((a != a) is False)
|
||||
self.assertTrue((a < a) is False)
|
||||
self.assertTrue((a <= a) is True)
|
||||
self.assertTrue((a > a) is False)
|
||||
self.assertTrue((a >= a) is True)
|
||||
|
||||
al = array.array(self.typecode, self.smallerexample)
|
||||
ab = array.array(self.typecode, self.biggerexample)
|
||||
|
||||
self.assert_((a == 2*a) is False)
|
||||
self.assert_((a != 2*a) is True)
|
||||
self.assert_((a < 2*a) is True)
|
||||
self.assert_((a <= 2*a) is True)
|
||||
self.assert_((a > 2*a) is False)
|
||||
self.assert_((a >= 2*a) is False)
|
||||
self.assertTrue((a == 2*a) is False)
|
||||
self.assertTrue((a != 2*a) is True)
|
||||
self.assertTrue((a < 2*a) is True)
|
||||
self.assertTrue((a <= 2*a) is True)
|
||||
self.assertTrue((a > 2*a) is False)
|
||||
self.assertTrue((a >= 2*a) is False)
|
||||
|
||||
self.assert_((a == al) is False)
|
||||
self.assert_((a != al) is True)
|
||||
self.assert_((a < al) is False)
|
||||
self.assert_((a <= al) is False)
|
||||
self.assert_((a > al) is True)
|
||||
self.assert_((a >= al) is True)
|
||||
self.assertTrue((a == al) is False)
|
||||
self.assertTrue((a != al) is True)
|
||||
self.assertTrue((a < al) is False)
|
||||
self.assertTrue((a <= al) is False)
|
||||
self.assertTrue((a > al) is True)
|
||||
self.assertTrue((a >= al) is True)
|
||||
|
||||
self.assert_((a == ab) is False)
|
||||
self.assert_((a != ab) is True)
|
||||
self.assert_((a < ab) is True)
|
||||
self.assert_((a <= ab) is True)
|
||||
self.assert_((a > ab) is False)
|
||||
self.assert_((a >= ab) is False)
|
||||
self.assertTrue((a == ab) is False)
|
||||
self.assertTrue((a != ab) is True)
|
||||
self.assertTrue((a < ab) is True)
|
||||
self.assertTrue((a <= ab) is True)
|
||||
self.assertTrue((a > ab) is False)
|
||||
self.assertTrue((a >= ab) is False)
|
||||
|
||||
def test_add(self):
|
||||
a = array.array(self.typecode, self.example) \
|
||||
|
@ -273,7 +273,7 @@ class BaseTest(unittest.TestCase):
|
|||
a = array.array(self.typecode, self.example[::-1])
|
||||
b = a
|
||||
a += array.array(self.typecode, 2*self.example)
|
||||
self.assert_(a is b)
|
||||
self.assertTrue(a is b)
|
||||
self.assertEqual(
|
||||
a,
|
||||
array.array(self.typecode, self.example[::-1]+2*self.example)
|
||||
|
@ -316,22 +316,22 @@ class BaseTest(unittest.TestCase):
|
|||
b = a
|
||||
|
||||
a *= 5
|
||||
self.assert_(a is b)
|
||||
self.assertTrue(a is b)
|
||||
self.assertEqual(
|
||||
a,
|
||||
array.array(self.typecode, 5*self.example)
|
||||
)
|
||||
|
||||
a *= 0
|
||||
self.assert_(a is b)
|
||||
self.assertTrue(a is b)
|
||||
self.assertEqual(a, array.array(self.typecode))
|
||||
|
||||
a *= 1000
|
||||
self.assert_(a is b)
|
||||
self.assertTrue(a is b)
|
||||
self.assertEqual(a, array.array(self.typecode))
|
||||
|
||||
a *= -1
|
||||
self.assert_(a is b)
|
||||
self.assertTrue(a is b)
|
||||
self.assertEqual(a, array.array(self.typecode))
|
||||
|
||||
a = array.array(self.typecode, self.example)
|
||||
|
|
|
@ -122,20 +122,20 @@ eval_tests = [
|
|||
|
||||
class AST_Tests(unittest.TestCase):
|
||||
|
||||
def _assert_order(self, ast_node, parent_pos):
|
||||
def _assertTrueorder(self, ast_node, parent_pos):
|
||||
if not isinstance(ast_node, ast.AST) or ast_node._fields is None:
|
||||
return
|
||||
if isinstance(ast_node, (ast.expr, ast.stmt, ast.excepthandler)):
|
||||
node_pos = (ast_node.lineno, ast_node.col_offset)
|
||||
self.assert_(node_pos >= parent_pos)
|
||||
self.assertTrue(node_pos >= parent_pos)
|
||||
parent_pos = (ast_node.lineno, ast_node.col_offset)
|
||||
for name in ast_node._fields:
|
||||
value = getattr(ast_node, name)
|
||||
if isinstance(value, list):
|
||||
for child in value:
|
||||
self._assert_order(child, parent_pos)
|
||||
self._assertTrueorder(child, parent_pos)
|
||||
elif value is not None:
|
||||
self._assert_order(value, parent_pos)
|
||||
self._assertTrueorder(value, parent_pos)
|
||||
|
||||
def test_snippets(self):
|
||||
for input, output, kind in ((exec_tests, exec_results, "exec"),
|
||||
|
@ -144,7 +144,7 @@ class AST_Tests(unittest.TestCase):
|
|||
for i, o in itertools.izip(input, output):
|
||||
ast_tree = compile(i, "?", kind, ast.PyCF_ONLY_AST)
|
||||
self.assertEquals(to_tuple(ast_tree), o)
|
||||
self._assert_order(ast_tree, (0, 0))
|
||||
self._assertTrueorder(ast_tree, (0, 0))
|
||||
|
||||
def test_slice(self):
|
||||
slc = ast.parse("x[::]").body[0].value.slice
|
||||
|
|
|
@ -71,7 +71,7 @@ class AugAssignTest(unittest.TestCase):
|
|||
y[1:2] += [1]
|
||||
|
||||
self.assertEquals(x, [1, 2, 1, 2, 3])
|
||||
self.assert_(x is y)
|
||||
self.assertTrue(x is y)
|
||||
|
||||
def testCustomMethods1(self):
|
||||
|
||||
|
@ -96,23 +96,23 @@ class AugAssignTest(unittest.TestCase):
|
|||
y = x
|
||||
x += 10
|
||||
|
||||
self.assert_(isinstance(x, aug_test))
|
||||
self.assert_(y is not x)
|
||||
self.assertTrue(isinstance(x, aug_test))
|
||||
self.assertTrue(y is not x)
|
||||
self.assertEquals(x.val, 11)
|
||||
|
||||
x = aug_test2(2)
|
||||
y = x
|
||||
x += 10
|
||||
|
||||
self.assert_(y is x)
|
||||
self.assertTrue(y is x)
|
||||
self.assertEquals(x.val, 12)
|
||||
|
||||
x = aug_test3(3)
|
||||
y = x
|
||||
x += 10
|
||||
|
||||
self.assert_(isinstance(x, aug_test3))
|
||||
self.assert_(y is not x)
|
||||
self.assertTrue(isinstance(x, aug_test3))
|
||||
self.assertTrue(y is not x)
|
||||
self.assertEquals(x.val, 13)
|
||||
|
||||
|
||||
|
|
|
@ -130,18 +130,18 @@ class StrTest(unittest.TestCase):
|
|||
except MemoryError:
|
||||
pass # acceptable on 32-bit
|
||||
else:
|
||||
self.failUnless(s == eval(r))
|
||||
self.assertTrue(s == eval(r))
|
||||
|
||||
@bigmemtest(minsize=_2G, memuse=2)
|
||||
def test_endswith(self, size):
|
||||
SUBSTR = ' abc def ghi'
|
||||
s = '-' * size + SUBSTR
|
||||
self.failUnless(s.endswith(SUBSTR))
|
||||
self.failUnless(s.endswith(s))
|
||||
self.assertTrue(s.endswith(SUBSTR))
|
||||
self.assertTrue(s.endswith(s))
|
||||
s2 = '...' + s
|
||||
self.failUnless(s2.endswith(s))
|
||||
self.failIf(s.endswith('a' + SUBSTR))
|
||||
self.failIf(SUBSTR.endswith(s))
|
||||
self.assertTrue(s2.endswith(s))
|
||||
self.assertFalse(s.endswith('a' + SUBSTR))
|
||||
self.assertFalse(SUBSTR.endswith(s))
|
||||
|
||||
@bigmemtest(minsize=_2G + 10, memuse=2)
|
||||
def test_expandtabs(self, size):
|
||||
|
@ -191,62 +191,62 @@ class StrTest(unittest.TestCase):
|
|||
def test_isalnum(self, size):
|
||||
SUBSTR = '123456'
|
||||
s = 'a' * size + SUBSTR
|
||||
self.failUnless(s.isalnum())
|
||||
self.assertTrue(s.isalnum())
|
||||
s += '.'
|
||||
self.failIf(s.isalnum())
|
||||
self.assertFalse(s.isalnum())
|
||||
|
||||
@bigmemtest(minsize=_2G, memuse=2)
|
||||
def test_isalpha(self, size):
|
||||
SUBSTR = 'zzzzzzz'
|
||||
s = 'a' * size + SUBSTR
|
||||
self.failUnless(s.isalpha())
|
||||
self.assertTrue(s.isalpha())
|
||||
s += '.'
|
||||
self.failIf(s.isalpha())
|
||||
self.assertFalse(s.isalpha())
|
||||
|
||||
@bigmemtest(minsize=_2G, memuse=2)
|
||||
def test_isdigit(self, size):
|
||||
SUBSTR = '123456'
|
||||
s = '9' * size + SUBSTR
|
||||
self.failUnless(s.isdigit())
|
||||
self.assertTrue(s.isdigit())
|
||||
s += 'z'
|
||||
self.failIf(s.isdigit())
|
||||
self.assertFalse(s.isdigit())
|
||||
|
||||
@bigmemtest(minsize=_2G, memuse=2)
|
||||
def test_islower(self, size):
|
||||
chars = ''.join([ chr(c) for c in range(255) if not chr(c).isupper() ])
|
||||
repeats = size // len(chars) + 2
|
||||
s = chars * repeats
|
||||
self.failUnless(s.islower())
|
||||
self.assertTrue(s.islower())
|
||||
s += 'A'
|
||||
self.failIf(s.islower())
|
||||
self.assertFalse(s.islower())
|
||||
|
||||
@bigmemtest(minsize=_2G, memuse=2)
|
||||
def test_isspace(self, size):
|
||||
whitespace = ' \f\n\r\t\v'
|
||||
repeats = size // len(whitespace) + 2
|
||||
s = whitespace * repeats
|
||||
self.failUnless(s.isspace())
|
||||
self.assertTrue(s.isspace())
|
||||
s += 'j'
|
||||
self.failIf(s.isspace())
|
||||
self.assertFalse(s.isspace())
|
||||
|
||||
@bigmemtest(minsize=_2G, memuse=2)
|
||||
def test_istitle(self, size):
|
||||
SUBSTR = '123456'
|
||||
s = ''.join(['A', 'a' * size, SUBSTR])
|
||||
self.failUnless(s.istitle())
|
||||
self.assertTrue(s.istitle())
|
||||
s += 'A'
|
||||
self.failUnless(s.istitle())
|
||||
self.assertTrue(s.istitle())
|
||||
s += 'aA'
|
||||
self.failIf(s.istitle())
|
||||
self.assertFalse(s.istitle())
|
||||
|
||||
@bigmemtest(minsize=_2G, memuse=2)
|
||||
def test_isupper(self, size):
|
||||
chars = ''.join([ chr(c) for c in range(255) if not chr(c).islower() ])
|
||||
repeats = size // len(chars) + 2
|
||||
s = chars * repeats
|
||||
self.failUnless(s.isupper())
|
||||
self.assertTrue(s.isupper())
|
||||
s += 'a'
|
||||
self.failIf(s.isupper())
|
||||
self.assertFalse(s.isupper())
|
||||
|
||||
@bigmemtest(minsize=_2G, memuse=2)
|
||||
def test_join(self, size):
|
||||
|
@ -254,14 +254,14 @@ class StrTest(unittest.TestCase):
|
|||
x = s.join(['aaaaa', 'bbbbb'])
|
||||
self.assertEquals(x.count('a'), 5)
|
||||
self.assertEquals(x.count('b'), 5)
|
||||
self.failUnless(x.startswith('aaaaaA'))
|
||||
self.failUnless(x.endswith('Abbbbb'))
|
||||
self.assertTrue(x.startswith('aaaaaA'))
|
||||
self.assertTrue(x.endswith('Abbbbb'))
|
||||
|
||||
@bigmemtest(minsize=_2G + 10, memuse=1)
|
||||
def test_ljust(self, size):
|
||||
SUBSTR = ' abc def ghi'
|
||||
s = SUBSTR.ljust(size)
|
||||
self.failUnless(s.startswith(SUBSTR + ' '))
|
||||
self.assertTrue(s.startswith(SUBSTR + ' '))
|
||||
self.assertEquals(len(s), size)
|
||||
self.assertEquals(s.strip(), SUBSTR.strip())
|
||||
|
||||
|
@ -282,7 +282,7 @@ class StrTest(unittest.TestCase):
|
|||
s = SUBSTR.ljust(size)
|
||||
self.assertEquals(len(s), size)
|
||||
stripped = s.lstrip()
|
||||
self.failUnless(stripped is s)
|
||||
self.assertTrue(stripped is s)
|
||||
|
||||
@bigmemtest(minsize=_2G + 10, memuse=2)
|
||||
def test_replace(self, size):
|
||||
|
@ -333,7 +333,7 @@ class StrTest(unittest.TestCase):
|
|||
def test_rjust(self, size):
|
||||
SUBSTR = ' abc def ghi'
|
||||
s = SUBSTR.ljust(size)
|
||||
self.failUnless(s.startswith(SUBSTR + ' '))
|
||||
self.assertTrue(s.startswith(SUBSTR + ' '))
|
||||
self.assertEquals(len(s), size)
|
||||
self.assertEquals(s.strip(), SUBSTR.strip())
|
||||
|
||||
|
@ -347,7 +347,7 @@ class StrTest(unittest.TestCase):
|
|||
s = SUBSTR.rjust(size)
|
||||
self.assertEquals(len(s), size)
|
||||
stripped = s.rstrip()
|
||||
self.failUnless(stripped is s)
|
||||
self.assertTrue(stripped is s)
|
||||
|
||||
# The test takes about size bytes to build a string, and then about
|
||||
# sqrt(size) substrings of sqrt(size) in size and a list to
|
||||
|
@ -399,9 +399,9 @@ class StrTest(unittest.TestCase):
|
|||
def test_startswith(self, size):
|
||||
SUBSTR = ' abc def ghi'
|
||||
s = '-' * size + SUBSTR
|
||||
self.failUnless(s.startswith(s))
|
||||
self.failUnless(s.startswith('-' * size))
|
||||
self.failIf(s.startswith(SUBSTR))
|
||||
self.assertTrue(s.startswith(s))
|
||||
self.assertTrue(s.startswith('-' * size))
|
||||
self.assertFalse(s.startswith(SUBSTR))
|
||||
|
||||
@bigmemtest(minsize=_2G, memuse=1)
|
||||
def test_strip(self, size):
|
||||
|
@ -430,8 +430,8 @@ class StrTest(unittest.TestCase):
|
|||
SUBSTR = 'SpaaHAaaAaham'
|
||||
s = SUBSTR * (size // len(SUBSTR) + 2)
|
||||
s = s.title()
|
||||
self.failUnless(s.startswith((SUBSTR * 3).title()))
|
||||
self.failUnless(s.endswith(SUBSTR.lower() * 3))
|
||||
self.assertTrue(s.startswith((SUBSTR * 3).title()))
|
||||
self.assertTrue(s.endswith(SUBSTR.lower() * 3))
|
||||
|
||||
@bigmemtest(minsize=_2G, memuse=2)
|
||||
def test_translate(self, size):
|
||||
|
@ -459,8 +459,8 @@ class StrTest(unittest.TestCase):
|
|||
def test_zfill(self, size):
|
||||
SUBSTR = '-568324723598234'
|
||||
s = SUBSTR.zfill(size)
|
||||
self.failUnless(s.endswith('0' + SUBSTR[1:]))
|
||||
self.failUnless(s.startswith('-0'))
|
||||
self.assertTrue(s.endswith('0' + SUBSTR[1:]))
|
||||
self.assertTrue(s.startswith('-0'))
|
||||
self.assertEquals(len(s), size)
|
||||
self.assertEquals(s.count('0'), size - len(SUBSTR))
|
||||
|
||||
|
@ -468,12 +468,12 @@ class StrTest(unittest.TestCase):
|
|||
def test_format(self, size):
|
||||
s = '-' * size
|
||||
sf = '%s' % (s,)
|
||||
self.failUnless(s == sf)
|
||||
self.assertTrue(s == sf)
|
||||
del sf
|
||||
sf = '..%s..' % (s,)
|
||||
self.assertEquals(len(sf), len(s) + 4)
|
||||
self.failUnless(sf.startswith('..-'))
|
||||
self.failUnless(sf.endswith('-..'))
|
||||
self.assertTrue(sf.startswith('..-'))
|
||||
self.assertTrue(sf.endswith('-..'))
|
||||
del s, sf
|
||||
|
||||
size //= 2
|
||||
|
@ -519,7 +519,7 @@ class StrTest(unittest.TestCase):
|
|||
@bigmemtest(minsize=2**32 / 5, memuse=6+2)
|
||||
def test_unicode_repr(self, size):
|
||||
s = u"\uAAAA" * size
|
||||
self.failUnless(len(repr(s)) > size)
|
||||
self.assertTrue(len(repr(s)) > size)
|
||||
|
||||
# This test is meaningful even with size < 2G, as long as the
|
||||
# doubled string is > 2G (but it tests more if both are > 2G :)
|
||||
|
@ -580,24 +580,24 @@ class StrTest(unittest.TestCase):
|
|||
edge = '-' * (size // 2)
|
||||
s = ''.join([edge, SUBSTR, edge])
|
||||
del edge
|
||||
self.failUnless(SUBSTR in s)
|
||||
self.failIf(SUBSTR * 2 in s)
|
||||
self.failUnless('-' in s)
|
||||
self.failIf('a' in s)
|
||||
self.assertTrue(SUBSTR in s)
|
||||
self.assertFalse(SUBSTR * 2 in s)
|
||||
self.assertTrue('-' in s)
|
||||
self.assertFalse('a' in s)
|
||||
s += 'a'
|
||||
self.failUnless('a' in s)
|
||||
self.assertTrue('a' in s)
|
||||
|
||||
@bigmemtest(minsize=_2G + 10, memuse=2)
|
||||
def test_compare(self, size):
|
||||
s1 = '-' * size
|
||||
s2 = '-' * size
|
||||
self.failUnless(s1 == s2)
|
||||
self.assertTrue(s1 == s2)
|
||||
del s2
|
||||
s2 = s1 + 'a'
|
||||
self.failIf(s1 == s2)
|
||||
self.assertFalse(s1 == s2)
|
||||
del s2
|
||||
s2 = '.' * size
|
||||
self.failIf(s1 == s2)
|
||||
self.assertFalse(s1 == s2)
|
||||
|
||||
@bigmemtest(minsize=_2G + 10, memuse=1)
|
||||
def test_hash(self, size):
|
||||
|
@ -611,7 +611,7 @@ class StrTest(unittest.TestCase):
|
|||
h1 = hash(s)
|
||||
del s
|
||||
s = '\x00' * (size + 1)
|
||||
self.failIf(h1 == hash(s))
|
||||
self.assertFalse(h1 == hash(s))
|
||||
|
||||
class TupleTest(unittest.TestCase):
|
||||
|
||||
|
@ -628,13 +628,13 @@ class TupleTest(unittest.TestCase):
|
|||
def test_compare(self, size):
|
||||
t1 = (u'',) * size
|
||||
t2 = (u'',) * size
|
||||
self.failUnless(t1 == t2)
|
||||
self.assertTrue(t1 == t2)
|
||||
del t2
|
||||
t2 = (u'',) * (size + 1)
|
||||
self.failIf(t1 == t2)
|
||||
self.assertFalse(t1 == t2)
|
||||
del t2
|
||||
t2 = (1,) * size
|
||||
self.failIf(t1 == t2)
|
||||
self.assertFalse(t1 == t2)
|
||||
|
||||
# Test concatenating into a single tuple of more than 2G in length,
|
||||
# and concatenating a tuple of more than 2G in length separately, so
|
||||
|
@ -659,9 +659,9 @@ class TupleTest(unittest.TestCase):
|
|||
def test_contains(self, size):
|
||||
t = (1, 2, 3, 4, 5) * size
|
||||
self.assertEquals(len(t), size * 5)
|
||||
self.failUnless(5 in t)
|
||||
self.failIf((1, 2, 3, 4, 5) in t)
|
||||
self.failIf(0 in t)
|
||||
self.assertTrue(5 in t)
|
||||
self.assertFalse((1, 2, 3, 4, 5) in t)
|
||||
self.assertFalse(0 in t)
|
||||
|
||||
@bigmemtest(minsize=_2G + 10, memuse=8)
|
||||
def test_hash(self, size):
|
||||
|
@ -669,7 +669,7 @@ class TupleTest(unittest.TestCase):
|
|||
h1 = hash(t1)
|
||||
del t1
|
||||
t2 = (0,) * (size + 1)
|
||||
self.failIf(h1 == hash(t2))
|
||||
self.assertFalse(h1 == hash(t2))
|
||||
|
||||
@bigmemtest(minsize=_2G + 10, memuse=8)
|
||||
def test_index_and_slice(self, size):
|
||||
|
@ -762,13 +762,13 @@ class ListTest(unittest.TestCase):
|
|||
def test_compare(self, size):
|
||||
l1 = [u''] * size
|
||||
l2 = [u''] * size
|
||||
self.failUnless(l1 == l2)
|
||||
self.assertTrue(l1 == l2)
|
||||
del l2
|
||||
l2 = [u''] * (size + 1)
|
||||
self.failIf(l1 == l2)
|
||||
self.assertFalse(l1 == l2)
|
||||
del l2
|
||||
l2 = [2] * size
|
||||
self.failIf(l1 == l2)
|
||||
self.assertFalse(l1 == l2)
|
||||
|
||||
# Test concatenating into a single list of more than 2G in length,
|
||||
# and concatenating a list of more than 2G in length separately, so
|
||||
|
@ -793,8 +793,8 @@ class ListTest(unittest.TestCase):
|
|||
l = [sys.stdout] * size
|
||||
l += l
|
||||
self.assertEquals(len(l), size * 2)
|
||||
self.failUnless(l[0] is l[-1])
|
||||
self.failUnless(l[size - 1] is l[size + 1])
|
||||
self.assertTrue(l[0] is l[-1])
|
||||
self.assertTrue(l[size - 1] is l[size + 1])
|
||||
|
||||
@bigmemtest(minsize=_2G // 2 + 2, memuse=24)
|
||||
def test_inplace_concat_small(self, size):
|
||||
|
@ -808,14 +808,14 @@ class ListTest(unittest.TestCase):
|
|||
def test_contains(self, size):
|
||||
l = [1, 2, 3, 4, 5] * size
|
||||
self.assertEquals(len(l), size * 5)
|
||||
self.failUnless(5 in l)
|
||||
self.failIf([1, 2, 3, 4, 5] in l)
|
||||
self.failIf(0 in l)
|
||||
self.assertTrue(5 in l)
|
||||
self.assertFalse([1, 2, 3, 4, 5] in l)
|
||||
self.assertFalse(0 in l)
|
||||
|
||||
@bigmemtest(minsize=_2G + 10, memuse=8)
|
||||
def test_hash(self, size):
|
||||
l = [0] * size
|
||||
self.failUnlessRaises(TypeError, hash, l)
|
||||
self.assertRaises(TypeError, hash, l)
|
||||
|
||||
@bigmemtest(minsize=_2G + 10, memuse=8)
|
||||
def test_index_and_slice(self, size):
|
||||
|
@ -875,7 +875,7 @@ class ListTest(unittest.TestCase):
|
|||
# Like test_concat, split in two.
|
||||
def basic_test_repeat(self, size):
|
||||
l = [] * size
|
||||
self.failIf(l)
|
||||
self.assertFalse(l)
|
||||
l = [''] * size
|
||||
self.assertEquals(len(l), size)
|
||||
l = l * 2
|
||||
|
@ -893,13 +893,13 @@ class ListTest(unittest.TestCase):
|
|||
l = ['']
|
||||
l *= size
|
||||
self.assertEquals(len(l), size)
|
||||
self.failUnless(l[0] is l[-1])
|
||||
self.assertTrue(l[0] is l[-1])
|
||||
del l
|
||||
|
||||
l = [''] * size
|
||||
l *= 2
|
||||
self.assertEquals(len(l), size * 2)
|
||||
self.failUnless(l[size - 1] is l[-1])
|
||||
self.assertTrue(l[size - 1] is l[-1])
|
||||
|
||||
@bigmemtest(minsize=_2G // 2 + 2, memuse=16)
|
||||
def test_inplace_repeat_small(self, size):
|
||||
|
@ -933,8 +933,8 @@ class ListTest(unittest.TestCase):
|
|||
l = [object()] * size
|
||||
l.append(object())
|
||||
self.assertEquals(len(l), size+1)
|
||||
self.failUnless(l[-3] is l[-2])
|
||||
self.failIf(l[-2] is l[-1])
|
||||
self.assertTrue(l[-3] is l[-2])
|
||||
self.assertFalse(l[-2] is l[-1])
|
||||
|
||||
@bigmemtest(minsize=_2G // 5 + 2, memuse=8 * 5)
|
||||
def test_count(self, size):
|
||||
|
@ -946,8 +946,8 @@ class ListTest(unittest.TestCase):
|
|||
l = [file] * size
|
||||
l.extend(l)
|
||||
self.assertEquals(len(l), size * 2)
|
||||
self.failUnless(l[0] is l[-1])
|
||||
self.failUnless(l[size - 1] is l[size + 1])
|
||||
self.assertTrue(l[0] is l[-1])
|
||||
self.assertTrue(l[size - 1] is l[size + 1])
|
||||
|
||||
@bigmemtest(minsize=_2G // 2 + 2, memuse=16)
|
||||
def test_extend_small(self, size):
|
||||
|
|
|
@ -14,8 +14,8 @@ class BinASCIITest(unittest.TestCase):
|
|||
|
||||
def test_exceptions(self):
|
||||
# Check module exceptions
|
||||
self.assert_(issubclass(binascii.Error, Exception))
|
||||
self.assert_(issubclass(binascii.Incomplete, Exception))
|
||||
self.assertTrue(issubclass(binascii.Error, Exception))
|
||||
self.assertTrue(issubclass(binascii.Incomplete, Exception))
|
||||
|
||||
def test_functions(self):
|
||||
# Check presence of all functions
|
||||
|
@ -26,10 +26,10 @@ class BinASCIITest(unittest.TestCase):
|
|||
prefixes.extend(["crc_", "rlecode_", "rledecode_"])
|
||||
for prefix in prefixes:
|
||||
name = prefix + suffix
|
||||
self.assert_(callable(getattr(binascii, name)))
|
||||
self.assertTrue(callable(getattr(binascii, name)))
|
||||
self.assertRaises(TypeError, getattr(binascii, name))
|
||||
for name in ("hexlify", "unhexlify"):
|
||||
self.assert_(callable(getattr(binascii, name)))
|
||||
self.assertTrue(callable(getattr(binascii, name)))
|
||||
self.assertRaises(TypeError, getattr(binascii, name))
|
||||
|
||||
def test_base64valid(self):
|
||||
|
|
|
@ -220,10 +220,10 @@ class RatTestCase(unittest.TestCase):
|
|||
self.assertEqual(gcd(-10, -2), -2)
|
||||
for i in range(1, 20):
|
||||
for j in range(1, 20):
|
||||
self.assert_(gcd(i, j) > 0)
|
||||
self.assert_(gcd(-i, j) < 0)
|
||||
self.assert_(gcd(i, -j) > 0)
|
||||
self.assert_(gcd(-i, -j) < 0)
|
||||
self.assertTrue(gcd(i, j) > 0)
|
||||
self.assertTrue(gcd(-i, j) < 0)
|
||||
self.assertTrue(gcd(i, -j) > 0)
|
||||
self.assertTrue(gcd(-i, -j) < 0)
|
||||
|
||||
def test_constructor(self):
|
||||
a = Rat(10, 15)
|
||||
|
|
|
@ -130,14 +130,14 @@ class TestBisect(unittest.TestCase):
|
|||
elem = randrange(-1, n+1)
|
||||
ip = self.module.bisect_left(data, elem)
|
||||
if ip < len(data):
|
||||
self.failUnless(elem <= data[ip])
|
||||
self.assertTrue(elem <= data[ip])
|
||||
if ip > 0:
|
||||
self.failUnless(data[ip-1] < elem)
|
||||
self.assertTrue(data[ip-1] < elem)
|
||||
ip = self.module.bisect_right(data, elem)
|
||||
if ip < len(data):
|
||||
self.failUnless(elem < data[ip])
|
||||
self.assertTrue(elem < data[ip])
|
||||
if ip > 0:
|
||||
self.failUnless(data[ip-1] <= elem)
|
||||
self.assertTrue(data[ip-1] <= elem)
|
||||
|
||||
def test_optionalSlicing(self):
|
||||
for func, data, elem, expected in self.precomputedCases:
|
||||
|
@ -146,15 +146,15 @@ class TestBisect(unittest.TestCase):
|
|||
for hi in xrange(3,8):
|
||||
hi = min(len(data), hi)
|
||||
ip = func(data, elem, lo, hi)
|
||||
self.failUnless(lo <= ip <= hi)
|
||||
self.assertTrue(lo <= ip <= hi)
|
||||
if func is self.module.bisect_left and ip < hi:
|
||||
self.failUnless(elem <= data[ip])
|
||||
self.assertTrue(elem <= data[ip])
|
||||
if func is self.module.bisect_left and ip > lo:
|
||||
self.failUnless(data[ip-1] < elem)
|
||||
self.assertTrue(data[ip-1] < elem)
|
||||
if func is self.module.bisect_right and ip < hi:
|
||||
self.failUnless(elem < data[ip])
|
||||
self.assertTrue(elem < data[ip])
|
||||
if func is self.module.bisect_right and ip > lo:
|
||||
self.failUnless(data[ip-1] <= elem)
|
||||
self.assertTrue(data[ip-1] <= elem)
|
||||
self.assertEqual(ip, max(lo, min(hi, expected)))
|
||||
|
||||
def test_backcompatibility(self):
|
||||
|
|
|
@ -8,10 +8,10 @@ import os
|
|||
class BoolTest(unittest.TestCase):
|
||||
|
||||
def assertIs(self, a, b):
|
||||
self.assert_(a is b)
|
||||
self.assertTrue(a is b)
|
||||
|
||||
def assertIsNot(self, a, b):
|
||||
self.assert_(a is not b)
|
||||
self.assertTrue(a is not b)
|
||||
|
||||
def test_subclass(self):
|
||||
try:
|
||||
|
@ -233,15 +233,15 @@ class BoolTest(unittest.TestCase):
|
|||
|
||||
def test_boolean(self):
|
||||
self.assertEqual(True & 1, 1)
|
||||
self.assert_(not isinstance(True & 1, bool))
|
||||
self.assertTrue(not isinstance(True & 1, bool))
|
||||
self.assertIs(True & True, True)
|
||||
|
||||
self.assertEqual(True | 1, 1)
|
||||
self.assert_(not isinstance(True | 1, bool))
|
||||
self.assertTrue(not isinstance(True | 1, bool))
|
||||
self.assertIs(True | True, True)
|
||||
|
||||
self.assertEqual(True ^ 1, 0)
|
||||
self.assert_(not isinstance(True ^ 1, bool))
|
||||
self.assertTrue(not isinstance(True ^ 1, bool))
|
||||
self.assertIs(True ^ True, False)
|
||||
|
||||
def test_fileclosed(self):
|
||||
|
|
|
@ -43,8 +43,8 @@ class TestBSDDB(unittest.TestCase):
|
|||
def test_change(self):
|
||||
self.f['r'] = 'discovered'
|
||||
self.assertEqual(self.f['r'], 'discovered')
|
||||
self.assert_('r' in self.f.keys())
|
||||
self.assert_('discovered' in self.f.values())
|
||||
self.assertTrue('r' in self.f.keys())
|
||||
self.assertTrue('discovered' in self.f.values())
|
||||
|
||||
def test_close_and_reopen(self):
|
||||
if self.fname is None:
|
||||
|
@ -176,7 +176,7 @@ class TestBSDDB(unittest.TestCase):
|
|||
|
||||
def test_first_while_deleting(self):
|
||||
# Test for bug 1725856
|
||||
self.assert_(len(self.d) >= 2, "test requires >=2 items")
|
||||
self.assertTrue(len(self.d) >= 2, "test requires >=2 items")
|
||||
for _ in self.d:
|
||||
key = self.f.first()[0]
|
||||
del self.f[key]
|
||||
|
@ -184,7 +184,7 @@ class TestBSDDB(unittest.TestCase):
|
|||
|
||||
def test_last_while_deleting(self):
|
||||
# Test for bug 1725856's evil twin
|
||||
self.assert_(len(self.d) >= 2, "test requires >=2 items")
|
||||
self.assertTrue(len(self.d) >= 2, "test requires >=2 items")
|
||||
for _ in self.d:
|
||||
key = self.f.last()[0]
|
||||
del self.f[key]
|
||||
|
@ -195,13 +195,13 @@ class TestBSDDB(unittest.TestCase):
|
|||
|
||||
def test_contains(self):
|
||||
for k in self.d:
|
||||
self.assert_(k in self.f)
|
||||
self.assert_('not here' not in self.f)
|
||||
self.assertTrue(k in self.f)
|
||||
self.assertTrue('not here' not in self.f)
|
||||
|
||||
def test_has_key(self):
|
||||
for k in self.d:
|
||||
self.assert_(self.f.has_key(k))
|
||||
self.assert_(not self.f.has_key('not here'))
|
||||
self.assertTrue(self.f.has_key(k))
|
||||
self.assertTrue(not self.f.has_key('not here'))
|
||||
|
||||
def test_clear(self):
|
||||
self.f.clear()
|
||||
|
@ -253,11 +253,11 @@ class TestBSDDB(unittest.TestCase):
|
|||
if debug: print "K"
|
||||
|
||||
# test the legacy cursor interface mixed with writes
|
||||
self.assert_(self.f.first()[0] in self.d)
|
||||
self.assertTrue(self.f.first()[0] in self.d)
|
||||
k = self.f.next()[0]
|
||||
self.assert_(k in self.d)
|
||||
self.assertTrue(k in self.d)
|
||||
self.f[k] = "be gone with ye deadlocks"
|
||||
self.assert_(self.f[k], "be gone with ye deadlocks")
|
||||
self.assertTrue(self.f[k], "be gone with ye deadlocks")
|
||||
|
||||
def test_for_cursor_memleak(self):
|
||||
# do the bsddb._DBWithCursor iterator internals leak cursors?
|
||||
|
@ -275,21 +275,21 @@ class TestBSDDB(unittest.TestCase):
|
|||
|
||||
self.assertEqual(nc1, nc2)
|
||||
self.assertEqual(nc1, nc4)
|
||||
self.assert_(nc3 == nc1+1)
|
||||
self.assertTrue(nc3 == nc1+1)
|
||||
|
||||
def test_popitem(self):
|
||||
k, v = self.f.popitem()
|
||||
self.assert_(k in self.d)
|
||||
self.assert_(v in self.d.values())
|
||||
self.assert_(k not in self.f)
|
||||
self.assertTrue(k in self.d)
|
||||
self.assertTrue(v in self.d.values())
|
||||
self.assertTrue(k not in self.f)
|
||||
self.assertEqual(len(self.d)-1, len(self.f))
|
||||
|
||||
def test_pop(self):
|
||||
k = 'w'
|
||||
v = self.f.pop(k)
|
||||
self.assertEqual(v, self.d[k])
|
||||
self.assert_(k not in self.f)
|
||||
self.assert_(v not in self.f.values())
|
||||
self.assertTrue(k not in self.f)
|
||||
self.assertTrue(v not in self.f.values())
|
||||
self.assertEqual(len(self.d)-1, len(self.f))
|
||||
|
||||
def test_get(self):
|
||||
|
|
|
@ -34,7 +34,7 @@ class BufferSizeTest(unittest.TestCase):
|
|||
line = f.readline()
|
||||
self.assertEqual(line, s)
|
||||
line = f.readline()
|
||||
self.assert_(not line) # Must be at EOF
|
||||
self.assertTrue(not line) # Must be at EOF
|
||||
f.close()
|
||||
finally:
|
||||
support.unlink(support.TESTFN)
|
||||
|
|
|
@ -122,7 +122,7 @@ class BuiltinTest(unittest.TestCase):
|
|||
|
||||
def test_neg(self):
|
||||
x = -sys.maxint-1
|
||||
self.assert_(isinstance(x, int))
|
||||
self.assertTrue(isinstance(x, int))
|
||||
self.assertEqual(-x, sys.maxint+1)
|
||||
|
||||
def test_apply(self):
|
||||
|
@ -152,19 +152,19 @@ class BuiltinTest(unittest.TestCase):
|
|||
self.assertRaises(TypeError, apply, id, (42,), 42)
|
||||
|
||||
def test_callable(self):
|
||||
self.assert_(callable(len))
|
||||
self.assertTrue(callable(len))
|
||||
def f(): pass
|
||||
self.assert_(callable(f))
|
||||
self.assertTrue(callable(f))
|
||||
class C:
|
||||
def meth(self): pass
|
||||
self.assert_(callable(C))
|
||||
self.assertTrue(callable(C))
|
||||
x = C()
|
||||
self.assert_(callable(x.meth))
|
||||
self.assert_(not callable(x))
|
||||
self.assertTrue(callable(x.meth))
|
||||
self.assertTrue(not callable(x))
|
||||
class D(C):
|
||||
def __call__(self): pass
|
||||
y = D()
|
||||
self.assert_(callable(y))
|
||||
self.assertTrue(callable(y))
|
||||
y()
|
||||
|
||||
def test_chr(self):
|
||||
|
@ -193,9 +193,9 @@ class BuiltinTest(unittest.TestCase):
|
|||
self.assertRaises(TypeError, cmp)
|
||||
|
||||
def test_coerce(self):
|
||||
self.assert_(not fcmp(coerce(1, 1.1), (1.0, 1.1)))
|
||||
self.assertTrue(not fcmp(coerce(1, 1.1), (1.0, 1.1)))
|
||||
self.assertEqual(coerce(1, 1L), (1L, 1L))
|
||||
self.assert_(not fcmp(coerce(1L, 1.1), (1.0, 1.1)))
|
||||
self.assertTrue(not fcmp(coerce(1L, 1.1), (1.0, 1.1)))
|
||||
self.assertRaises(TypeError, coerce)
|
||||
class BadNumber:
|
||||
def __coerce__(self, other):
|
||||
|
@ -234,11 +234,11 @@ class BuiltinTest(unittest.TestCase):
|
|||
|
||||
# dir() - local scope
|
||||
local_var = 1
|
||||
self.assert_('local_var' in dir())
|
||||
self.assertTrue('local_var' in dir())
|
||||
|
||||
# dir(module)
|
||||
import sys
|
||||
self.assert_('exit' in dir(sys))
|
||||
self.assertTrue('exit' in dir(sys))
|
||||
|
||||
# dir(module_with_invalid__dict__)
|
||||
import types
|
||||
|
@ -248,8 +248,8 @@ class BuiltinTest(unittest.TestCase):
|
|||
self.assertRaises(TypeError, dir, f)
|
||||
|
||||
# dir(type)
|
||||
self.assert_("strip" in dir(str))
|
||||
self.assert_("__mro__" not in dir(str))
|
||||
self.assertTrue("strip" in dir(str))
|
||||
self.assertTrue("__mro__" not in dir(str))
|
||||
|
||||
# dir(obj)
|
||||
class Foo(object):
|
||||
|
@ -258,13 +258,13 @@ class BuiltinTest(unittest.TestCase):
|
|||
self.y = 8
|
||||
self.z = 9
|
||||
f = Foo()
|
||||
self.assert_("y" in dir(f))
|
||||
self.assertTrue("y" in dir(f))
|
||||
|
||||
# dir(obj_no__dict__)
|
||||
class Foo(object):
|
||||
__slots__ = []
|
||||
f = Foo()
|
||||
self.assert_("__repr__" in dir(f))
|
||||
self.assertTrue("__repr__" in dir(f))
|
||||
|
||||
# dir(obj_no__class__with__dict__)
|
||||
# (an ugly trick to cause getattr(f, "__class__") to fail)
|
||||
|
@ -273,15 +273,15 @@ class BuiltinTest(unittest.TestCase):
|
|||
def __init__(self):
|
||||
self.bar = "wow"
|
||||
f = Foo()
|
||||
self.assert_("__repr__" not in dir(f))
|
||||
self.assert_("bar" in dir(f))
|
||||
self.assertTrue("__repr__" not in dir(f))
|
||||
self.assertTrue("bar" in dir(f))
|
||||
|
||||
# dir(obj_using __dir__)
|
||||
class Foo(object):
|
||||
def __dir__(self):
|
||||
return ["kan", "ga", "roo"]
|
||||
f = Foo()
|
||||
self.assert_(dir(f) == ["ga", "kan", "roo"])
|
||||
self.assertTrue(dir(f) == ["ga", "kan", "roo"])
|
||||
|
||||
# dir(obj__dir__not_list)
|
||||
class Foo(object):
|
||||
|
@ -309,10 +309,10 @@ class BuiltinTest(unittest.TestCase):
|
|||
self.assertEqual(divmod(-sys.maxint-1, -1),
|
||||
(sys.maxint+1, 0))
|
||||
|
||||
self.assert_(not fcmp(divmod(3.25, 1.0), (3.0, 0.25)))
|
||||
self.assert_(not fcmp(divmod(-3.25, 1.0), (-4.0, 0.75)))
|
||||
self.assert_(not fcmp(divmod(3.25, -1.0), (-4.0, -0.75)))
|
||||
self.assert_(not fcmp(divmod(-3.25, -1.0), (3.0, -0.25)))
|
||||
self.assertTrue(not fcmp(divmod(3.25, 1.0), (3.0, 0.25)))
|
||||
self.assertTrue(not fcmp(divmod(-3.25, 1.0), (-4.0, 0.75)))
|
||||
self.assertTrue(not fcmp(divmod(3.25, -1.0), (-4.0, -0.75)))
|
||||
self.assertTrue(not fcmp(divmod(-3.25, -1.0), (3.0, -0.25)))
|
||||
|
||||
self.assertRaises(TypeError, divmod)
|
||||
|
||||
|
@ -571,11 +571,11 @@ class BuiltinTest(unittest.TestCase):
|
|||
for func in funcs:
|
||||
outp = filter(func, cls(inp))
|
||||
self.assertEqual(outp, exp)
|
||||
self.assert_(not isinstance(outp, cls))
|
||||
self.assertTrue(not isinstance(outp, cls))
|
||||
|
||||
def test_getattr(self):
|
||||
import sys
|
||||
self.assert_(getattr(sys, 'stdout') is sys.stdout)
|
||||
self.assertTrue(getattr(sys, 'stdout') is sys.stdout)
|
||||
self.assertRaises(TypeError, getattr, sys, 1)
|
||||
self.assertRaises(TypeError, getattr, sys, 1, "foo")
|
||||
self.assertRaises(TypeError, getattr)
|
||||
|
@ -584,7 +584,7 @@ class BuiltinTest(unittest.TestCase):
|
|||
|
||||
def test_hasattr(self):
|
||||
import sys
|
||||
self.assert_(hasattr(sys, 'stdout'))
|
||||
self.assertTrue(hasattr(sys, 'stdout'))
|
||||
self.assertRaises(TypeError, hasattr, sys, 1)
|
||||
self.assertRaises(TypeError, hasattr)
|
||||
if have_unicode:
|
||||
|
@ -647,9 +647,9 @@ class BuiltinTest(unittest.TestCase):
|
|||
def test_intern(self):
|
||||
self.assertRaises(TypeError, intern)
|
||||
s = "never interned before"
|
||||
self.assert_(intern(s) is s)
|
||||
self.assertTrue(intern(s) is s)
|
||||
s2 = s.swapcase().swapcase()
|
||||
self.assert_(intern(s2) is s)
|
||||
self.assertTrue(intern(s2) is s)
|
||||
|
||||
# Subclasses of string can't be interned, because they
|
||||
# provide too much opportunity for insane things to happen.
|
||||
|
@ -690,11 +690,11 @@ class BuiltinTest(unittest.TestCase):
|
|||
c = C()
|
||||
d = D()
|
||||
e = E()
|
||||
self.assert_(isinstance(c, C))
|
||||
self.assert_(isinstance(d, C))
|
||||
self.assert_(not isinstance(e, C))
|
||||
self.assert_(not isinstance(c, D))
|
||||
self.assert_(not isinstance('foo', E))
|
||||
self.assertTrue(isinstance(c, C))
|
||||
self.assertTrue(isinstance(d, C))
|
||||
self.assertTrue(not isinstance(e, C))
|
||||
self.assertTrue(not isinstance(c, D))
|
||||
self.assertTrue(not isinstance('foo', E))
|
||||
self.assertRaises(TypeError, isinstance, E, 'foo')
|
||||
self.assertRaises(TypeError, isinstance)
|
||||
|
||||
|
@ -708,9 +708,9 @@ class BuiltinTest(unittest.TestCase):
|
|||
c = C()
|
||||
d = D()
|
||||
e = E()
|
||||
self.assert_(issubclass(D, C))
|
||||
self.assert_(issubclass(C, C))
|
||||
self.assert_(not issubclass(C, D))
|
||||
self.assertTrue(issubclass(D, C))
|
||||
self.assertTrue(issubclass(C, C))
|
||||
self.assertTrue(not issubclass(C, D))
|
||||
self.assertRaises(TypeError, issubclass, 'foo', E)
|
||||
self.assertRaises(TypeError, issubclass, E, 'foo')
|
||||
self.assertRaises(TypeError, issubclass)
|
||||
|
@ -1042,18 +1042,18 @@ class BuiltinTest(unittest.TestCase):
|
|||
self.assertEqual(range(a+4, a, -2), [a+4, a+2])
|
||||
|
||||
seq = range(a, b, c)
|
||||
self.assert_(a in seq)
|
||||
self.assert_(b not in seq)
|
||||
self.assertTrue(a in seq)
|
||||
self.assertTrue(b not in seq)
|
||||
self.assertEqual(len(seq), 2)
|
||||
|
||||
seq = range(b, a, -c)
|
||||
self.assert_(b in seq)
|
||||
self.assert_(a not in seq)
|
||||
self.assertTrue(b in seq)
|
||||
self.assertTrue(a not in seq)
|
||||
self.assertEqual(len(seq), 2)
|
||||
|
||||
seq = range(-a, -b, -c)
|
||||
self.assert_(-a in seq)
|
||||
self.assert_(-b not in seq)
|
||||
self.assertTrue(-a in seq)
|
||||
self.assertTrue(-b not in seq)
|
||||
self.assertEqual(len(seq), 2)
|
||||
|
||||
self.assertRaises(TypeError, range)
|
||||
|
@ -1452,7 +1452,7 @@ class BuiltinTest(unittest.TestCase):
|
|||
# tests for object.__format__ really belong elsewhere, but
|
||||
# there's no good place to put them
|
||||
x = object().__format__('')
|
||||
self.assert_(x.startswith('<object object at'))
|
||||
self.assertTrue(x.startswith('<object object at'))
|
||||
|
||||
# first argument to object.__format__ must be string
|
||||
self.assertRaises(TypeError, object().__format__, 3)
|
||||
|
|
|
@ -102,22 +102,22 @@ class BaseBytesTest(unittest.TestCase):
|
|||
b3 = self.type2test([1, 3])
|
||||
|
||||
self.assertEqual(b1, b2)
|
||||
self.failUnless(b2 != b3)
|
||||
self.failUnless(b1 <= b2)
|
||||
self.failUnless(b1 <= b3)
|
||||
self.failUnless(b1 < b3)
|
||||
self.failUnless(b1 >= b2)
|
||||
self.failUnless(b3 >= b2)
|
||||
self.failUnless(b3 > b2)
|
||||
self.assertTrue(b2 != b3)
|
||||
self.assertTrue(b1 <= b2)
|
||||
self.assertTrue(b1 <= b3)
|
||||
self.assertTrue(b1 < b3)
|
||||
self.assertTrue(b1 >= b2)
|
||||
self.assertTrue(b3 >= b2)
|
||||
self.assertTrue(b3 > b2)
|
||||
|
||||
self.failIf(b1 != b2)
|
||||
self.failIf(b2 == b3)
|
||||
self.failIf(b1 > b2)
|
||||
self.failIf(b1 > b3)
|
||||
self.failIf(b1 >= b3)
|
||||
self.failIf(b1 < b2)
|
||||
self.failIf(b3 < b2)
|
||||
self.failIf(b3 <= b2)
|
||||
self.assertFalse(b1 != b2)
|
||||
self.assertFalse(b2 == b3)
|
||||
self.assertFalse(b1 > b2)
|
||||
self.assertFalse(b1 > b3)
|
||||
self.assertFalse(b1 >= b3)
|
||||
self.assertFalse(b1 < b2)
|
||||
self.assertFalse(b3 < b2)
|
||||
self.assertFalse(b3 <= b2)
|
||||
|
||||
def test_compare_to_str(self):
|
||||
warnings.simplefilter('ignore', BytesWarning)
|
||||
|
@ -220,27 +220,27 @@ class BaseBytesTest(unittest.TestCase):
|
|||
|
||||
def test_contains(self):
|
||||
b = self.type2test(b"abc")
|
||||
self.failUnless(ord('a') in b)
|
||||
self.failUnless(int(ord('a')) in b)
|
||||
self.failIf(200 in b)
|
||||
self.failIf(200 in b)
|
||||
self.assertTrue(ord('a') in b)
|
||||
self.assertTrue(int(ord('a')) in b)
|
||||
self.assertFalse(200 in b)
|
||||
self.assertFalse(200 in b)
|
||||
self.assertRaises(ValueError, lambda: 300 in b)
|
||||
self.assertRaises(ValueError, lambda: -1 in b)
|
||||
self.assertRaises(TypeError, lambda: None in b)
|
||||
self.assertRaises(TypeError, lambda: float(ord('a')) in b)
|
||||
self.assertRaises(TypeError, lambda: u"a" in b)
|
||||
for f in bytes, bytearray:
|
||||
self.failUnless(f(b"") in b)
|
||||
self.failUnless(f(b"a") in b)
|
||||
self.failUnless(f(b"b") in b)
|
||||
self.failUnless(f(b"c") in b)
|
||||
self.failUnless(f(b"ab") in b)
|
||||
self.failUnless(f(b"bc") in b)
|
||||
self.failUnless(f(b"abc") in b)
|
||||
self.failIf(f(b"ac") in b)
|
||||
self.failIf(f(b"d") in b)
|
||||
self.failIf(f(b"dab") in b)
|
||||
self.failIf(f(b"abd") in b)
|
||||
self.assertTrue(f(b"") in b)
|
||||
self.assertTrue(f(b"a") in b)
|
||||
self.assertTrue(f(b"b") in b)
|
||||
self.assertTrue(f(b"c") in b)
|
||||
self.assertTrue(f(b"ab") in b)
|
||||
self.assertTrue(f(b"bc") in b)
|
||||
self.assertTrue(f(b"abc") in b)
|
||||
self.assertFalse(f(b"ac") in b)
|
||||
self.assertFalse(f(b"d") in b)
|
||||
self.assertFalse(f(b"dab") in b)
|
||||
self.assertFalse(f(b"abd") in b)
|
||||
|
||||
def test_fromhex(self):
|
||||
self.assertRaises(TypeError, self.type2test.fromhex)
|
||||
|
@ -600,7 +600,7 @@ class ByteArrayTest(BaseBytesTest):
|
|||
b += b"def"
|
||||
self.assertEqual(b, b"abcdef")
|
||||
self.assertEqual(b, b1)
|
||||
self.failUnless(b is b1)
|
||||
self.assertTrue(b is b1)
|
||||
b += b"xyz"
|
||||
self.assertEqual(b, b"abcdefxyz")
|
||||
try:
|
||||
|
@ -616,7 +616,7 @@ class ByteArrayTest(BaseBytesTest):
|
|||
b *= 3
|
||||
self.assertEqual(b, b"abcabcabc")
|
||||
self.assertEqual(b, b1)
|
||||
self.failUnless(b is b1)
|
||||
self.assertTrue(b is b1)
|
||||
|
||||
def test_irepeat_1char(self):
|
||||
b = bytearray(b"x")
|
||||
|
@ -624,17 +624,17 @@ class ByteArrayTest(BaseBytesTest):
|
|||
b *= 100
|
||||
self.assertEqual(b, b"x"*100)
|
||||
self.assertEqual(b, b1)
|
||||
self.failUnless(b is b1)
|
||||
self.assertTrue(b is b1)
|
||||
|
||||
def test_alloc(self):
|
||||
b = bytearray()
|
||||
alloc = b.__alloc__()
|
||||
self.assert_(alloc >= 0)
|
||||
self.assertTrue(alloc >= 0)
|
||||
seq = [alloc]
|
||||
for i in range(100):
|
||||
b += b"x"
|
||||
alloc = b.__alloc__()
|
||||
self.assert_(alloc >= len(b))
|
||||
self.assertTrue(alloc >= len(b))
|
||||
if alloc not in seq:
|
||||
seq.append(alloc)
|
||||
|
||||
|
@ -734,7 +734,7 @@ class ByteArrayTest(BaseBytesTest):
|
|||
a, b, c = bytearray(b"x").partition(b"y")
|
||||
self.assertEqual(b, b"")
|
||||
self.assertEqual(c, b"")
|
||||
self.assert_(b is not c)
|
||||
self.assertTrue(b is not c)
|
||||
b += b"!"
|
||||
self.assertEqual(c, b"")
|
||||
a, b, c = bytearray(b"x").partition(b"y")
|
||||
|
@ -744,7 +744,7 @@ class ByteArrayTest(BaseBytesTest):
|
|||
b, c, a = bytearray(b"x").rpartition(b"y")
|
||||
self.assertEqual(b, b"")
|
||||
self.assertEqual(c, b"")
|
||||
self.assert_(b is not c)
|
||||
self.assertTrue(b is not c)
|
||||
b += b"!"
|
||||
self.assertEqual(c, b"")
|
||||
c, b, a = bytearray(b"x").rpartition(b"y")
|
||||
|
@ -836,10 +836,10 @@ class AssortedBytesTest(unittest.TestCase):
|
|||
self.assertEqual(bytes(b"abc") <= b"ab", False)
|
||||
|
||||
def test_doc(self):
|
||||
self.failUnless(bytearray.__doc__ != None)
|
||||
self.failUnless(bytearray.__doc__.startswith("bytearray("), bytearray.__doc__)
|
||||
self.failUnless(bytes.__doc__ != None)
|
||||
self.failUnless(bytes.__doc__.startswith("bytes("), bytes.__doc__)
|
||||
self.assertTrue(bytearray.__doc__ != None)
|
||||
self.assertTrue(bytearray.__doc__.startswith("bytearray("), bytearray.__doc__)
|
||||
self.assertTrue(bytes.__doc__ != None)
|
||||
self.assertTrue(bytes.__doc__.startswith("bytes("), bytes.__doc__)
|
||||
|
||||
def test_from_bytearray(self):
|
||||
sample = bytes(b"Hello world\n\x80\x81\xfe\xff")
|
||||
|
@ -958,20 +958,20 @@ class ByteArraySubclass(bytearray):
|
|||
class ByteArraySubclassTest(unittest.TestCase):
|
||||
|
||||
def test_basic(self):
|
||||
self.assert_(issubclass(ByteArraySubclass, bytearray))
|
||||
self.assert_(isinstance(ByteArraySubclass(), bytearray))
|
||||
self.assertTrue(issubclass(ByteArraySubclass, bytearray))
|
||||
self.assertTrue(isinstance(ByteArraySubclass(), bytearray))
|
||||
|
||||
a, b = b"abcd", b"efgh"
|
||||
_a, _b = ByteArraySubclass(a), ByteArraySubclass(b)
|
||||
|
||||
# test comparison operators with subclass instances
|
||||
self.assert_(_a == _a)
|
||||
self.assert_(_a != _b)
|
||||
self.assert_(_a < _b)
|
||||
self.assert_(_a <= _b)
|
||||
self.assert_(_b >= _a)
|
||||
self.assert_(_b > _a)
|
||||
self.assert_(_a is not a)
|
||||
self.assertTrue(_a == _a)
|
||||
self.assertTrue(_a != _b)
|
||||
self.assertTrue(_a < _b)
|
||||
self.assertTrue(_a <= _b)
|
||||
self.assertTrue(_b >= _a)
|
||||
self.assertTrue(_b > _a)
|
||||
self.assertTrue(_a is not a)
|
||||
|
||||
# test concat of subclass instances
|
||||
self.assertEqual(a + b, _a + _b)
|
||||
|
@ -979,7 +979,7 @@ class ByteArraySubclassTest(unittest.TestCase):
|
|||
self.assertEqual(a + b, _a + b)
|
||||
|
||||
# test repeat
|
||||
self.assert_(a*5 == _a*5)
|
||||
self.assertTrue(a*5 == _a*5)
|
||||
|
||||
def test_join(self):
|
||||
# Make sure join returns a NEW object for single item sequences
|
||||
|
@ -987,12 +987,12 @@ class ByteArraySubclassTest(unittest.TestCase):
|
|||
# Make sure that it is of the appropriate type.
|
||||
s1 = ByteArraySubclass(b"abcd")
|
||||
s2 = bytearray().join([s1])
|
||||
self.assert_(s1 is not s2)
|
||||
self.assert_(type(s2) is bytearray, type(s2))
|
||||
self.assertTrue(s1 is not s2)
|
||||
self.assertTrue(type(s2) is bytearray, type(s2))
|
||||
|
||||
# Test reverse, calling join on subclass
|
||||
s3 = s1.join([b"abcd"])
|
||||
self.assert_(type(s3) is bytearray)
|
||||
self.assertTrue(type(s3) is bytearray)
|
||||
|
||||
def test_pickle(self):
|
||||
a = ByteArraySubclass(b"abcd")
|
||||
|
|
|
@ -41,7 +41,7 @@ class TestPendingCalls(unittest.TestCase):
|
|||
if context and not context.event.is_set():
|
||||
continue
|
||||
count += 1
|
||||
self.failUnless(count < 10000,
|
||||
self.assertTrue(count < 10000,
|
||||
"timeout waiting for %i callbacks, got %i"%(n, len(l)))
|
||||
if False and test_support.verbose:
|
||||
print "(%i)"%(len(l),)
|
||||
|
|
|
@ -81,16 +81,16 @@ class TestCaseBase(unittest.TestCase):
|
|||
eq(cf.get('Spaces', 'key with spaces'), 'value')
|
||||
eq(cf.get('Spaces', 'another with spaces'), 'splat!')
|
||||
|
||||
self.failIf('__name__' in cf.options("Foo Bar"),
|
||||
self.assertFalse('__name__' in cf.options("Foo Bar"),
|
||||
'__name__ "option" should not be exposed by the API!')
|
||||
|
||||
# Make sure the right things happen for remove_option();
|
||||
# added to include check for SourceForge bug #123324:
|
||||
self.failUnless(cf.remove_option('Foo Bar', 'foo'),
|
||||
self.assertTrue(cf.remove_option('Foo Bar', 'foo'),
|
||||
"remove_option() failed to report existence of option")
|
||||
self.failIf(cf.has_option('Foo Bar', 'foo'),
|
||||
self.assertFalse(cf.has_option('Foo Bar', 'foo'),
|
||||
"remove_option() failed to remove option")
|
||||
self.failIf(cf.remove_option('Foo Bar', 'foo'),
|
||||
self.assertFalse(cf.remove_option('Foo Bar', 'foo'),
|
||||
"remove_option() failed to report non-existence of option"
|
||||
" that was removed")
|
||||
|
||||
|
@ -112,10 +112,10 @@ class TestCaseBase(unittest.TestCase):
|
|||
eq(cf.options("a"), ["b"])
|
||||
eq(cf.get("a", "b"), "value",
|
||||
"could not locate option, expecting case-insensitive option names")
|
||||
self.failUnless(cf.has_option("a", "b"))
|
||||
self.assertTrue(cf.has_option("a", "b"))
|
||||
cf.set("A", "A-B", "A-B value")
|
||||
for opt in ("a-b", "A-b", "a-B", "A-B"):
|
||||
self.failUnless(
|
||||
self.assertTrue(
|
||||
cf.has_option("A", opt),
|
||||
"has_option() returned false for option which should exist")
|
||||
eq(cf.options("A"), ["a-b"])
|
||||
|
@ -132,7 +132,7 @@ class TestCaseBase(unittest.TestCase):
|
|||
# SF bug #561822:
|
||||
cf = self.fromstring("[section]\nnekey=nevalue\n",
|
||||
defaults={"key":"value"})
|
||||
self.failUnless(cf.has_option("section", "Key"))
|
||||
self.assertTrue(cf.has_option("section", "Key"))
|
||||
|
||||
|
||||
def test_default_case_sensitivity(self):
|
||||
|
@ -168,7 +168,7 @@ class TestCaseBase(unittest.TestCase):
|
|||
cf = self.newconfig()
|
||||
self.assertEqual(cf.sections(), [],
|
||||
"new ConfigParser should have no defined sections")
|
||||
self.failIf(cf.has_section("Foo"),
|
||||
self.assertFalse(cf.has_section("Foo"),
|
||||
"new ConfigParser should have no acknowledged sections")
|
||||
self.assertRaises(ConfigParser.NoSectionError,
|
||||
cf.options, "Foo")
|
||||
|
@ -207,8 +207,8 @@ class TestCaseBase(unittest.TestCase):
|
|||
"E5=FALSE AND MORE"
|
||||
)
|
||||
for x in range(1, 5):
|
||||
self.failUnless(cf.getboolean('BOOLTEST', 't%d' % x))
|
||||
self.failIf(cf.getboolean('BOOLTEST', 'f%d' % x))
|
||||
self.assertTrue(cf.getboolean('BOOLTEST', 't%d' % x))
|
||||
self.assertFalse(cf.getboolean('BOOLTEST', 'f%d' % x))
|
||||
self.assertRaises(ValueError,
|
||||
cf.getboolean, 'BOOLTEST', 'e%d' % x)
|
||||
|
||||
|
|
|
@ -151,10 +151,10 @@ class CgiTests(unittest.TestCase):
|
|||
# test individual fields
|
||||
for key in expect.keys():
|
||||
expect_val = expect[key]
|
||||
self.assert_(fcd.has_key(key))
|
||||
self.assertTrue(fcd.has_key(key))
|
||||
self.assertEqual(norm(fcd[key]), norm(expect[key]))
|
||||
self.assertEqual(fcd.get(key, "default"), fcd[key])
|
||||
self.assert_(fs.has_key(key))
|
||||
self.assertTrue(fs.has_key(key))
|
||||
if len(expect_val) > 1:
|
||||
single_value = 0
|
||||
else:
|
||||
|
@ -162,10 +162,10 @@ class CgiTests(unittest.TestCase):
|
|||
try:
|
||||
val = sd[key]
|
||||
except IndexError:
|
||||
self.failIf(single_value)
|
||||
self.assertFalse(single_value)
|
||||
self.assertEqual(fs.getvalue(key), expect_val)
|
||||
else:
|
||||
self.assert_(single_value)
|
||||
self.assertTrue(single_value)
|
||||
self.assertEqual(val, expect_val[0])
|
||||
self.assertEqual(fs.getvalue(key), expect_val[0])
|
||||
self.assertEqual(norm(sd.getlist(key)), norm(expect_val))
|
||||
|
@ -231,7 +231,7 @@ class CgiTests(unittest.TestCase):
|
|||
# if we're not chunking properly, readline is only called twice
|
||||
# (by read_binary); if we are chunking properly, it will be called 5 times
|
||||
# as long as the chunksize is 1 << 16.
|
||||
self.assert_(f.numcalls > 2)
|
||||
self.assertTrue(f.numcalls > 2)
|
||||
|
||||
def test_fieldstorage_multipart(self):
|
||||
#Test basic FieldStorage multipart parsing
|
||||
|
|
|
@ -416,7 +416,7 @@ class CMathTests(unittest.TestCase):
|
|||
|
||||
# real or imaginary part NaN
|
||||
for z in complex_nans:
|
||||
self.assert_(math.isnan(phase(z)))
|
||||
self.assertTrue(math.isnan(phase(z)))
|
||||
|
||||
def test_abs(self):
|
||||
# zeros
|
||||
|
@ -429,18 +429,18 @@ class CMathTests(unittest.TestCase):
|
|||
|
||||
# real or imaginary part NaN
|
||||
self.assertEqual(abs(complex(NAN, -INF)), INF)
|
||||
self.assert_(math.isnan(abs(complex(NAN, -2.3))))
|
||||
self.assert_(math.isnan(abs(complex(NAN, -0.0))))
|
||||
self.assert_(math.isnan(abs(complex(NAN, 0.0))))
|
||||
self.assert_(math.isnan(abs(complex(NAN, 2.3))))
|
||||
self.assertTrue(math.isnan(abs(complex(NAN, -2.3))))
|
||||
self.assertTrue(math.isnan(abs(complex(NAN, -0.0))))
|
||||
self.assertTrue(math.isnan(abs(complex(NAN, 0.0))))
|
||||
self.assertTrue(math.isnan(abs(complex(NAN, 2.3))))
|
||||
self.assertEqual(abs(complex(NAN, INF)), INF)
|
||||
self.assertEqual(abs(complex(-INF, NAN)), INF)
|
||||
self.assert_(math.isnan(abs(complex(-2.3, NAN))))
|
||||
self.assert_(math.isnan(abs(complex(-0.0, NAN))))
|
||||
self.assert_(math.isnan(abs(complex(0.0, NAN))))
|
||||
self.assert_(math.isnan(abs(complex(2.3, NAN))))
|
||||
self.assertTrue(math.isnan(abs(complex(-2.3, NAN))))
|
||||
self.assertTrue(math.isnan(abs(complex(-0.0, NAN))))
|
||||
self.assertTrue(math.isnan(abs(complex(0.0, NAN))))
|
||||
self.assertTrue(math.isnan(abs(complex(2.3, NAN))))
|
||||
self.assertEqual(abs(complex(INF, NAN)), INF)
|
||||
self.assert_(math.isnan(abs(complex(NAN, NAN))))
|
||||
self.assertTrue(math.isnan(abs(complex(NAN, NAN))))
|
||||
|
||||
# result overflows
|
||||
if float.__getformat__("double").startswith("IEEE"):
|
||||
|
@ -459,26 +459,26 @@ class CMathTests(unittest.TestCase):
|
|||
self.assertCEqual(rect(1, -pi/2), (0, -1.))
|
||||
|
||||
def test_isnan(self):
|
||||
self.failIf(cmath.isnan(1))
|
||||
self.failIf(cmath.isnan(1j))
|
||||
self.failIf(cmath.isnan(INF))
|
||||
self.assert_(cmath.isnan(NAN))
|
||||
self.assert_(cmath.isnan(complex(NAN, 0)))
|
||||
self.assert_(cmath.isnan(complex(0, NAN)))
|
||||
self.assert_(cmath.isnan(complex(NAN, NAN)))
|
||||
self.assert_(cmath.isnan(complex(NAN, INF)))
|
||||
self.assert_(cmath.isnan(complex(INF, NAN)))
|
||||
self.assertFalse(cmath.isnan(1))
|
||||
self.assertFalse(cmath.isnan(1j))
|
||||
self.assertFalse(cmath.isnan(INF))
|
||||
self.assertTrue(cmath.isnan(NAN))
|
||||
self.assertTrue(cmath.isnan(complex(NAN, 0)))
|
||||
self.assertTrue(cmath.isnan(complex(0, NAN)))
|
||||
self.assertTrue(cmath.isnan(complex(NAN, NAN)))
|
||||
self.assertTrue(cmath.isnan(complex(NAN, INF)))
|
||||
self.assertTrue(cmath.isnan(complex(INF, NAN)))
|
||||
|
||||
def test_isinf(self):
|
||||
self.failIf(cmath.isinf(1))
|
||||
self.failIf(cmath.isinf(1j))
|
||||
self.failIf(cmath.isinf(NAN))
|
||||
self.assert_(cmath.isinf(INF))
|
||||
self.assert_(cmath.isinf(complex(INF, 0)))
|
||||
self.assert_(cmath.isinf(complex(0, INF)))
|
||||
self.assert_(cmath.isinf(complex(INF, INF)))
|
||||
self.assert_(cmath.isinf(complex(NAN, INF)))
|
||||
self.assert_(cmath.isinf(complex(INF, NAN)))
|
||||
self.assertFalse(cmath.isinf(1))
|
||||
self.assertFalse(cmath.isinf(1j))
|
||||
self.assertFalse(cmath.isinf(NAN))
|
||||
self.assertTrue(cmath.isinf(INF))
|
||||
self.assertTrue(cmath.isinf(complex(INF, 0)))
|
||||
self.assertTrue(cmath.isinf(complex(0, INF)))
|
||||
self.assertTrue(cmath.isinf(complex(INF, INF)))
|
||||
self.assertTrue(cmath.isinf(complex(NAN, INF)))
|
||||
self.assertTrue(cmath.isinf(complex(INF, NAN)))
|
||||
|
||||
|
||||
def test_main():
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue