Index: Lib/ctypes/test/test_byteswap.py =================================================================== --- Lib/ctypes/test/test_byteswap.py (revision 77489) +++ Lib/ctypes/test/test_byteswap.py (working copy) @@ -4,7 +4,7 @@ from ctypes import * def bin(s): - return hexlify(buffer(s)).upper() + return hexlify(memoryview(s)).upper() # Each *simple* type that supports different byte orders has an # __ctype_be__ attribute that specifies the same type in BIG ENDIAN Index: Lib/ctypes/test/test_pickling.py =================================================================== --- Lib/ctypes/test/test_pickling.py (revision 77489) +++ Lib/ctypes/test/test_pickling.py (working copy) @@ -28,8 +28,8 @@ ]: dst = self.loads(self.dumps(src)) self.assertEqual(src.__dict__, dst.__dict__) - self.assertEqual(buffer(src)[:], - buffer(dst)[:]) + self.assertEqual(memoryview(src).tobytes(), + memoryview(dst).tobytes()) def test_struct(self): X.init_called = 0 @@ -46,8 +46,8 @@ # ctypes instances are identical when the instance __dict__ # and the memory buffer are identical self.assertEqual(y.__dict__, x.__dict__) - self.assertEqual(buffer(y)[:], - buffer(x)[:]) + self.assertEqual(memoryview(y).tobytes(), + memoryview(x).tobytes()) def test_unpickable(self): # ctypes objects that are pointers or contain pointers are Index: Lib/ctypes/test/test_pep3118.py =================================================================== --- Lib/ctypes/test/test_pep3118.py (revision 77489) +++ Lib/ctypes/test/test_pep3118.py (working copy) @@ -1,6 +1,6 @@ import unittest from ctypes import * -import re, struct, sys +import re, sys if sys.byteorder == "little": THIS_ENDIAN = "<" @@ -9,27 +9,6 @@ THIS_ENDIAN = ">" OTHER_ENDIAN = "<" -class memoryview(object): - # This class creates a memoryview - like object from data returned - # by the private _ctypes._buffer_info() function, just enough for - # these tests. - # - # It can be removed when the py3k memoryview object is backported. - def __init__(self, ob): - from _ctypes import _buffer_info - self.format, self.ndim, self.shape = _buffer_info(ob) - if self.shape == (): - self.shape = None - self.itemsize = sizeof(ob) - else: - size = sizeof(ob) - for dim in self.shape: - size /= dim - self.itemsize = size - self.strides = None - self.readonly = False - self.size = sizeof(ob) - def normalize(format): # Remove current endian specifier and white space from a format # string @@ -46,7 +25,10 @@ v = memoryview(ob) try: self.assertEqual(normalize(v.format), normalize(fmt)) - self.assertEqual(v.size, sizeof(ob)) + if shape is not None: + self.assertEqual(len(v), shape[0]) + else: + 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 @@ -58,7 +40,7 @@ n = 1 for dim in v.shape: n = n * dim - self.assertEqual(v.itemsize * n, v.size) + self.assertEqual(n * v.itemsize, len(v.tobytes())) except: # so that we can see the failing type print(tp) @@ -70,7 +52,10 @@ v = memoryview(ob) try: self.assertEqual(v.format, fmt) - self.assertEqual(v.size, sizeof(ob)) + if shape is not None: + self.assertEqual(len(v), shape[0]) + else: + 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 @@ -82,7 +67,7 @@ n = 1 for dim in v.shape: n = n * dim - self.assertEqual(v.itemsize * n, v.size) + self.assertEqual(n, len(v)) except: # so that we can see the failing type print(tp) Index: Lib/ctypes/test/test_array_in_pointer.py =================================================================== --- Lib/ctypes/test/test_array_in_pointer.py (revision 77489) +++ Lib/ctypes/test/test_array_in_pointer.py (working copy) @@ -6,7 +6,7 @@ def dump(obj): # helper function to dump memory contents in hex, with a hyphen # between the bytes. - h = hexlify(buffer(obj)) + h = hexlify(memoryview(obj)) return re.sub(r"(..)", r"\1-", h)[:-1] Index: Lib/ctypes/test/test_structures.py =================================================================== --- Lib/ctypes/test/test_structures.py (revision 77489) +++ Lib/ctypes/test/test_structures.py (working copy) @@ -367,11 +367,11 @@ _fields_ = [("d", c_int), ("e", c_int), ("f", c_int)] z = Z(1, 2, 3, 4, 5, 6) - self.failUnlessEqual((z.a, z.b, z.c, z.d, z.e, z.f), - (1, 2, 3, 4, 5, 6)) + self.assertEqual((z.a, z.b, z.c, z.d, z.e, z.f), + (1, 2, 3, 4, 5, 6)) z = Z(1) - self.failUnlessEqual((z.a, z.b, z.c, z.d, z.e, z.f), - (1, 0, 0, 0, 0, 0)) + self.assertEqual((z.a, z.b, z.c, z.d, z.e, z.f), + (1, 0, 0, 0, 0, 0)) self.assertRaises(TypeError, lambda: Z(1, 2, 3, 4, 5, 6, 7)) class PointerMemberTestCase(unittest.TestCase): Index: Lib/ctypes/test/test_strings.py =================================================================== --- Lib/ctypes/test/test_strings.py (revision 77489) +++ Lib/ctypes/test/test_strings.py (working copy) @@ -30,17 +30,17 @@ buf.value = "Hello, World" self.assertEqual(buf.value, "Hello, World") - self.assertRaises(TypeError, setattr, buf, "value", buffer("Hello, World")) - self.assertRaises(TypeError, setattr, buf, "value", buffer("abc")) - self.assertRaises(ValueError, setattr, buf, "raw", buffer("x" * 100)) + self.assertRaises(TypeError, setattr, buf, "value", memoryview("Hello, World")) + self.assertRaises(TypeError, setattr, buf, "value", memoryview("abc")) + self.assertRaises(ValueError, setattr, buf, "raw", memoryview("x" * 100)) def test_c_buffer_raw(self): buf = c_buffer(32) - buf.raw = buffer("Hello, World") + buf.raw = memoryview("Hello, World") self.assertEqual(buf.value, "Hello, World") - self.assertRaises(TypeError, setattr, buf, "value", buffer("abc")) - self.assertRaises(ValueError, setattr, buf, "raw", buffer("x" * 100)) + self.assertRaises(TypeError, setattr, buf, "value", memoryview("abc")) + self.assertRaises(ValueError, setattr, buf, "raw", memoryview("x" * 100)) def test_param_1(self): BUF = c_char * 4