Commit 5c8da86f authored by Benjamin Peterson's avatar Benjamin Peterson

convert usage of fail* to assert*

parent be96cf60
......@@ -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()
This diff is collapsed.
......@@ -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__":
......
This diff is collapsed.
......@@ -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()
This diff is collapsed.
......@@ -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_", [])
......
This diff is collapsed.
......@@ -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'
......
This diff is collapsed.
This diff is collapsed.
......@@ -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, )
......
This diff is collapsed.
This diff is collapsed.
......@@ -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)
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment