diff options
Diffstat (limited to 'Lib/ctypes')
47 files changed, 933 insertions, 933 deletions
diff --git a/Lib/ctypes/test/test_anon.py b/Lib/ctypes/test/test_anon.py index 99e02cb..d892b59 100644 --- a/Lib/ctypes/test/test_anon.py +++ b/Lib/ctypes/test/test_anon.py @@ -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() diff --git a/Lib/ctypes/test/test_array_in_pointer.py b/Lib/ctypes/test/test_array_in_pointer.py index 6bed1f1..ca1edcf 100644 --- a/Lib/ctypes/test/test_array_in_pointer.py +++ b/Lib/ctypes/test/test_array_in_pointer.py @@ -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") ) diff --git a/Lib/ctypes/test/test_arrays.py b/Lib/ctypes/test/test_arrays.py index 8b5476d..c0cdfd5 100644 --- a/Lib/ctypes/test/test_arrays.py +++ b/Lib/ctypes/test/test_arrays.py @@ -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 = list(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], b"a") - self.failUnlessEqual(ca[1], b"b") - self.failUnlessEqual(ca[2], b"c") - self.failUnlessEqual(ca[-3], b"a") - self.failUnlessEqual(ca[-2], b"b") - self.failUnlessEqual(ca[-1], b"c") + self.assertEqual(ca[0], b"a") + self.assertEqual(ca[1], b"b") + self.assertEqual(ca[2], b"c") + self.assertEqual(ca[-3], b"a") + self.assertEqual(ca[-2], b"b") + self.assertEqual(ca[-1], b"c") - self.failUnlessEqual(len(ca), 3) + self.assertEqual(len(ca), 3) # cannot delete items from operator import delitem @@ -69,34 +69,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[:], b"foo") - self.failUnlessEqual(sz[::], b"foo") - self.failUnlessEqual(sz[::-1], b"oof") - self.failUnlessEqual(sz[::3], b"f") - self.failUnlessEqual(sz[1:4:2], b"o") - self.failUnlessEqual(sz.value, b"foo") + self.assertEqual(sz[:], b"foo") + self.assertEqual(sz[::], b"foo") + self.assertEqual(sz[::-1], b"oof") + self.assertEqual(sz[::3], b"f") + self.assertEqual(sz[1:4:2], b"o") + self.assertEqual(sz.value, b"foo") try: create_unicode_buffer @@ -106,12 +106,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, @@ -125,7 +125,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() diff --git a/Lib/ctypes/test/test_as_parameter.py b/Lib/ctypes/test/test_as_parameter.py index 884361c..835398f 100644 --- a/Lib/ctypes/test/test_as_parameter.py +++ b/Lib/ctypes/test/test_as_parameter.py @@ -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("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)) + self.assertTrue(isinstance(value, int)) 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)) #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/Lib/ctypes/test/test_bitfields.py b/Lib/ctypes/test/test_bitfields.py index de1c619..4eb9571 100644 --- a/Lib/ctypes/test/test_bitfields.py +++ b/Lib/ctypes/test/test_bitfields.py @@ -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 diff --git a/Lib/ctypes/test/test_buffers.py b/Lib/ctypes/test/test_buffers.py index 1f4091e..3f8a587 100644 --- a/Lib/ctypes/test/test_buffers.py +++ b/Lib/ctypes/test/test_buffers.py @@ -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 bytes) + self.assertEqual(len(b), 32) + self.assertEqual(sizeof(b), 32 * sizeof(c_char)) + self.assertTrue(type(b[0]) is bytes) 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 bytes) - self.failUnlessEqual(b[0], b"a") - self.failUnlessEqual(b[:], b"abc\0") - self.failUnlessEqual(b[::], b"abc\0") - self.failUnlessEqual(b[::-1], b"\0cba") - self.failUnlessEqual(b[::2], b"ac") - self.failUnlessEqual(b[::5], b"a") + self.assertEqual(len(b), 4) # trailing nul char + self.assertEqual(sizeof(b), 4 * sizeof(c_char)) + self.assertTrue(type(b[0]) is bytes) + self.assertEqual(b[0], b"a") + self.assertEqual(b[:], b"abc\0") + self.assertEqual(b[::], b"abc\0") + self.assertEqual(b[::-1], b"\0cba") + self.assertEqual(b[::2], b"ac") + self.assertEqual(b[::5], b"a") def test_string_conversion(self): 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 bytes) - self.failUnlessEqual(b[0], b"a") - self.failUnlessEqual(b[:], b"abc\0") - self.failUnlessEqual(b[::], b"abc\0") - self.failUnlessEqual(b[::-1], b"\0cba") - self.failUnlessEqual(b[::2], b"ac") - self.failUnlessEqual(b[::5], b"a") + self.assertEqual(len(b), 4) # trailing nul char + self.assertEqual(sizeof(b), 4 * sizeof(c_char)) + self.assertTrue(type(b[0]) is bytes) + self.assertEqual(b[0], b"a") + self.assertEqual(b[:], b"abc\0") + self.assertEqual(b[::], b"abc\0") + self.assertEqual(b[::-1], b"\0cba") + self.assertEqual(b[::2], b"ac") + self.assertEqual(b[::5], b"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 str) + self.assertEqual(len(b), 32) + self.assertEqual(sizeof(b), 32 * sizeof(c_wchar)) + self.assertTrue(type(b[0]) is str) 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 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_wchar)) + 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_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 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_wchar)) + 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") if __name__ == "__main__": unittest.main() diff --git a/Lib/ctypes/test/test_byteswap.py b/Lib/ctypes/test/test_byteswap.py index 67fa44b..83cb667 100644 --- a/Lib/ctypes/test/test_byteswap.py +++ b/Lib/ctypes/test/test_byteswap.py @@ -23,131 +23,131 @@ class Test(unittest.TestCase): def test_endian_short(self): if sys.byteorder == "little": - self.failUnless(c_short.__ctype_le__ is c_short) - self.failUnless(c_short.__ctype_be__.__ctype_le__ is c_short) + self.assertTrue(c_short.__ctype_le__ is c_short) + self.assertTrue(c_short.__ctype_be__.__ctype_le__ is c_short) else: - self.failUnless(c_short.__ctype_be__ is c_short) - self.failUnless(c_short.__ctype_le__.__ctype_be__ is c_short) + self.assertTrue(c_short.__ctype_be__ is c_short) + self.assertTrue(c_short.__ctype_le__.__ctype_be__ is c_short) s = c_short.__ctype_be__(0x1234) - self.failUnlessEqual(bin(struct.pack(">h", 0x1234)), "1234") - self.failUnlessEqual(bin(s), "1234") - self.failUnlessEqual(s.value, 0x1234) + self.assertEqual(bin(struct.pack(">h", 0x1234)), "1234") + self.assertEqual(bin(s), "1234") + self.assertEqual(s.value, 0x1234) s = c_short.__ctype_le__(0x1234) - self.failUnlessEqual(bin(struct.pack("<h", 0x1234)), "3412") - self.failUnlessEqual(bin(s), "3412") - self.failUnlessEqual(s.value, 0x1234) + self.assertEqual(bin(struct.pack("<h", 0x1234)), "3412") + self.assertEqual(bin(s), "3412") + self.assertEqual(s.value, 0x1234) s = c_ushort.__ctype_be__(0x1234) - self.failUnlessEqual(bin(struct.pack(">h", 0x1234)), "1234") - self.failUnlessEqual(bin(s), "1234") - self.failUnlessEqual(s.value, 0x1234) + self.assertEqual(bin(struct.pack(">h", 0x1234)), "1234") + self.assertEqual(bin(s), "1234") + self.assertEqual(s.value, 0x1234) s = c_ushort.__ctype_le__(0x1234) - self.failUnlessEqual(bin(struct.pack("<h", 0x1234)), "3412") - self.failUnlessEqual(bin(s), "3412") - self.failUnlessEqual(s.value, 0x1234) + self.assertEqual(bin(struct.pack("<h", 0x1234)), "3412") + self.assertEqual(bin(s), "3412") + self.assertEqual(s.value, 0x1234) def test_endian_int(self): if sys.byteorder == "little": - self.failUnless(c_int.__ctype_le__ is c_int) - self.failUnless(c_int.__ctype_be__.__ctype_le__ is c_int) + self.assertTrue(c_int.__ctype_le__ is c_int) + self.assertTrue(c_int.__ctype_be__.__ctype_le__ is c_int) else: - self.failUnless(c_int.__ctype_be__ is c_int) - self.failUnless(c_int.__ctype_le__.__ctype_be__ is c_int) + self.assertTrue(c_int.__ctype_be__ is c_int) + self.assertTrue(c_int.__ctype_le__.__ctype_be__ is c_int) s = c_int.__ctype_be__(0x12345678) - self.failUnlessEqual(bin(struct.pack(">i", 0x12345678)), "12345678") - self.failUnlessEqual(bin(s), "12345678") - self.failUnlessEqual(s.value, 0x12345678) + self.assertEqual(bin(struct.pack(">i", 0x12345678)), "12345678") + self.assertEqual(bin(s), "12345678") + self.assertEqual(s.value, 0x12345678) s = c_int.__ctype_le__(0x12345678) - self.failUnlessEqual(bin(struct.pack("<i", 0x12345678)), "78563412") - self.failUnlessEqual(bin(s), "78563412") - self.failUnlessEqual(s.value, 0x12345678) + self.assertEqual(bin(struct.pack("<i", 0x12345678)), "78563412") + self.assertEqual(bin(s), "78563412") + self.assertEqual(s.value, 0x12345678) s = c_uint.__ctype_be__(0x12345678) - self.failUnlessEqual(bin(struct.pack(">I", 0x12345678)), "12345678") - self.failUnlessEqual(bin(s), "12345678") - self.failUnlessEqual(s.value, 0x12345678) + self.assertEqual(bin(struct.pack(">I", 0x12345678)), "12345678") + self.assertEqual(bin(s), "12345678") + self.assertEqual(s.value, 0x12345678) s = c_uint.__ctype_le__(0x12345678) - self.failUnlessEqual(bin(struct.pack("<I", 0x12345678)), "78563412") - self.failUnlessEqual(bin(s), "78563412") - self.failUnlessEqual(s.value, 0x12345678) + self.assertEqual(bin(struct.pack("<I", 0x12345678)), "78563412") + self.assertEqual(bin(s), "78563412") + self.assertEqual(s.value, 0x12345678) def test_endian_longlong(self): if sys.byteorder == "little": - self.failUnless(c_longlong.__ctype_le__ is c_longlong) - self.failUnless(c_longlong.__ctype_be__.__ctype_le__ is c_longlong) + self.assertTrue(c_longlong.__ctype_le__ is c_longlong) + self.assertTrue(c_longlong.__ctype_be__.__ctype_le__ is c_longlong) else: - self.failUnless(c_longlong.__ctype_be__ is c_longlong) - self.failUnless(c_longlong.__ctype_le__.__ctype_be__ is c_longlong) + self.assertTrue(c_longlong.__ctype_be__ is c_longlong) + self.assertTrue(c_longlong.__ctype_le__.__ctype_be__ is c_longlong) s = c_longlong.__ctype_be__(0x1234567890ABCDEF) - self.failUnlessEqual(bin(struct.pack(">q", 0x1234567890ABCDEF)), "1234567890ABCDEF") - self.failUnlessEqual(bin(s), "1234567890ABCDEF") - self.failUnlessEqual(s.value, 0x1234567890ABCDEF) + self.assertEqual(bin(struct.pack(">q", 0x1234567890ABCDEF)), "1234567890ABCDEF") + self.assertEqual(bin(s), "1234567890ABCDEF") + self.assertEqual(s.value, 0x1234567890ABCDEF) s = c_longlong.__ctype_le__(0x1234567890ABCDEF) - self.failUnlessEqual(bin(struct.pack("<q", 0x1234567890ABCDEF)), "EFCDAB9078563412") - self.failUnlessEqual(bin(s), "EFCDAB9078563412") - self.failUnlessEqual(s.value, 0x1234567890ABCDEF) + self.assertEqual(bin(struct.pack("<q", 0x1234567890ABCDEF)), "EFCDAB9078563412") + self.assertEqual(bin(s), "EFCDAB9078563412") + self.assertEqual(s.value, 0x1234567890ABCDEF) s = c_ulonglong.__ctype_be__(0x1234567890ABCDEF) - self.failUnlessEqual(bin(struct.pack(">Q", 0x1234567890ABCDEF)), "1234567890ABCDEF") - self.failUnlessEqual(bin(s), "1234567890ABCDEF") - self.failUnlessEqual(s.value, 0x1234567890ABCDEF) + self.assertEqual(bin(struct.pack(">Q", 0x1234567890ABCDEF)), "1234567890ABCDEF") + self.assertEqual(bin(s), "1234567890ABCDEF") + self.assertEqual(s.value, 0x1234567890ABCDEF) s = c_ulonglong.__ctype_le__(0x1234567890ABCDEF) - self.failUnlessEqual(bin(struct.pack("<Q", 0x1234567890ABCDEF)), "EFCDAB9078563412") - self.failUnlessEqual(bin(s), "EFCDAB9078563412") - self.failUnlessEqual(s.value, 0x1234567890ABCDEF) + self.assertEqual(bin(struct.pack("<Q", 0x1234567890ABCDEF)), "EFCDAB9078563412") + self.assertEqual(bin(s), "EFCDAB9078563412") + self.assertEqual(s.value, 0x1234567890ABCDEF) def test_endian_float(self): if sys.byteorder == "little": - self.failUnless(c_float.__ctype_le__ is c_float) - self.failUnless(c_float.__ctype_be__.__ctype_le__ is c_float) + self.assertTrue(c_float.__ctype_le__ is c_float) + self.assertTrue(c_float.__ctype_be__.__ctype_le__ is c_float) else: - self.failUnless(c_float.__ctype_be__ is c_float) - self.failUnless(c_float.__ctype_le__.__ctype_be__ is c_float) + self.assertTrue(c_float.__ctype_be__ is c_float) + self.assertTrue(c_float.__ctype_le__.__ctype_be__ is c_float) s = c_float(math.pi) - self.failUnlessEqual(bin(struct.pack("f", math.pi)), bin(s)) + self.assertEqual(bin(struct.pack("f", math.pi)), bin(s)) # Hm, what's the precision of a float compared to a double? - self.failUnlessAlmostEqual(s.value, math.pi, places=6) + self.assertAlmostEqual(s.value, math.pi, places=6) s = c_float.__ctype_le__(math.pi) - self.failUnlessAlmostEqual(s.value, math.pi, places=6) - self.failUnlessEqual(bin(struct.pack("<f", math.pi)), bin(s)) + self.assertAlmostEqual(s.value, math.pi, places=6) + self.assertEqual(bin(struct.pack("<f", math.pi)), bin(s)) s = c_float.__ctype_be__(math.pi) - self.failUnlessAlmostEqual(s.value, math.pi, places=6) - self.failUnlessEqual(bin(struct.pack(">f", math.pi)), bin(s)) + self.assertAlmostEqual(s.value, math.pi, places=6) + self.assertEqual(bin(struct.pack(">f", math.pi)), bin(s)) def test_endian_double(self): if sys.byteorder == "little": - self.failUnless(c_double.__ctype_le__ is c_double) - self.failUnless(c_double.__ctype_be__.__ctype_le__ is c_double) + self.assertTrue(c_double.__ctype_le__ is c_double) + self.assertTrue(c_double.__ctype_be__.__ctype_le__ is c_double) else: - self.failUnless(c_double.__ctype_be__ is c_double) - self.failUnless(c_double.__ctype_le__.__ctype_be__ is c_double) + self.assertTrue(c_double.__ctype_be__ is c_double) + self.assertTrue(c_double.__ctype_le__.__ctype_be__ is c_double) s = c_double(math.pi) - self.failUnlessEqual(s.value, math.pi) - self.failUnlessEqual(bin(struct.pack("d", math.pi)), bin(s)) + self.assertEqual(s.value, math.pi) + self.assertEqual(bin(struct.pack("d", math.pi)), bin(s)) s = c_double.__ctype_le__(math.pi) - self.failUnlessEqual(s.value, math.pi) - self.failUnlessEqual(bin(struct.pack("<d", math.pi)), bin(s)) + self.assertEqual(s.value, math.pi) + self.assertEqual(bin(struct.pack("<d", math.pi)), bin(s)) s = c_double.__ctype_be__(math.pi) - self.failUnlessEqual(s.value, math.pi) - self.failUnlessEqual(bin(struct.pack(">d", math.pi)), bin(s)) + self.assertEqual(s.value, math.pi) + self.assertEqual(bin(struct.pack(">d", math.pi)), bin(s)) def test_endian_other(self): - self.failUnless(c_byte.__ctype_le__ is c_byte) - self.failUnless(c_byte.__ctype_be__ is c_byte) + self.assertTrue(c_byte.__ctype_le__ is c_byte) + self.assertTrue(c_byte.__ctype_be__ is c_byte) - self.failUnless(c_ubyte.__ctype_le__ is c_ubyte) - self.failUnless(c_ubyte.__ctype_be__ is c_ubyte) + self.assertTrue(c_ubyte.__ctype_le__ is c_ubyte) + self.assertTrue(c_ubyte.__ctype_be__ is c_ubyte) - self.failUnless(c_char.__ctype_le__ is c_char) - self.failUnless(c_char.__ctype_be__ is c_char) + self.assertTrue(c_char.__ctype_le__ is c_char) + self.assertTrue(c_char.__ctype_be__ is c_char) def test_struct_fields_1(self): if sys.byteorder == "little": @@ -219,7 +219,7 @@ class Test(unittest.TestCase): s1 = S(0x12, 0x1234, 0x12345678, 3.14) s2 = struct.pack(fmt, 0x12, 0x1234, 0x12345678, 3.14) - self.failUnlessEqual(bin(s1), bin(s2)) + self.assertEqual(bin(s1), bin(s2)) def test_unaligned_nonnative_struct_fields(self): if sys.byteorder == "little": @@ -247,7 +247,7 @@ class Test(unittest.TestCase): s1.i = 0x12345678 s1.d = 3.14 s2 = struct.pack(fmt, 0x12, 0x1234, 0x12345678, 3.14) - self.failUnlessEqual(bin(s1), bin(s2)) + self.assertEqual(bin(s1), bin(s2)) def test_unaligned_native_struct_fields(self): if sys.byteorder == "little": @@ -274,7 +274,7 @@ class Test(unittest.TestCase): s1.i = 0x12345678 s1.d = 3.14 s2 = struct.pack(fmt, 0x12, 0x1234, 0x12345678, 3.14) - self.failUnlessEqual(bin(s1), bin(s2)) + self.assertEqual(bin(s1), bin(s2)) if __name__ == "__main__": unittest.main() diff --git a/Lib/ctypes/test/test_callbacks.py b/Lib/ctypes/test/test_callbacks.py index bf580ae..1bef33f 100644 --- a/Lib/ctypes/test/test_callbacks.py +++ b/Lib/ctypes/test/test_callbacks.py @@ -17,18 +17,18 @@ class Callbacks(unittest.TestCase): PROTO = self.functype.__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.__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) ################################################################ diff --git a/Lib/ctypes/test/test_cast.py b/Lib/ctypes/test/test_cast.py index cb7524e..04ed5ca 100644 --- a/Lib/ctypes/test/test_cast.py +++ b/Lib/ctypes/test/test_cast.py @@ -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': b"foo bar"}) + self.assertEqual(array._objects, {'0': b"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': b"foo bar", id(array): array}) + self.assertTrue(p._objects is array._objects) + self.assertEqual(array._objects, {'0': b"foo bar", id(array): array}) p[0] = "spam spam" - self.failUnlessEqual(p._objects, {'0': b"spam spam", id(array): array}) - self.failUnless(array._objects is p._objects) + self.assertEqual(p._objects, {'0': b"spam spam", id(array): array}) + self.assertTrue(array._objects is p._objects) p[1] = "foo bar" - self.failUnlessEqual(p._objects, {'1': b'foo bar', '0': b"spam spam", id(array): array}) - self.failUnless(array._objects is p._objects) + self.assertEqual(p._objects, {'1': b'foo bar', '0': b"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__": diff --git a/Lib/ctypes/test/test_cfuncs.py b/Lib/ctypes/test/test_cfuncs.py index 8f97fc4..493cbe9 100644 --- a/Lib/ctypes/test/test_cfuncs.py +++ b/Lib/ctypes/test/test_cfuncs.py @@ -17,176 +17,176 @@ class CFunctions(unittest.TestCase): def test_byte(self): self._dll.tf_b.restype = c_byte self._dll.tf_b.argtypes = (c_byte,) - self.failUnlessEqual(self._dll.tf_b(-126), -42) - self.failUnlessEqual(self.S(), -126) + self.assertEqual(self._dll.tf_b(-126), -42) + self.assertEqual(self.S(), -126) def test_byte_plus(self): self._dll.tf_bb.restype = c_byte self._dll.tf_bb.argtypes = (c_byte, c_byte) - self.failUnlessEqual(self._dll.tf_bb(0, -126), -42) - self.failUnlessEqual(self.S(), -126) + self.assertEqual(self._dll.tf_bb(0, -126), -42) + self.assertEqual(self.S(), -126) def test_ubyte(self): self._dll.tf_B.restype = c_ubyte self._dll.tf_B.argtypes = (c_ubyte,) - self.failUnlessEqual(self._dll.tf_B(255), 85) - self.failUnlessEqual(self.U(), 255) + self.assertEqual(self._dll.tf_B(255), 85) + self.assertEqual(self.U(), 255) def test_ubyte_plus(self): self._dll.tf_bB.restype = c_ubyte self._dll.tf_bB.argtypes = (c_byte, c_ubyte) - self.failUnlessEqual(self._dll.tf_bB(0, 255), 85) - self.failUnlessEqual(self.U(), 255) + self.assertEqual(self._dll.tf_bB(0, 255), 85) + self.assertEqual(self.U(), 255) def test_short(self): self._dll.tf_h.restype = c_short self._dll.tf_h.argtypes = (c_short,) - self.failUnlessEqual(self._dll.tf_h(-32766), -10922) - self.failUnlessEqual(self.S(), -32766) + self.assertEqual(self._dll.tf_h(-32766), -10922) + self.assertEqual(self.S(), -32766) def test_short_plus(self): self._dll.tf_bh.restype = c_short self._dll.tf_bh.argtypes = (c_byte, c_short) - self.failUnlessEqual(self._dll.tf_bh(0, -32766), -10922) - self.failUnlessEqual(self.S(), -32766) + self.assertEqual(self._dll.tf_bh(0, -32766), -10922) + self.assertEqual(self.S(), -32766) def test_ushort(self): self._dll.tf_H.restype = c_ushort self._dll.tf_H.argtypes = (c_ushort,) - self.failUnlessEqual(self._dll.tf_H(65535), 21845) - self.failUnlessEqual(self.U(), 65535) + self.assertEqual(self._dll.tf_H(65535), 21845) + self.assertEqual(self.U(), 65535) def test_ushort_plus(self): self._dll.tf_bH.restype = c_ushort self._dll.tf_bH.argtypes = (c_byte, c_ushort) - self.failUnlessEqual(self._dll.tf_bH(0, 65535), 21845) - self.failUnlessEqual(self.U(), 65535) + self.assertEqual(self._dll.tf_bH(0, 65535), 21845) + self.assertEqual(self.U(), 65535) def test_int(self): self._dll.tf_i.restype = c_int self._dll.tf_i.argtypes = (c_int,) - self.failUnlessEqual(self._dll.tf_i(-2147483646), -715827882) - self.failUnlessEqual(self.S(), -2147483646) + self.assertEqual(self._dll.tf_i(-2147483646), -715827882) + self.assertEqual(self.S(), -2147483646) def test_int_plus(self): self._dll.tf_bi.restype = c_int self._dll.tf_bi.argtypes = (c_byte, c_int) - self.failUnlessEqual(self._dll.tf_bi(0, -2147483646), -715827882) - self.failUnlessEqual(self.S(), -2147483646) + self.assertEqual(self._dll.tf_bi(0, -2147483646), -715827882) + self.assertEqual(self.S(), -2147483646) def test_uint(self): self._dll.tf_I.restype = c_uint self._dll.tf_I.argtypes = (c_uint,) - self.failUnlessEqual(self._dll.tf_I(4294967295), 1431655765) - self.failUnlessEqual(self.U(), 4294967295) + self.assertEqual(self._dll.tf_I(4294967295), 1431655765) + self.assertEqual(self.U(), 4294967295) def test_uint_plus(self): self._dll.tf_bI.restype = c_uint self._dll.tf_bI.argtypes = (c_byte, c_uint) - self.failUnlessEqual(self._dll.tf_bI(0, 4294967295), 1431655765) - self.failUnlessEqual(self.U(), 4294967295) + self.assertEqual(self._dll.tf_bI(0, 4294967295), 1431655765) + self.assertEqual(self.U(), 4294967295) def test_long(self): self._dll.tf_l.restype = c_long self._dll.tf_l.argtypes = (c_long,) - self.failUnlessEqual(self._dll.tf_l(-2147483646), -715827882) - self.failUnlessEqual(self.S(), -2147483646) + self.assertEqual(self._dll.tf_l(-2147483646), -715827882) + self.assertEqual(self.S(), -2147483646) def test_long_plus(self): self._dll.tf_bl.restype = c_long self._dll.tf_bl.argtypes = (c_byte, c_long) - self.failUnlessEqual(self._dll.tf_bl(0, -2147483646), -715827882) - self.failUnlessEqual(self.S(), -2147483646) + self.assertEqual(self._dll.tf_bl(0, -2147483646), -715827882) + self.assertEqual(self.S(), -2147483646) def test_ulong(self): self._dll.tf_L.restype = c_ulong self._dll.tf_L.argtypes = (c_ulong,) - self.failUnlessEqual(self._dll.tf_L(4294967295), 1431655765) - self.failUnlessEqual(self.U(), 4294967295) + self.assertEqual(self._dll.tf_L(4294967295), 1431655765) + self.assertEqual(self.U(), 4294967295) def test_ulong_plus(self): self._dll.tf_bL.restype = c_ulong self._dll.tf_bL.argtypes = (c_char, c_ulong) - self.failUnlessEqual(self._dll.tf_bL(' ', 4294967295), 1431655765) - self.failUnlessEqual(self.U(), 4294967295) + self.assertEqual(self._dll.tf_bL(' ', 4294967295), 1431655765) + self.assertEqual(self.U(), 4294967295) def test_longlong(self): self._dll.tf_q.restype = c_longlong self._dll.tf_q.argtypes = (c_longlong, ) - self.failUnlessEqual(self._dll.tf_q(-9223372036854775806), -3074457345618258602) - self.failUnlessEqual(self.S(), -9223372036854775806) + self.assertEqual(self._dll.tf_q(-9223372036854775806), -3074457345618258602) + self.assertEqual(self.S(), -9223372036854775806) def test_longlong_plus(self): self._dll.tf_bq.restype = c_longlong self._dll.tf_bq.argtypes = (c_byte, c_longlong) - self.failUnlessEqual(self._dll.tf_bq(0, -9223372036854775806), -3074457345618258602) - self.failUnlessEqual(self.S(), -9223372036854775806) + self.assertEqual(self._dll.tf_bq(0, -9223372036854775806), -3074457345618258602) + self.assertEqual(self.S(), -9223372036854775806) def test_ulonglong(self): self._dll.tf_Q.restype = c_ulonglong self._dll.tf_Q.argtypes = (c_ulonglong, ) - self.failUnlessEqual(self._dll.tf_Q(18446744073709551615), 6148914691236517205) - self.failUnlessEqual(self.U(), 18446744073709551615) + self.assertEqual(self._dll.tf_Q(18446744073709551615), 6148914691236517205) + self.assertEqual(self.U(), 18446744073709551615) def test_ulonglong_plus(self): self._dll.tf_bQ.restype = c_ulonglong self._dll.tf_bQ.argtypes = (c_byte, c_ulonglong) - self.failUnlessEqual(self._dll.tf_bQ(0, 18446744073709551615), 6148914691236517205) - self.failUnlessEqual(self.U(), 18446744073709551615) + self.assertEqual(self._dll.tf_bQ(0, 18446744073709551615), 6148914691236517205) + self.assertEqual(self.U(), 18446744073709551615) def test_float(self): self._dll.tf_f.restype = c_float self._dll.tf_f.argtypes = (c_float,) - self.failUnlessEqual(self._dll.tf_f(-42.), -14.) - self.failUnlessEqual(self.S(), -42) + self.assertEqual(self._dll.tf_f(-42.), -14.) + self.assertEqual(self.S(), -42) def test_float_plus(self): self._dll.tf_bf.restype = c_float self._dll.tf_bf.argtypes = (c_byte, c_float) - self.failUnlessEqual(self._dll.tf_bf(0, -42.), -14.) - self.failUnlessEqual(self.S(), -42) + self.assertEqual(self._dll.tf_bf(0, -42.), -14.) + self.assertEqual(self.S(), -42) def test_double(self): self._dll.tf_d.restype = c_double self._dll.tf_d.argtypes = (c_double,) - self.failUnlessEqual(self._dll.tf_d(42.), 14.) - self.failUnlessEqual(self.S(), 42) + self.assertEqual(self._dll.tf_d(42.), 14.) + self.assertEqual(self.S(), 42) def test_double_plus(self): self._dll.tf_bd.restype = c_double self._dll.tf_bd.argtypes = (c_byte, c_double) - self.failUnlessEqual(self._dll.tf_bd(0, 42.), 14.) - self.failUnlessEqual(self.S(), 42) + self.assertEqual(self._dll.tf_bd(0, 42.), 14.) + self.assertEqual(self.S(), 42) def test_longdouble(self): self._dll.tf_D.restype = c_longdouble self._dll.tf_D.argtypes = (c_longdouble,) - self.failUnlessEqual(self._dll.tf_D(42.), 14.) - self.failUnlessEqual(self.S(), 42) + self.assertEqual(self._dll.tf_D(42.), 14.) + self.assertEqual(self.S(), 42) def test_longdouble_plus(self): self._dll.tf_bD.restype = c_longdouble self._dll.tf_bD.argtypes = (c_byte, c_longdouble) - self.failUnlessEqual(self._dll.tf_bD(0, 42.), 14.) - self.failUnlessEqual(self.S(), 42) + self.assertEqual(self._dll.tf_bD(0, 42.), 14.) + self.assertEqual(self.S(), 42) def test_callwithresult(self): def process_result(result): return result * 2 self._dll.tf_i.restype = process_result self._dll.tf_i.argtypes = (c_int,) - self.failUnlessEqual(self._dll.tf_i(42), 28) - self.failUnlessEqual(self.S(), 42) - self.failUnlessEqual(self._dll.tf_i(-42), -28) - self.failUnlessEqual(self.S(), -42) + self.assertEqual(self._dll.tf_i(42), 28) + self.assertEqual(self.S(), 42) + self.assertEqual(self._dll.tf_i(-42), -28) + self.assertEqual(self.S(), -42) def test_void(self): self._dll.tv_i.restype = None self._dll.tv_i.argtypes = (c_int,) - self.failUnlessEqual(self._dll.tv_i(42), None) - self.failUnlessEqual(self.S(), 42) - self.failUnlessEqual(self._dll.tv_i(-42), None) - self.failUnlessEqual(self.S(), -42) + self.assertEqual(self._dll.tv_i(42), None) + self.assertEqual(self.S(), 42) + self.assertEqual(self._dll.tv_i(-42), None) + self.assertEqual(self.S(), -42) # The following repeates the above tests with stdcall functions (where # they are available) diff --git a/Lib/ctypes/test/test_checkretval.py b/Lib/ctypes/test/test_checkretval.py index d15bd2e..01ccc57 100644 --- a/Lib/ctypes/test/test_checkretval.py +++ b/Lib/ctypes/test/test_checkretval.py @@ -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) diff --git a/Lib/ctypes/test/test_errno.py b/Lib/ctypes/test/test_errno.py index b80656b..0254c3b 100644 --- a/Lib/ctypes/test/test_errno.py +++ b/Lib/ctypes/test/test_errno.py @@ -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) diff --git a/Lib/ctypes/test/test_find.py b/Lib/ctypes/test/test_find.py index dc05093..c54b69b 100644 --- a/Lib/ctypes/test/test_find.py +++ b/Lib/ctypes/test/test_find.py @@ -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() diff --git a/Lib/ctypes/test/test_frombuffer.py b/Lib/ctypes/test/test_frombuffer.py index 23e2dcb..92d6158 100644 --- a/Lib/ctypes/test/test_frombuffer.py +++ b/Lib/ctypes/test/test_frombuffer.py @@ -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[:], list(range(16))) diff --git a/Lib/ctypes/test/test_funcptr.py b/Lib/ctypes/test/test_funcptr.py index 56099cc..1b29317 100644 --- a/Lib/ctypes/test/test_funcptr.py +++ b/Lib/ctypes/test/test_funcptr.py @@ -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, b"\n"), "a") - self.failUnlessEqual(strtok(None, b"\n"), "b") - self.failUnlessEqual(strtok(None, b"\n"), "c") - self.failUnlessEqual(strtok(None, b"\n"), None) + self.assertEqual(strtok(b, b"\n"), "a") + self.assertEqual(strtok(None, b"\n"), "b") + self.assertEqual(strtok(None, b"\n"), "c") + self.assertEqual(strtok(None, b"\n"), None) if __name__ == '__main__': unittest.main() diff --git a/Lib/ctypes/test/test_functions.py b/Lib/ctypes/test/test_functions.py index 3af11cc..303ce07 100644 --- a/Lib/ctypes/test/test_functions.py +++ b/Lib/ctypes/test/test_functions.py @@ -71,8 +71,8 @@ class FunctionTestCase(unittest.TestCase): f = dll._testfunc_i_bhilfd f.argtypes = [c_byte, c_wchar, c_int, c_long, c_float, c_double] result = f(1, "x", 3, 4, 5.0, 6.0) - self.failUnlessEqual(result, 139) - self.failUnlessEqual(type(result), int) + self.assertEqual(result, 139) + self.assertEqual(type(result), int) def test_wchar_result(self): try: @@ -83,38 +83,38 @@ class FunctionTestCase(unittest.TestCase): f.argtypes = [c_byte, c_short, c_int, c_long, c_float, c_double] f.restype = c_wchar result = f(0, 0, 0, 0, 0, 0) - self.failUnlessEqual(result, '\x00') + self.assertEqual(result, '\x00') def test_voidresult(self): f = dll._testfunc_v f.restype = None f.argtypes = [c_int, c_int, POINTER(c_int)] result = c_int() - self.failUnlessEqual(None, f(1, 2, byref(result))) - self.failUnlessEqual(result.value, 3) + self.assertEqual(None, f(1, 2, byref(result))) + self.assertEqual(result.value, 3) def test_intresult(self): f = dll._testfunc_i_bhilfd f.argtypes = [c_byte, c_short, c_int, c_long, c_float, c_double] f.restype = c_int result = f(1, 2, 3, 4, 5.0, 6.0) - self.failUnlessEqual(result, 21) - self.failUnlessEqual(type(result), int) + self.assertEqual(result, 21) + self.assertEqual(type(result), int) result = f(-1, -2, -3, -4, -5.0, -6.0) - self.failUnlessEqual(result, -21) - self.failUnlessEqual(type(result), int) + self.assertEqual(result, -21) + self.assertEqual(type(result), int) # If we declare the function to return a short, # is the high part split off? f.restype = c_short result = f(1, 2, 3, 4, 5.0, 6.0) - self.failUnlessEqual(result, 21) - self.failUnlessEqual(type(result), int) + self.assertEqual(result, 21) + self.assertEqual(type(result), int) result = f(1, 2, 3, 0x10004, 5.0, 6.0) - self.failUnlessEqual(result, 21) - self.failUnlessEqual(type(result), int) + self.assertEqual(result, 21) + self.assertEqual(type(result), int) # You cannot assing character format codes as restype any longer self.assertRaises(TypeError, setattr, f, "restype", "i") @@ -124,36 +124,36 @@ class FunctionTestCase(unittest.TestCase): f.argtypes = [c_byte, c_short, c_int, c_long, c_float, c_double] f.restype = c_float result = f(1, 2, 3, 4, 5.0, 6.0) - self.failUnlessEqual(result, 21) - self.failUnlessEqual(type(result), float) + self.assertEqual(result, 21) + self.assertEqual(type(result), float) result = f(-1, -2, -3, -4, -5.0, -6.0) - self.failUnlessEqual(result, -21) - self.failUnlessEqual(type(result), float) + self.assertEqual(result, -21) + self.assertEqual(type(result), float) def test_doubleresult(self): f = dll._testfunc_d_bhilfd f.argtypes = [c_byte, c_short, c_int, c_long, c_float, c_double] f.restype = c_double result = f(1, 2, 3, 4, 5.0, 6.0) - self.failUnlessEqual(result, 21) - self.failUnlessEqual(type(result), float) + self.assertEqual(result, 21) + self.assertEqual(type(result), float) result = f(-1, -2, -3, -4, -5.0, -6.0) - self.failUnlessEqual(result, -21) - self.failUnlessEqual(type(result), float) + self.assertEqual(result, -21) + self.assertEqual(type(result), float) def test_longdoubleresult(self): f = dll._testfunc_D_bhilfD f.argtypes = [c_byte, c_short, c_int, c_long, c_float, c_longdouble] f.restype = c_longdouble result = f(1, 2, 3, 4, 5.0, 6.0) - self.failUnlessEqual(result, 21) - self.failUnlessEqual(type(result), float) + self.assertEqual(result, 21) + self.assertEqual(type(result), float) result = f(-1, -2, -3, -4, -5.0, -6.0) - self.failUnlessEqual(result, -21) - self.failUnlessEqual(type(result), float) + self.assertEqual(result, -21) + self.assertEqual(type(result), float) def test_longlongresult(self): try: @@ -164,23 +164,23 @@ class FunctionTestCase(unittest.TestCase): f.restype = c_longlong f.argtypes = [c_byte, c_short, c_int, c_long, c_float, c_double] result = f(1, 2, 3, 4, 5.0, 6.0) - self.failUnlessEqual(result, 21) + self.assertEqual(result, 21) f = dll._testfunc_q_bhilfdq f.restype = c_longlong f.argtypes = [c_byte, c_short, c_int, c_long, c_float, c_double, c_longlong] result = f(1, 2, 3, 4, 5.0, 6.0, 21) - self.failUnlessEqual(result, 42) + self.assertEqual(result, 42) def test_stringresult(self): f = dll._testfunc_p_p f.argtypes = None f.restype = c_char_p result = f(b"123") - self.failUnlessEqual(result, "123") + self.assertEqual(result, "123") result = f(None) - self.failUnlessEqual(result, None) + self.assertEqual(result, None) def test_pointers(self): f = dll._testfunc_p_p @@ -193,29 +193,29 @@ class FunctionTestCase(unittest.TestCase): v = c_int(42) - self.failUnlessEqual(pointer(v).contents.value, 42) + self.assertEqual(pointer(v).contents.value, 42) result = f(pointer(v)) - self.failUnlessEqual(type(result), POINTER(c_int)) - self.failUnlessEqual(result.contents.value, 42) + self.assertEqual(type(result), POINTER(c_int)) + self.assertEqual(result.contents.value, 42) # This on works... result = f(pointer(v)) - self.failUnlessEqual(result.contents.value, v.value) + self.assertEqual(result.contents.value, v.value) p = pointer(c_int(99)) result = f(p) - self.failUnlessEqual(result.contents.value, 99) + self.assertEqual(result.contents.value, 99) arg = byref(v) result = f(arg) - self.failIfEqual(result.contents, v.value) + self.assertNotEqual(result.contents, v.value) self.assertRaises(ArgumentError, f, byref(c_short(22))) # It is dangerous, however, because you don't control the lifetime # of the pointer: result = f(byref(c_int(99))) - self.failIfEqual(result.contents, 99) + self.assertNotEqual(result.contents, 99) def test_errors(self): f = dll._testfunc_p_p @@ -242,7 +242,7 @@ class FunctionTestCase(unittest.TestCase): cb = CallBack(callback) f(2**18, cb) - self.failUnlessEqual(args, expected) + self.assertEqual(args, expected) ################################################################ @@ -259,13 +259,13 @@ class FunctionTestCase(unittest.TestCase): cb = MyCallback(callback) result = f(-10, cb) - self.failUnlessEqual(result, -18) + self.assertEqual(result, -18) # test with prototype f.argtypes = [c_int, MyCallback] cb = MyCallback(callback) result = f(-10, cb) - self.failUnlessEqual(result, -18) + self.assertEqual(result, -18) AnotherCallback = WINFUNCTYPE(c_int, c_int, c_int, c_int, c_int) @@ -288,12 +288,12 @@ class FunctionTestCase(unittest.TestCase): def callback(value): #print "called back with", value - self.failUnlessEqual(type(value), int) + self.assertEqual(type(value), int) return value cb = MyCallback(callback) result = f(-10, cb) - self.failUnlessEqual(result, -18) + self.assertEqual(result, -18) def test_longlong_callbacks(self): @@ -305,12 +305,12 @@ class FunctionTestCase(unittest.TestCase): f.argtypes = [c_longlong, MyCallback] def callback(value): - self.failUnless(isinstance(value, int)) + self.assertTrue(isinstance(value, int)) return value & 0x7FFFFFFF cb = MyCallback(callback) - self.failUnlessEqual(13577625587, f(1000000000000, cb)) + self.assertEqual(13577625587, f(1000000000000, cb)) def test_errors(self): self.assertRaises(AttributeError, getattr, dll, "_xxx_yyy") @@ -325,7 +325,7 @@ class FunctionTestCase(unittest.TestCase): result = dll._testfunc_byval(ptin, byref(ptout)) got = result, ptout.x, ptout.y expected = 3, 1, 2 - self.failUnlessEqual(got, expected) + self.assertEqual(got, expected) # with prototype ptin = POINT(101, 102) @@ -335,7 +335,7 @@ class FunctionTestCase(unittest.TestCase): result = dll._testfunc_byval(ptin, byref(ptout)) got = result, ptout.x, ptout.y expected = 203, 101, 102 - self.failUnlessEqual(got, expected) + self.assertEqual(got, expected) def test_struct_return_2H(self): class S2H(Structure): @@ -345,7 +345,7 @@ class FunctionTestCase(unittest.TestCase): dll.ret_2h_func.argtypes = [S2H] inp = S2H(99, 88) s2h = dll.ret_2h_func(inp) - self.failUnlessEqual((s2h.x, s2h.y), (99*2, 88*3)) + self.assertEqual((s2h.x, s2h.y), (99*2, 88*3)) if sys.platform == "win32": def test_struct_return_2H_stdcall(self): @@ -356,7 +356,7 @@ class FunctionTestCase(unittest.TestCase): windll.s_ret_2h_func.restype = S2H windll.s_ret_2h_func.argtypes = [S2H] s2h = windll.s_ret_2h_func(S2H(99, 88)) - self.failUnlessEqual((s2h.x, s2h.y), (99*2, 88*3)) + self.assertEqual((s2h.x, s2h.y), (99*2, 88*3)) def test_struct_return_8H(self): class S8I(Structure): @@ -372,7 +372,7 @@ class FunctionTestCase(unittest.TestCase): dll.ret_8i_func.argtypes = [S8I] inp = S8I(9, 8, 7, 6, 5, 4, 3, 2) s8i = dll.ret_8i_func(inp) - self.failUnlessEqual((s8i.a, s8i.b, s8i.c, s8i.d, s8i.e, s8i.f, s8i.g, s8i.h), + self.assertEqual((s8i.a, s8i.b, s8i.c, s8i.d, s8i.e, s8i.f, s8i.g, s8i.h), (9*2, 8*3, 7*4, 6*5, 5*6, 4*7, 3*8, 2*9)) if sys.platform == "win32": @@ -390,7 +390,7 @@ class FunctionTestCase(unittest.TestCase): windll.s_ret_8i_func.argtypes = [S8I] inp = S8I(9, 8, 7, 6, 5, 4, 3, 2) s8i = windll.s_ret_8i_func(inp) - self.failUnlessEqual((s8i.a, s8i.b, s8i.c, s8i.d, s8i.e, s8i.f, s8i.g, s8i.h), + self.assertEqual((s8i.a, s8i.b, s8i.c, s8i.d, s8i.e, s8i.f, s8i.g, s8i.h), (9*2, 8*3, 7*4, 6*5, 5*6, 4*7, 3*8, 2*9)) def test_sf1651235(self): @@ -401,7 +401,7 @@ class FunctionTestCase(unittest.TestCase): return 0 callback = proto(callback) - self.failUnlessRaises(ArgumentError, lambda: callback((1, 2, 3, 4), POINT())) + self.assertRaises(ArgumentError, lambda: callback((1, 2, 3, 4), POINT())) if __name__ == '__main__': unittest.main() diff --git a/Lib/ctypes/test/test_incomplete.py b/Lib/ctypes/test/test_incomplete.py index af9f504..1e03e9f 100644 --- a/Lib/ctypes/test/test_incomplete.py +++ b/Lib/ctypes/test/test_incomplete.py @@ -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 diff --git a/Lib/ctypes/test/test_init.py b/Lib/ctypes/test/test_init.py index e4dfe36..94928c8 100644 --- a/Lib/ctypes/test/test_init.py +++ b/Lib/ctypes/test/test_init.py @@ -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() diff --git a/Lib/ctypes/test/test_internals.py b/Lib/ctypes/test/test_internals.py index c6a51a7..f7d9a1b 100644 --- a/Lib/ctypes/test/test_internals.py +++ b/Lib/ctypes/test/test_internals.py @@ -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 rc = grc(i) ci = c_int(i) - self.failUnlessEqual(rc, grc(i)) - self.failUnlessEqual(ci._objects, None) + self.assertEqual(rc, grc(i)) + self.assertEqual(ci._objects, None) def test_c_char_p(self): s = b"Hello, World" rc = grc(s) cs = c_char_p(s) - self.failUnlessEqual(rc + 1, grc(s)) - self.failUnlessSame(cs._objects, s) + self.assertEqual(rc + 1, 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,12 +76,12 @@ class ObjectsTestCase(unittest.TestCase): x = X() x.a = s1 x.b = s2 - self.failUnlessEqual(x._objects, {"0": bytes(s1, "ascii"), + self.assertEqual(x._objects, {"0": bytes(s1, "ascii"), "1": bytes(s2, "ascii")}) y = Y() y.x = x - self.failUnlessEqual(y._objects, {"0": {"0": bytes(s1, "ascii"), + self.assertEqual(y._objects, {"0": {"0": bytes(s1, "ascii"), "1": bytes(s2, "ascii")}}) ## x = y.x ## del y @@ -93,7 +93,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 diff --git a/Lib/ctypes/test/test_keeprefs.py b/Lib/ctypes/test/test_keeprefs.py index 75e227c..b90765a 100644 --- a/Lib/ctypes/test/test_keeprefs.py +++ b/Lib/ctypes/test/test_keeprefs.py @@ -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): diff --git a/Lib/ctypes/test/test_libc.py b/Lib/ctypes/test/test_libc.py index fa4c0c9..cce409f 100644 --- a/Lib/ctypes/test/test_libc.py +++ b/Lib/ctypes/test/test_libc.py @@ -13,9 +13,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)) @@ -27,7 +27,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, b" ,,aaaadmmmnpppsss\x00") + self.assertEqual(chars.raw, b" ,,aaaadmmmnpppsss\x00") if __name__ == "__main__": unittest.main() diff --git a/Lib/ctypes/test/test_loading.py b/Lib/ctypes/test/test_loading.py index b83828a..07b69ec 100644 --- a/Lib/ctypes/test/test_loading.py +++ b/Lib/ctypes/test/test_loading.py @@ -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() diff --git a/Lib/ctypes/test/test_macholib.py b/Lib/ctypes/test/test_macholib.py index f2ee035..eda846d 100644 --- a/Lib/ctypes/test/test_macholib.py +++ b/Lib/ctypes/test/test_macholib.py @@ -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__": diff --git a/Lib/ctypes/test/test_memfunctions.py b/Lib/ctypes/test/test_memfunctions.py index 4bee77f..7082b55 100644 --- a/Lib/ctypes/test/test_memfunctions.py +++ b/Lib/ctypes/test/test_memfunctions.py @@ -19,45 +19,45 @@ class MemFunctionsTest(unittest.TestCase): a = create_string_buffer(1000000) p = b"Hello, World" result = memmove(a, p, len(p)) - self.failUnlessEqual(a.value, b"Hello, World") + self.assertEqual(a.value, b"Hello, World") - self.failUnlessEqual(string_at(result), b"Hello, World") - self.failUnlessEqual(string_at(result, 5), b"Hello") - self.failUnlessEqual(string_at(result, 16), b"Hello, World\0\0\0\0") - self.failUnlessEqual(string_at(result, 0), b"") + self.assertEqual(string_at(result), b"Hello, World") + self.assertEqual(string_at(result, 5), b"Hello") + self.assertEqual(string_at(result, 16), b"Hello, World\0\0\0\0") + self.assertEqual(string_at(result, 0), b"") def test_memset(self): a = create_string_buffer(1000000) result = memset(a, ord('x'), 16) - self.failUnlessEqual(a.value, b"xxxxxxxxxxxxxxxx") + self.assertEqual(a.value, b"xxxxxxxxxxxxxxxx") - self.failUnlessEqual(string_at(result), b"xxxxxxxxxxxxxxxx") - self.failUnlessEqual(string_at(a), b"xxxxxxxxxxxxxxxx") - self.failUnlessEqual(string_at(a, 20), b"xxxxxxxxxxxxxxxx\0\0\0\0") + self.assertEqual(string_at(result), b"xxxxxxxxxxxxxxxx") + self.assertEqual(string_at(a), b"xxxxxxxxxxxxxxxx") + self.assertEqual(string_at(a, 20), b"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(b"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(b"foo bar", 7), b"foo bar") - self.failUnlessEqual(string_at(b"foo bar", 3), b"foo") + self.assertEqual(string_at(b"foo bar", 7), b"foo bar") + self.assertEqual(string_at(b"foo bar", 3), b"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() diff --git a/Lib/ctypes/test/test_numbers.py b/Lib/ctypes/test/test_numbers.py index c0732de..24d7293 100644 --- a/Lib/ctypes/test/test_numbers.py +++ b/Lib/ctypes/test/test_numbers.py @@ -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(2).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(2).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 @@ -193,11 +193,11 @@ class NumberTestCase(unittest.TestCase): a = array('b', [0]) a[0] = ord('x') v = c_char.from_address(a.buffer_info()[0]) - self.failUnlessEqual(v.value, b'x') - self.failUnless(type(v) is c_char) + self.assertEqual(v.value, b'x') + self.assertTrue(type(v) is c_char) a[0] = ord('?') - self.failUnlessEqual(v.value, b'?') + self.assertEqual(v.value, b'?') # array does not support c_bool / 't' # def test_bool_from_address(self): @@ -205,11 +205,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. diff --git a/Lib/ctypes/test/test_parameters.py b/Lib/ctypes/test/test_parameters.py index 4c80bdf..10eddd4 100644 --- a/Lib/ctypes/test/test_parameters.py +++ b/Lib/ctypes/test/test_parameters.py @@ -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 = b"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("123")._obj, b"123") + self.assertEqual(c_char_p.from_param("123")._obj, b"123") self.assertRaises(UnicodeEncodeError, c_char_p.from_param, "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 = "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, "123") + self.assertEqual(c_wchar_p.from_param("123")._obj, "123") self.assertRaises(UnicodeDecodeError, c_wchar_p.from_param, b"123\377") pa = c_wchar_p.from_param(c_wchar_p("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): diff --git a/Lib/ctypes/test/test_pep3118.py b/Lib/ctypes/test/test_pep3118.py index b839ac2..fa6461f 100644 --- a/Lib/ctypes/test/test_pep3118.py +++ b/Lib/ctypes/test/test_pep3118.py @@ -24,23 +24,23 @@ class Test(unittest.TestCase): ob = tp() v = memoryview(ob) try: - self.failUnlessEqual(normalize(v.format), normalize(fmt)) + self.assertEqual(normalize(v.format), normalize(fmt)) if shape is not None: - self.failUnlessEqual(len(v), shape[0]) + self.assertEqual(len(v), shape[0]) else: - self.failUnlessEqual(len(v) * sizeof(itemtp), sizeof(ob)) - self.failUnlessEqual(v.itemsize, sizeof(itemtp)) - self.failUnlessEqual(v.shape, shape) + self.assertEqual(len(v) * sizeof(itemtp), 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(n * v.itemsize, len(v.tobytes())) + self.assertEqual(n * v.itemsize, len(v.tobytes())) except: # so that we can see the failing type print(tp) @@ -51,23 +51,23 @@ class Test(unittest.TestCase): ob = tp() v = memoryview(ob) try: - self.failUnlessEqual(v.format, fmt) + self.assertEqual(v.format, fmt) if shape is not None: - self.failUnlessEqual(len(v), shape[0]) + self.assertEqual(len(v), shape[0]) else: - self.failUnlessEqual(len(v) * sizeof(itemtp), sizeof(ob)) - self.failUnlessEqual(v.itemsize, sizeof(itemtp)) - self.failUnlessEqual(v.shape, shape) + self.assertEqual(len(v) * sizeof(itemtp), 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(n, len(v)) + self.assertEqual(n, len(v)) except: # so that we can see the failing type print(tp) diff --git a/Lib/ctypes/test/test_pickling.py b/Lib/ctypes/test/test_pickling.py index d88f08b..8c91222 100644 --- a/Lib/ctypes/test/test_pickling.py +++ b/Lib/ctypes/test/test_pickling.py @@ -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(memoryview(src).tobytes(), + self.assertEqual(src.__dict__, dst.__dict__) + self.assertEqual(memoryview(src).tobytes(), memoryview(dst).tobytes()) 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(memoryview(y).tobytes(), + self.assertEqual(y.__dict__, x.__dict__) + self.assertEqual(memoryview(y).tobytes(), memoryview(x).tobytes()) def test_unpickable(self): diff --git a/Lib/ctypes/test/test_pointers.py b/Lib/ctypes/test/test_pointers.py index 86429c0..6e61d30 100644 --- a/Lib/ctypes/test/test_pointers.py +++ b/Lib/ctypes/test/test_pointers.py @@ -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(0xFFFFFFFF).value, + self.assertEqual(c_void_p(0xFFFFFFFF).value, c_void_p(-1).value) - self.failUnlessEqual(c_void_p(0xFFFFFFFFFFFFFFFF).value, + self.assertEqual(c_void_p(0xFFFFFFFFFFFFFFFF).value, c_void_p(-1).value) elif sizeof(c_void_p) == 8: - self.failUnlessEqual(c_void_p(0xFFFFFFFF).value, + self.assertEqual(c_void_p(0xFFFFFFFF).value, 0xFFFFFFFF) - self.failUnlessEqual(c_void_p(0xFFFFFFFFFFFFFFFF).value, + self.assertEqual(c_void_p(0xFFFFFFFFFFFFFFFF).value, c_void_p(-1).value) - self.failUnlessEqual(c_void_p(0xFFFFFFFFFFFFFFFFFFFFFFFF).value, + self.assertEqual(c_void_p(0xFFFFFFFFFFFFFFFFFFFFFFFF).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() diff --git a/Lib/ctypes/test/test_prototypes.py b/Lib/ctypes/test/test_prototypes.py index e098e7b..9041750 100644 --- a/Lib/ctypes/test/test_prototypes.py +++ b/Lib/ctypes/test/test_prototypes.py @@ -58,23 +58,23 @@ class CharPointersTestCase(unittest.TestCase): try: func() except TypeError as 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(b"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(b"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("123", func(c_wchar_p("123"))) + self.assertEqual(None, func(c_wchar_p(None))) + self.assertEqual("123", func(c_wchar_p("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("123", func("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("123")) + self.assertEqual(None, func(c_wchar_p(None))) + self.assertEqual("123", func(c_wchar_p("123"))) - 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]) def test_c_wchar_p_arg(self): func = testdll._testfunc_p_p @@ -191,16 +191,16 @@ else: c_wchar_p.from_param("123") - self.failUnlessEqual(None, func(None)) - self.failUnlessEqual("123", func("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("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): diff --git a/Lib/ctypes/test/test_python_api.py b/Lib/ctypes/test/test_python_api.py index 674f9ab..b74767a 100644 --- a/Lib/ctypes/test/test_python_api.py +++ b/Lib/ctypes/test/test_python_api.py @@ -23,7 +23,7 @@ class PythonAPITestCase(unittest.TestCase): PyBytes_FromStringAndSize.restype = py_object PyBytes_FromStringAndSize.argtypes = c_char_p, c_py_ssize_t - self.failUnlessEqual(PyBytes_FromStringAndSize(b"abcdefghi", 3), b"abc") + self.assertEqual(PyBytes_FromStringAndSize(b"abcdefghi", 3), b"abc") def test_PyString_FromString(self): pythonapi.PyBytes_FromString.restype = py_object @@ -32,10 +32,10 @@ class PythonAPITestCase(unittest.TestCase): s = b"abc" refcnt = grc(s) pyob = pythonapi.PyBytes_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_PyLong_Long(self): ref42 = grc(42) pythonapi.PyLong_FromLong.restype = py_object - self.failUnlessEqual(pythonapi.PyLong_FromLong(42), 42) + self.assertEqual(pythonapi.PyLong_FromLong(42), 42) - self.failUnlessEqual(grc(42), ref42) + self.assertEqual(grc(42), ref42) pythonapi.PyLong_AsLong.argtypes = (py_object,) pythonapi.PyLong_AsLong.restype = c_long res = pythonapi.PyLong_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", b"ctypes") - self.failUnlessEqual(buf.value, b"Hello from ctypes") + self.assertEqual(buf.value, b"Hello from ctypes") PyOS_snprintf(buf, sizeof(buf), "Hello from %s (%d, %d, %d)", b"ctypes", 1, 2, 3) - self.failUnlessEqual(buf.value, b"Hello from ctypes (1, 2, 3)") + self.assertEqual(buf.value, b"Hello from ctypes (1, 2, 3)") # 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() diff --git a/Lib/ctypes/test/test_random_things.py b/Lib/ctypes/test/test_random_things.py index 6b2c1b1..2520a5e 100644 --- a/Lib/ctypes/test/test_random_things.py +++ b/Lib/ctypes/test/test_random_things.py @@ -20,7 +20,7 @@ if sys.platform == "win32": hdll = windll.kernel32.LoadLibraryA(b"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'") diff --git a/Lib/ctypes/test/test_refcounts.py b/Lib/ctypes/test/test_refcounts.py index 448f292..35a81aa 100644 --- a/Lib/ctypes/test/test_refcounts.py +++ b/Lib/ctypes/test/test_refcounts.py @@ -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() diff --git a/Lib/ctypes/test/test_repr.py b/Lib/ctypes/test/test_repr.py index 3f1e819..9a1e238 100644 --- a/Lib/ctypes/test/test_repr.py +++ b/Lib/ctypes/test/test_repr.py @@ -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(b'x')", repr(c_char('x'))) - self.failUnlessEqual("<X object at", repr(X('x'))[:12]) + self.assertEqual("c_char(b'x')", repr(c_char('x'))) + self.assertEqual("<X object at", repr(X('x'))[:12]) if __name__ == "__main__": unittest.main() diff --git a/Lib/ctypes/test/test_returnfuncptrs.py b/Lib/ctypes/test/test_returnfuncptrs.py index cd451a2..ae8c26a 100644 --- a/Lib/ctypes/test/test_returnfuncptrs.py +++ b/Lib/ctypes/test/test_returnfuncptrs.py @@ -12,10 +12,10 @@ 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.failUnlessEqual(strchr("abcdef", 98), "bcdef") - self.failUnlessEqual(strchr("abcdef", 107), None) + self.assertEqual(strchr("abcdef", "b"), "bcdef") + self.assertEqual(strchr("abcdef", "x"), None) + self.assertEqual(strchr("abcdef", 98), "bcdef") + self.assertEqual(strchr("abcdef", 107), None) self.assertRaises(ArgumentError, strchr, "abcdef", 3.0) self.assertRaises(TypeError, strchr, "abcdef") @@ -28,8 +28,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.0) self.assertRaises(TypeError, strchr, "abcdef") diff --git a/Lib/ctypes/test/test_simplesubclasses.py b/Lib/ctypes/test/test_simplesubclasses.py index 420c0a0..3da2794 100644 --- a/Lib/ctypes/test/test_simplesubclasses.py +++ b/Lib/ctypes/test/test_simplesubclasses.py @@ -10,8 +10,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 @@ -21,7 +21,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): @@ -32,24 +32,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() diff --git a/Lib/ctypes/test/test_sizes.py b/Lib/ctypes/test/test_sizes.py index 208c00e..0509cbb 100644 --- a/Lib/ctypes/test/test_sizes.py +++ b/Lib/ctypes/test/test_sizes.py @@ -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() diff --git a/Lib/ctypes/test/test_slicing.py b/Lib/ctypes/test/test_slicing.py index 7c863c1..5343917 100644 --- a/Lib/ctypes/test/test_slicing.py +++ b/Lib/ctypes/test/test_slicing.py @@ -7,43 +7,43 @@ class SlicesTestCase(unittest.TestCase): def test_getslice_cint(self): a = (c_int * 100)(*range(1100, 1200)) b = list(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], list(range(5, 10))) - self.failUnlessEqual(a[0:5:], list(range(5, 10))) - self.failUnlessEqual(a[4::-1], list(range(9, 4, -1))) + self.assertEqual(a[0:5], list(range(5, 10))) + self.assertEqual(a[0:5:], list(range(5, 10))) + self.assertEqual(a[4::-1], list(range(9, 4, -1))) def test_setslice_cint(self): a = (c_int * 100)(*range(1100, 1200)) b = list(range(1100, 1200)) a[32:47] = list(range(32, 47)) - self.failUnlessEqual(a[32:47], list(range(32, 47))) + self.assertEqual(a[32:47], list(range(32, 47))) a[32:47] = range(132, 147) - self.failUnlessEqual(a[32:47:], list(range(132, 147))) + self.assertEqual(a[32:47:], list(range(132, 147))) a[46:31:-1] = range(232, 247) - self.failUnlessEqual(a[32:47:1], list(range(246, 231, -1))) + self.assertEqual(a[32:47:1], list(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 setitem @@ -65,12 +65,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, @@ -88,8 +88,8 @@ class SlicesTestCase(unittest.TestCase): dll.my_strdup.restype = POINTER(c_byte) res = dll.my_strdup(s) - self.failUnlessEqual(res[:len(s)], list(range(ord("a"), ord("z")+1))) - self.failUnlessEqual(res[:len(s):], list(range(ord("a"), ord("z")+1))) + self.assertEqual(res[:len(s)], list(range(ord("a"), ord("z")+1))) + self.assertEqual(res[:len(s):], list(range(ord("a"), ord("z")+1))) dll.my_free(res) def test_char_ptr_with_free(self): @@ -109,7 +109,7 @@ class SlicesTestCase(unittest.TestCase): dll.my_strdup.errcheck = errcheck try: res = dll.my_strdup(s) - self.failUnlessEqual(res, s.decode()) + self.assertEqual(res, s.decode()) finally: del dll.my_strdup.errcheck @@ -118,11 +118,11 @@ class SlicesTestCase(unittest.TestCase): s = b"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: @@ -138,10 +138,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.setitem, @@ -158,10 +158,10 @@ class SlicesTestCase(unittest.TestCase): return res = dll.my_wcsdup(s) tmpl = list(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) ################################################################ diff --git a/Lib/ctypes/test/test_stringptr.py b/Lib/ctypes/test/test_stringptr.py index a5a471c..84126f5 100644 --- a/Lib/ctypes/test/test_stringptr.py +++ b/Lib/ctypes/test/test_stringptr.py @@ -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, (b"c", b"d", b"e", b"f", b"\000")) + self.assertEqual(x, (b"c", b"d", b"e", b"f", b"\000")) del buf # x1 will NOT be the same as x, usually: x1 = r[0], r[1], r[2], r[3], r[4] diff --git a/Lib/ctypes/test/test_strings.py b/Lib/ctypes/test/test_strings.py index ef1cfcf..3cd1f84 100644 --- a/Lib/ctypes/test/test_strings.py +++ b/Lib/ctypes/test/test_strings.py @@ -6,20 +6,20 @@ class StringArrayTestCase(unittest.TestCase): BUF = c_char * 4 buf = BUF("a", "b", "c") - self.failUnlessEqual(buf.value, b"abc") - self.failUnlessEqual(buf.raw, b"abc\000") + self.assertEqual(buf.value, b"abc") + self.assertEqual(buf.raw, b"abc\000") buf.value = "ABCD" - self.failUnlessEqual(buf.value, b"ABCD") - self.failUnlessEqual(buf.raw, b"ABCD") + self.assertEqual(buf.value, b"ABCD") + self.assertEqual(buf.raw, b"ABCD") buf.value = "x" - self.failUnlessEqual(buf.value, b"x") - self.failUnlessEqual(buf.raw, b"x\000CD") + self.assertEqual(buf.value, b"x") + self.assertEqual(buf.raw, b"x\000CD") buf[1] = "Z" - self.failUnlessEqual(buf.value, b"xZCD") - self.failUnlessEqual(buf.raw, b"xZCD") + self.assertEqual(buf.value, b"xZCD") + self.assertEqual(buf.raw, b"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 = b"Hello, World" - self.failUnlessEqual(buf.value, b"Hello, World") + self.assertEqual(buf.value, b"Hello, World") - self.failUnlessRaises(TypeError, setattr, buf, "value", memoryview(b"Hello, World")) + self.assertRaises(TypeError, setattr, buf, "value", memoryview(b"Hello, World")) self.assertRaises(TypeError, setattr, buf, "value", memoryview(b"abc")) self.assertRaises(ValueError, setattr, buf, "raw", memoryview(b"x" * 100)) @@ -38,7 +38,7 @@ class StringArrayTestCase(unittest.TestCase): buf = c_buffer(32) buf.raw = memoryview(b"Hello, World") - self.failUnlessEqual(buf.value, b"Hello, World") + self.assertEqual(buf.value, b"Hello, World") self.assertRaises(TypeError, setattr, buf, "value", memoryview(b"abc")) self.assertRaises(ValueError, setattr, buf, "raw", memoryview(b"x" * 100)) @@ -63,16 +63,16 @@ else: BUF = c_wchar * 4 buf = BUF("a", "b", "c") - self.failUnlessEqual(buf.value, "abc") + self.assertEqual(buf.value, "abc") buf.value = "ABCD" - self.failUnlessEqual(buf.value, "ABCD") + self.assertEqual(buf.value, "ABCD") buf.value = "x" - self.failUnlessEqual(buf.value, "x") + self.assertEqual(buf.value, "x") buf[1] = "Z" - self.failUnlessEqual(buf.value, "xZCD") + self.assertEqual(buf.value, "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, "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 == "abcdef") - self.failUnless(c_wstring("abc\000def").value == "abc") + self.assertTrue(cs.value == "abcdef") + self.assertTrue(c_wstring("abc\000def").value == "abc") - self.failUnless(c_wstring("abc\000def").value == "abc") + self.assertTrue(c_wstring("abc\000def").value == "abc") # The raw property is the total buffer contents: - self.failUnless(cs.raw == "abcdef\000") - self.failUnless(c_wstring("abc\000def").raw == "abc\000def\000") + self.assertTrue(cs.raw == "abcdef\000") + self.assertTrue(c_wstring("abc\000def").raw == "abc\000def\000") # We can change the value: cs.value = "ab" - self.failUnless(cs.value == "ab") - self.failUnless(cs.raw == "ab\000\000\000\000\000") + self.assertTrue(cs.value == "ab") + self.assertTrue(cs.raw == "ab\000\000\000\000\000") self.assertRaises(TypeError, c_wstring, "123") self.assertRaises(ValueError, c_wstring, 0) diff --git a/Lib/ctypes/test/test_struct_fields.py b/Lib/ctypes/test/test_struct_fields.py index ef5fb50..22eb3b0 100644 --- a/Lib/ctypes/test/test_struct_fields.py +++ b/Lib/ctypes/test/test_struct_fields.py @@ -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_", []) diff --git a/Lib/ctypes/test/test_structures.py b/Lib/ctypes/test/test_structures.py index 3587f0f..23468dc 100644 --- a/Lib/ctypes/test/test_structures.py +++ b/Lib/ctypes/test/test_structures.py @@ -13,33 +13,33 @@ class SubclassesTest(unittest.TestCase): class Z(X): pass - self.failUnlessEqual(sizeof(X), sizeof(c_int)) - self.failUnlessEqual(sizeof(Y), sizeof(c_int)*2) - self.failUnlessEqual(sizeof(Z), sizeof(c_int)) - self.failUnlessEqual(X._fields_, [("a", c_int)]) - self.failUnlessEqual(Y._fields_, [("b", c_int)]) - self.failUnlessEqual(Z._fields_, [("a", c_int)]) + self.assertEqual(sizeof(X), sizeof(c_int)) + self.assertEqual(sizeof(Y), sizeof(c_int)*2) + self.assertEqual(sizeof(Z), sizeof(c_int)) + self.assertEqual(X._fields_, [("a", c_int)]) + self.assertEqual(Y._fields_, [("b", c_int)]) + self.assertEqual(Z._fields_, [("a", c_int)]) def test_subclass_delayed(self): class X(Structure): pass - self.failUnlessEqual(sizeof(X), 0) + self.assertEqual(sizeof(X), 0) X._fields_ = [("a", c_int)] class Y(X): pass - self.failUnlessEqual(sizeof(Y), sizeof(X)) + self.assertEqual(sizeof(Y), sizeof(X)) Y._fields_ = [("b", c_int)] class Z(X): pass - self.failUnlessEqual(sizeof(X), sizeof(c_int)) - self.failUnlessEqual(sizeof(Y), sizeof(c_int)*2) - self.failUnlessEqual(sizeof(Z), sizeof(c_int)) - self.failUnlessEqual(X._fields_, [("a", c_int)]) - self.failUnlessEqual(Y._fields_, [("b", c_int)]) - self.failUnlessEqual(Z._fields_, [("a", c_int)]) + self.assertEqual(sizeof(X), sizeof(c_int)) + self.assertEqual(sizeof(Y), sizeof(c_int)*2) + self.assertEqual(sizeof(Z), sizeof(c_int)) + self.assertEqual(X._fields_, [("a", c_int)]) + self.assertEqual(Y._fields_, [("b", c_int)]) + self.assertEqual(Z._fields_, [("a", c_int)]) class StructureTestCase(unittest.TestCase): formats = {"c": c_char, @@ -62,7 +62,7 @@ class StructureTestCase(unittest.TestCase): class X(Structure): _fields_ = [("x", c_char), ("y", tp)] - self.failUnlessEqual((sizeof(X), code), + self.assertEqual((sizeof(X), code), (calcsize("c%c0%c" % (code, code)), code)) def test_unions(self): @@ -70,39 +70,39 @@ class StructureTestCase(unittest.TestCase): class X(Union): _fields_ = [("x", c_char), ("y", tp)] - self.failUnlessEqual((sizeof(X), code), + self.assertEqual((sizeof(X), code), (calcsize("%c" % (code)), code)) def test_struct_alignment(self): class X(Structure): _fields_ = [("x", c_char * 3)] - self.failUnlessEqual(alignment(X), calcsize("s")) - self.failUnlessEqual(sizeof(X), calcsize("3s")) + self.assertEqual(alignment(X), calcsize("s")) + self.assertEqual(sizeof(X), calcsize("3s")) class Y(Structure): _fields_ = [("x", c_char * 3), ("y", c_int)] - self.failUnlessEqual(alignment(Y), calcsize("i")) - self.failUnlessEqual(sizeof(Y), calcsize("3si")) + self.assertEqual(alignment(Y), calcsize("i")) + self.assertEqual(sizeof(Y), calcsize("3si")) class SI(Structure): _fields_ = [("a", X), ("b", Y)] - self.failUnlessEqual(alignment(SI), max(alignment(Y), alignment(X))) - self.failUnlessEqual(sizeof(SI), calcsize("3s0i 3si 0i")) + self.assertEqual(alignment(SI), max(alignment(Y), alignment(X))) + self.assertEqual(sizeof(SI), calcsize("3s0i 3si 0i")) class IS(Structure): _fields_ = [("b", Y), ("a", X)] - self.failUnlessEqual(alignment(SI), max(alignment(X), alignment(Y))) - self.failUnlessEqual(sizeof(IS), calcsize("3si 3s 0i")) + self.assertEqual(alignment(SI), max(alignment(X), alignment(Y))) + self.assertEqual(sizeof(IS), calcsize("3si 3s 0i")) class XX(Structure): _fields_ = [("a", X), ("b", X)] - self.failUnlessEqual(alignment(XX), alignment(X)) - self.failUnlessEqual(sizeof(XX), calcsize("3s 3s 0s")) + self.assertEqual(alignment(XX), alignment(X)) + self.assertEqual(sizeof(XX), calcsize("3s 3s 0s")) def test_emtpy(self): # I had problems with these @@ -115,15 +115,15 @@ class StructureTestCase(unittest.TestCase): _fields_ = [] # Is this really the correct alignment, or should it be 0? - self.failUnless(alignment(X) == alignment(Y) == 1) - self.failUnless(sizeof(X) == sizeof(Y) == 0) + self.assertTrue(alignment(X) == alignment(Y) == 1) + self.assertTrue(sizeof(X) == sizeof(Y) == 0) class XX(Structure): _fields_ = [("a", X), ("b", X)] - self.failUnlessEqual(alignment(XX), 1) - self.failUnlessEqual(sizeof(XX), 0) + self.assertEqual(alignment(XX), 1) + self.assertEqual(sizeof(XX), 0) def test_fields(self): # test the offset and size attributes of Structure/Unoin fields. @@ -131,11 +131,11 @@ class StructureTestCase(unittest.TestCase): _fields_ = [("x", c_int), ("y", c_char)] - self.failUnlessEqual(X.x.offset, 0) - self.failUnlessEqual(X.x.size, sizeof(c_int)) + self.assertEqual(X.x.offset, 0) + self.assertEqual(X.x.size, sizeof(c_int)) - self.failUnlessEqual(X.y.offset, sizeof(c_int)) - self.failUnlessEqual(X.y.size, sizeof(c_char)) + self.assertEqual(X.y.offset, sizeof(c_int)) + self.assertEqual(X.y.size, sizeof(c_char)) # readonly self.assertRaises((TypeError, AttributeError), setattr, X.x, "offset", 92) @@ -145,11 +145,11 @@ class StructureTestCase(unittest.TestCase): _fields_ = [("x", c_int), ("y", c_char)] - self.failUnlessEqual(X.x.offset, 0) - self.failUnlessEqual(X.x.size, sizeof(c_int)) + self.assertEqual(X.x.offset, 0) + self.assertEqual(X.x.size, sizeof(c_int)) - self.failUnlessEqual(X.y.offset, 0) - self.failUnlessEqual(X.y.size, sizeof(c_char)) + self.assertEqual(X.y.offset, 0) + self.assertEqual(X.y.size, sizeof(c_char)) # readonly self.assertRaises((TypeError, AttributeError), setattr, X.x, "offset", 92) @@ -164,22 +164,22 @@ class StructureTestCase(unittest.TestCase): ("b", c_longlong)] _pack_ = 1 - self.failUnlessEqual(sizeof(X), 9) - self.failUnlessEqual(X.b.offset, 1) + self.assertEqual(sizeof(X), 9) + self.assertEqual(X.b.offset, 1) class X(Structure): _fields_ = [("a", c_byte), ("b", c_longlong)] _pack_ = 2 - self.failUnlessEqual(sizeof(X), 10) - self.failUnlessEqual(X.b.offset, 2) + self.assertEqual(sizeof(X), 10) + self.assertEqual(X.b.offset, 2) class X(Structure): _fields_ = [("a", c_byte), ("b", c_longlong)] _pack_ = 4 - self.failUnlessEqual(sizeof(X), 12) - self.failUnlessEqual(X.b.offset, 4) + self.assertEqual(sizeof(X), 12) + self.assertEqual(X.b.offset, 4) import struct longlong_size = struct.calcsize("q") @@ -190,8 +190,8 @@ class StructureTestCase(unittest.TestCase): ("b", c_longlong)] _pack_ = 8 - self.failUnlessEqual(sizeof(X), longlong_align + longlong_size) - self.failUnlessEqual(X.b.offset, min(8, longlong_align)) + self.assertEqual(sizeof(X), longlong_align + longlong_size) + self.assertEqual(X.b.offset, min(8, longlong_align)) d = {"_fields_": [("a", "b"), @@ -209,9 +209,9 @@ class StructureTestCase(unittest.TestCase): self.assertRaises(TypeError, Person, "Name", "HI") # short enough - self.failUnlessEqual(Person("12345", 5).name, "12345") + self.assertEqual(Person("12345", 5).name, "12345") # exact fit - self.failUnlessEqual(Person("123456", 5).name, "123456") + self.assertEqual(Person("123456", 5).name, "123456") # too long self.assertRaises(ValueError, Person, "1234567", 5) @@ -229,10 +229,10 @@ class StructureTestCase(unittest.TestCase): class POINT(Structure): _fields_ = [("x", c_int), ("y", c_int)] pt = POINT(1, 2) - self.failUnlessEqual((pt.x, pt.y), (1, 2)) + self.assertEqual((pt.x, pt.y), (1, 2)) pt = POINT(y=2, x=1) - self.failUnlessEqual((pt.x, pt.y), (1, 2)) + self.assertEqual((pt.x, pt.y), (1, 2)) def test_invalid_field_types(self): class POINT(Structure): @@ -244,14 +244,14 @@ class StructureTestCase(unittest.TestCase): _fields_ = [("a", c_int * 4)] # can use tuple to initialize array (but not list!) - self.failUnlessEqual(SomeInts((1, 2)).a[:], [1, 2, 0, 0]) - self.failUnlessEqual(SomeInts((1, 2)).a[::], [1, 2, 0, 0]) - self.failUnlessEqual(SomeInts((1, 2)).a[::-1], [0, 0, 2, 1]) - self.failUnlessEqual(SomeInts((1, 2)).a[::2], [1, 0]) - self.failUnlessEqual(SomeInts((1, 2)).a[1:5:6], [2]) - self.failUnlessEqual(SomeInts((1, 2)).a[6:4:-1], []) - self.failUnlessEqual(SomeInts((1, 2, 3, 4)).a[:], [1, 2, 3, 4]) - self.failUnlessEqual(SomeInts((1, 2, 3, 4)).a[::], [1, 2, 3, 4]) + self.assertEqual(SomeInts((1, 2)).a[:], [1, 2, 0, 0]) + self.assertEqual(SomeInts((1, 2)).a[::], [1, 2, 0, 0]) + self.assertEqual(SomeInts((1, 2)).a[::-1], [0, 0, 2, 1]) + self.assertEqual(SomeInts((1, 2)).a[::2], [1, 0]) + self.assertEqual(SomeInts((1, 2)).a[1:5:6], [2]) + self.assertEqual(SomeInts((1, 2)).a[6:4:-1], []) + self.assertEqual(SomeInts((1, 2, 3, 4)).a[:], [1, 2, 3, 4]) + self.assertEqual(SomeInts((1, 2, 3, 4)).a[::], [1, 2, 3, 4]) # too long # XXX Should raise ValueError?, not RuntimeError self.assertRaises(RuntimeError, SomeInts, (1, 2, 3, 4, 5)) @@ -269,10 +269,10 @@ class StructureTestCase(unittest.TestCase): p = Person("Someone", ("1234", "5678"), 5) - self.failUnlessEqual(p.name, "Someone") - self.failUnlessEqual(p.phone.areacode, "1234") - self.failUnlessEqual(p.phone.number, "5678") - self.failUnlessEqual(p.age, 5) + self.assertEqual(p.name, "Someone") + self.assertEqual(p.phone.areacode, "1234") + self.assertEqual(p.phone.number, "5678") + self.assertEqual(p.age, 5) def test_structures_with_wchar(self): try: @@ -285,12 +285,12 @@ class StructureTestCase(unittest.TestCase): ("age", c_int)] p = PersonW("Someone") - self.failUnlessEqual(p.name, "Someone") + self.assertEqual(p.name, "Someone") - self.failUnlessEqual(PersonW("1234567890").name, "1234567890") - self.failUnlessEqual(PersonW("12345678901").name, "12345678901") + self.assertEqual(PersonW("1234567890").name, "1234567890") + self.assertEqual(PersonW("12345678901").name, "12345678901") # exact fit - self.failUnlessEqual(PersonW("123456789012").name, "123456789012") + self.assertEqual(PersonW("123456789012").name, "123456789012") #too long self.assertRaises(ValueError, PersonW, "1234567890123") @@ -305,18 +305,18 @@ class StructureTestCase(unittest.TestCase): ("age", c_int)] cls, msg = self.get_except(Person, "Someone", (1, 2)) - self.failUnlessEqual(cls, RuntimeError) - self.failUnlessEqual(msg, + self.assertEqual(cls, RuntimeError) + self.assertEqual(msg, "(Phone) <class 'TypeError'>: " "expected string, int found") cls, msg = self.get_except(Person, "Someone", ("a", "b", "c")) - self.failUnlessEqual(cls, RuntimeError) + self.assertEqual(cls, RuntimeError) if issubclass(Exception, object): - self.failUnlessEqual(msg, + self.assertEqual(msg, "(Phone) <class 'TypeError'>: too many initializers") else: - self.failUnlessEqual(msg, "(Phone) TypeError: too many initializers") + self.assertEqual(msg, "(Phone) TypeError: too many initializers") def get_except(self, func, *args): @@ -331,7 +331,7 @@ class StructureTestCase(unittest.TestCase): ## # same as 'class X(Structure): pass' ## # fails, since we need either a _fields_ or a _abstract_ attribute ## cls, msg = self.get_except(meta, "X", (Structure,), {}) -## self.failUnlessEqual((cls, msg), +## self.assertEqual((cls, msg), ## (AttributeError, "class must define a '_fields_' attribute")) def test_abstract_class(self): @@ -339,15 +339,15 @@ class StructureTestCase(unittest.TestCase): _abstract_ = "something" # try 'X()' cls, msg = self.get_except(eval, "X()", locals()) - self.failUnlessEqual((cls, msg), (TypeError, "abstract class")) + self.assertEqual((cls, msg), (TypeError, "abstract class")) def test_methods(self): ## class X(Structure): ## _fields_ = [] - self.failUnless("in_dll" in dir(type(Structure))) - self.failUnless("from_address" in dir(type(Structure))) - self.failUnless("in_dll" in dir(type(Structure))) + self.assertTrue("in_dll" in dir(type(Structure))) + self.assertTrue("from_address" in dir(type(Structure))) + self.assertTrue("in_dll" in dir(type(Structure))) class PointerMemberTestCase(unittest.TestCase): @@ -360,7 +360,7 @@ class PointerMemberTestCase(unittest.TestCase): # We can assign arrays of the correct type s.array = (c_int * 3)(1, 2, 3) items = [s.array[i] for i in range(3)] - self.failUnlessEqual(items, [1, 2, 3]) + self.assertEqual(items, [1, 2, 3]) # The following are bugs, but are included here because the unittests # also describe the current behaviour. @@ -371,14 +371,14 @@ class PointerMemberTestCase(unittest.TestCase): s.array[0] = 42 items = [s.array[i] for i in range(3)] - self.failUnlessEqual(items, [42, 2, 3]) + self.assertEqual(items, [42, 2, 3]) s.array[0] = 1 ## s.array[1] = 42 items = [s.array[i] for i in range(3)] - self.failUnlessEqual(items, [1, 2, 3]) + self.assertEqual(items, [1, 2, 3]) def test_none_to_pointer_fields(self): class S(Structure): @@ -388,7 +388,7 @@ class PointerMemberTestCase(unittest.TestCase): s = S() s.x = 12345678 s.p = None - self.failUnlessEqual(s.x, 12345678) + self.assertEqual(s.x, 12345678) class TestRecursiveStructure(unittest.TestCase): def test_contains_itself(self): @@ -398,7 +398,7 @@ class TestRecursiveStructure(unittest.TestCase): try: Recursive._fields_ = [("next", Recursive)] except AttributeError as details: - self.failUnless("Structure or union cannot contain itself" in + self.assertTrue("Structure or union cannot contain itself" in str(details)) else: self.fail("Structure or union cannot contain itself") @@ -415,7 +415,7 @@ class TestRecursiveStructure(unittest.TestCase): try: Second._fields_ = [("first", First)] except AttributeError as details: - self.failUnless("_fields_ is final" in + self.assertTrue("_fields_ is final" in str(details)) else: self.fail("AttributeError not raised") diff --git a/Lib/ctypes/test/test_unaligned_structures.py b/Lib/ctypes/test/test_unaligned_structures.py index 89343ba..bcacfc8 100644 --- a/Lib/ctypes/test/test_unaligned_structures.py +++ b/Lib/ctypes/test/test_unaligned_structures.py @@ -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() diff --git a/Lib/ctypes/test/test_unicode.py b/Lib/ctypes/test/test_unicode.py index 0eae59b..7d628f2 100644 --- a/Lib/ctypes/test/test_unicode.py +++ b/Lib/ctypes/test/test_unicode.py @@ -22,55 +22,55 @@ else: def test_ascii_strict(self): ctypes.set_conversion_mode("ascii", "strict") # no conversions take place with unicode arguments - self.failUnlessEqual(wcslen("abc"), 3) - self.failUnlessEqual(wcslen("ab\u2070"), 3) + self.assertEqual(wcslen("abc"), 3) + self.assertEqual(wcslen("ab\u2070"), 3) # string args are converted - self.failUnlessEqual(wcslen("abc"), 3) - self.failUnlessRaises(ctypes.ArgumentError, wcslen, b"ab\xe4") + self.assertEqual(wcslen("abc"), 3) + self.assertRaises(ctypes.ArgumentError, wcslen, b"ab\xe4") def test_ascii_replace(self): ctypes.set_conversion_mode("ascii", "replace") - self.failUnlessEqual(wcslen("abc"), 3) - self.failUnlessEqual(wcslen("ab\u2070"), 3) - self.failUnlessEqual(wcslen("abc"), 3) - self.failUnlessEqual(wcslen("ab\xe4"), 3) + self.assertEqual(wcslen("abc"), 3) + self.assertEqual(wcslen("ab\u2070"), 3) + self.assertEqual(wcslen("abc"), 3) + self.assertEqual(wcslen("ab\xe4"), 3) def test_ascii_ignore(self): ctypes.set_conversion_mode("ascii", "ignore") - self.failUnlessEqual(wcslen("abc"), 3) - self.failUnlessEqual(wcslen("ab\u2070"), 3) + self.assertEqual(wcslen("abc"), 3) + self.assertEqual(wcslen("ab\u2070"), 3) # ignore error mode skips non-ascii characters - self.failUnlessEqual(wcslen("abc"), 3) - self.failUnlessEqual(wcslen(b"\xe4\xf6\xfc\xdf"), 0) + self.assertEqual(wcslen("abc"), 3) + self.assertEqual(wcslen(b"\xe4\xf6\xfc\xdf"), 0) def test_latin1_strict(self): ctypes.set_conversion_mode("latin-1", "strict") - self.failUnlessEqual(wcslen("abc"), 3) - self.failUnlessEqual(wcslen("ab\u2070"), 3) - self.failUnlessEqual(wcslen("abc"), 3) - self.failUnlessEqual(wcslen("\xe4\xf6\xfc\xdf"), 4) + self.assertEqual(wcslen("abc"), 3) + self.assertEqual(wcslen("ab\u2070"), 3) + self.assertEqual(wcslen("abc"), 3) + self.assertEqual(wcslen("\xe4\xf6\xfc\xdf"), 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(b"ab\xe4\xf6\xfc") - self.failUnlessEqual(buf[:], "ab\uFFFD\uFFFD\uFFFD\0") - self.failUnlessEqual(buf[::], "ab\uFFFD\uFFFD\uFFFD\0") - self.failUnlessEqual(buf[::-1], "\0\uFFFD\uFFFD\uFFFDba") - self.failUnlessEqual(buf[::2], "a\uFFFD\uFFFD") - self.failUnlessEqual(buf[6:5:-1], "") + self.assertEqual(buf[:], "ab\uFFFD\uFFFD\uFFFD\0") + self.assertEqual(buf[::], "ab\uFFFD\uFFFD\uFFFD\0") + self.assertEqual(buf[::-1], "\0\uFFFD\uFFFD\uFFFDba") + self.assertEqual(buf[::2], "a\uFFFD\uFFFD") + self.assertEqual(buf[6:5:-1], "") ctypes.set_conversion_mode("ascii", "ignore") buf = ctypes.create_unicode_buffer(b"ab\xe4\xf6\xfc") # 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.failUnlessEqual(buf[::2], "a\0\0") - self.failUnlessEqual(buf[6:5:-1], "") + self.assertEqual(buf[:], "ab\0\0\0\0") + self.assertEqual(buf[::], "ab\0\0\0\0") + self.assertEqual(buf[::-1], "\0\0\0\0ba") + self.assertEqual(buf[::2], "a\0\0") + self.assertEqual(buf[6:5:-1], "") import _ctypes_test func = ctypes.CDLL(_ctypes_test.__file__)._testfunc_p_p @@ -88,41 +88,41 @@ else: def test_ascii_replace(self): ctypes.set_conversion_mode("ascii", "strict") - self.failUnlessEqual(func("abc"), "abc") - self.failUnlessEqual(func("abc"), "abc") + self.assertEqual(func("abc"), "abc") + self.assertEqual(func("abc"), "abc") self.assertRaises(ctypes.ArgumentError, func, "ab\xe4") def test_ascii_ignore(self): ctypes.set_conversion_mode("ascii", "ignore") - self.failUnlessEqual(func("abc"), "abc") - self.failUnlessEqual(func("abc"), "abc") - self.failUnlessEqual(func("\xe4\xf6\xfc\xdf"), "") + self.assertEqual(func("abc"), "abc") + self.assertEqual(func("abc"), "abc") + self.assertEqual(func("\xe4\xf6\xfc\xdf"), "") def test_ascii_replace(self): ctypes.set_conversion_mode("ascii", "replace") - self.failUnlessEqual(func("abc"), "abc") - self.failUnlessEqual(func("abc"), "abc") - self.failUnlessEqual(func("\xe4\xf6\xfc\xdf"), "????") + self.assertEqual(func("abc"), "abc") + self.assertEqual(func("abc"), "abc") + self.assertEqual(func("\xe4\xf6\xfc\xdf"), "????") def test_buffers(self): ctypes.set_conversion_mode("ascii", "strict") buf = ctypes.create_string_buffer("abc") - self.failUnlessEqual(len(buf), 3+1) + self.assertEqual(len(buf), 3+1) ctypes.set_conversion_mode("ascii", "replace") buf = ctypes.create_string_buffer("ab\xe4\xf6\xfc") - self.failUnlessEqual(buf[:], b"ab???\0") - self.failUnlessEqual(buf[::], b"ab???\0") - self.failUnlessEqual(buf[::-1], b"\0???ba") - self.failUnlessEqual(buf[::2], b"a??") - self.failUnlessEqual(buf[6:5:-1], b"") + self.assertEqual(buf[:], b"ab???\0") + self.assertEqual(buf[::], b"ab???\0") + self.assertEqual(buf[::-1], b"\0???ba") + self.assertEqual(buf[::2], b"a??") + self.assertEqual(buf[6:5:-1], b"") ctypes.set_conversion_mode("ascii", "ignore") buf = ctypes.create_string_buffer("ab\xe4\xf6\xfc") # is that correct? not sure. But with 'ignore', you get what you pay for.. - self.failUnlessEqual(buf[:], b"ab\0\0\0\0") - self.failUnlessEqual(buf[::], b"ab\0\0\0\0") - self.failUnlessEqual(buf[::-1], b"\0\0\0\0ba") + self.assertEqual(buf[:], b"ab\0\0\0\0") + self.assertEqual(buf[::], b"ab\0\0\0\0") + self.assertEqual(buf[::-1], b"\0\0\0\0ba") if __name__ == '__main__': unittest.main() diff --git a/Lib/ctypes/test/test_values.py b/Lib/ctypes/test/test_values.py index 476b7b7..e464102 100644 --- a/Lib/ctypes/test/test_values.py +++ b/Lib/ctypes/test/test_values.py @@ -15,13 +15,13 @@ 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()) # To avoid test failures when this test is repeated several # times the original value must be restored an_integer.value = x - self.failUnlessEqual(x, ctdll.get_an_integer()) + self.assertEqual(x, ctdll.get_an_integer()) def test_undefined(self): ctdll = CDLL(_ctypes_test.__file__) @@ -40,11 +40,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 @@ -76,7 +76,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] diff --git a/Lib/ctypes/test/test_varsize_struct.py b/Lib/ctypes/test/test_varsize_struct.py index 06d2323..f409500 100644 --- a/Lib/ctypes/test/test_varsize_struct.py +++ b/Lib/ctypes/test/test_varsize_struct.py @@ -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() diff --git a/Lib/ctypes/test/test_win32.py b/Lib/ctypes/test/test_win32.py index 5067b60..5dedd9f 100644 --- a/Lib/ctypes/test/test_win32.py +++ b/Lib/ctypes/test/test_win32.py @@ -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() |