[pypy-commit] pypy py3k: py3k-ify ctypes_test. Certainly incomplete, but at least they can be imported.

amauryfa noreply at buildbot.pypy.org
Mon Nov 5 22:50:38 CET 2012


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: py3k
Changeset: r58758:132836979560
Date: 2012-10-28 19:47 +0100
http://bitbucket.org/pypy/pypy/changeset/132836979560/

Log:	py3k-ify ctypes_test. Certainly incomplete, but at least they can be
	imported.

diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_as_parameter.py b/pypy/module/test_lib_pypy/ctypes_tests/test_as_parameter.py
--- a/pypy/module/test_lib_pypy/ctypes_tests/test_as_parameter.py
+++ b/pypy/module/test_lib_pypy/ctypes_tests/test_as_parameter.py
@@ -27,7 +27,7 @@
             return
         f = dll._testfunc_i_bhilfd
         f.argtypes = [c_byte, c_wchar, c_int, c_long, c_float, c_double]
-        result = f(self.wrap(1), self.wrap(u"x"), self.wrap(3), self.wrap(4), self.wrap(5.0), self.wrap(6.0))
+        result = f(self.wrap(1), self.wrap("x"), self.wrap(3), self.wrap(4), self.wrap(5.0), self.wrap(6.0))
         assert result == 139
         assert type(result), int
 
diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_bitfields.py b/pypy/module/test_lib_pypy/ctypes_tests/test_bitfields.py
--- a/pypy/module/test_lib_pypy/ctypes_tests/test_bitfields.py
+++ b/pypy/module/test_lib_pypy/ctypes_tests/test_bitfields.py
@@ -194,7 +194,7 @@
     def get_except(self, func, *args, **kw):
         try:
             func(*args, **kw)
-        except Exception, detail:
+        except Exception as detail:
             import traceback
             traceback.print_exc()
             return detail.__class__, str(detail)
diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_buffers.py b/pypy/module/test_lib_pypy/ctypes_tests/test_buffers.py
--- a/pypy/module/test_lib_pypy/ctypes_tests/test_buffers.py
+++ b/pypy/module/test_lib_pypy/ctypes_tests/test_buffers.py
@@ -9,15 +9,15 @@
         assert sizeof(b) == 32 * sizeof(c_char)
         assert type(b[0]) is str
 
-        b = create_string_buffer("abc")
+        b = create_string_buffer(b"abc")
         assert len(b) == 4 # trailing nul char
         assert sizeof(b) == 4 * sizeof(c_char)
-        assert type(b[0]) is str
-        assert b[0] == "a"
-        assert b[:] == "abc\0"
+        assert type(b[0]) is bytes
+        assert b[0] == b"a"
+        assert b[:] == b"abc\0"
 
     def test_string_conversion(self):
-        b = create_string_buffer(u"abc")
+        b = create_string_buffer("abc")
         assert len(b) == 4 # trailing nul char
         assert sizeof(b) == 4 * sizeof(c_char)
         assert type(b[0]) is str
@@ -35,18 +35,18 @@
             assert sizeof(b) == 32 * sizeof(c_wchar)
             assert type(b[0]) is unicode
 
-            b = create_unicode_buffer(u"abc")
-            assert len(b) == 4 # trailing nul char
-            assert sizeof(b) == 4 * sizeof(c_wchar)
-            assert type(b[0]) is unicode
-            assert b[0] == u"a"
-            assert b[:] == "abc\0"
-
-        def test_unicode_conversion(self):
             b = create_unicode_buffer("abc")
             assert len(b) == 4 # trailing nul char
             assert sizeof(b) == 4 * sizeof(c_wchar)
             assert type(b[0]) is unicode
-            assert b[0] == u"a"
+            assert b[0] == "a"
             assert b[:] == "abc\0"
 
+        def test_unicode_conversion(self):
+            b = create_unicode_buffer(b"abc")
+            assert len(b) == 4 # trailing nul char
+            assert sizeof(b) == 4 * sizeof(c_wchar)
+            assert type(b[0]) is unicode
+            assert b[0] == "a"
+            assert b[:] == "abc\0"
+
diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_callback_traceback.py b/pypy/module/test_lib_pypy/ctypes_tests/test_callback_traceback.py
--- a/pypy/module/test_lib_pypy/ctypes_tests/test_callback_traceback.py
+++ b/pypy/module/test_lib_pypy/ctypes_tests/test_callback_traceback.py
@@ -5,7 +5,7 @@
 
 def callback_func(arg):
     42 / arg
-    raise ValueError, arg
+    raise ValueError(arg)
 
 class TestCallbackTraceback:
     # When an exception is raised in a ctypes callback function, the C
diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_cfuncs.py b/pypy/module/test_lib_pypy/ctypes_tests/test_cfuncs.py
--- a/pypy/module/test_lib_pypy/ctypes_tests/test_cfuncs.py
+++ b/pypy/module/test_lib_pypy/ctypes_tests/test_cfuncs.py
@@ -190,7 +190,7 @@
     class stdcall_dll(WinDLL):
         def __getattr__(self, name):
             if name[:2] == '__' and name[-2:] == '__':
-                raise AttributeError, name
+                raise AttributeError(name)
             func = self._FuncPtr(("s_" + name, self))
             setattr(self, name, func)
             return func
diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_extra.py b/pypy/module/test_lib_pypy/ctypes_tests/test_extra.py
--- a/pypy/module/test_lib_pypy/ctypes_tests/test_extra.py
+++ b/pypy/module/test_lib_pypy/ctypes_tests/test_extra.py
@@ -174,7 +174,7 @@
         assert not c_float(0.0)
         assert not c_double(0.0)
         assert not c_ulonglong(0)
-        assert c_ulonglong(2L**42)
+        assert c_ulonglong(2**42)
 
         assert c_char_p("hello")
         assert c_char_p("")
@@ -230,7 +230,7 @@
         assert isinstance(c_void_p.from_param((c_int * 4)()), c_int*4)
 
     def test_array_mul(self):
-        assert c_int * 10 == 10 * c_int == c_int * 10L == 10L * c_int
+        assert c_int * 10 == 10 * c_int
         py.test.raises(TypeError, 'c_int * c_int')
         py.test.raises(TypeError, 'c_int * (-1.5)')
         py.test.raises(TypeError, 'c_int * "foo"')
diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_functions.py b/pypy/module/test_lib_pypy/ctypes_tests/test_functions.py
--- a/pypy/module/test_lib_pypy/ctypes_tests/test_functions.py
+++ b/pypy/module/test_lib_pypy/ctypes_tests/test_functions.py
@@ -77,7 +77,7 @@
             return
         f = dll._testfunc_i_bhilfd
         f.argtypes = [c_byte, c_wchar, c_int, c_long, c_float, c_double]
-        result = f(1, u"x", 3, 4, 5.0, 6.0)
+        result = f(1, "x", 3, 4, 5.0, 6.0)
         assert result == 139
         assert type(result) == int
 
@@ -90,14 +90,14 @@
         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)
-        assert result == u'\x00'
+        assert result == '\x00'
 
     def test_char_result(self):
         f = dll._testfunc_i_bhilfd
         f.argtypes = [c_byte, c_short, c_int, c_long, c_float, c_double]
         f.restype = c_char
         result = f(0, 0, 0, 0, 0, 0)
-        assert result == '\x00'
+        assert result == b'\x00'
 
     def test_voidresult(self):
         f = dll._testfunc_v
diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_guess_argtypes.py b/pypy/module/test_lib_pypy/ctypes_tests/test_guess_argtypes.py
--- a/pypy/module/test_lib_pypy/ctypes_tests/test_guess_argtypes.py
+++ b/pypy/module/test_lib_pypy/ctypes_tests/test_guess_argtypes.py
@@ -19,10 +19,10 @@
 
     assert guess(13) == c_int
     assert guess(0) == c_int
-    assert guess('xca') == c_char_p
+    assert guess(b'xca') == c_char_p
     assert guess(None) == c_void_p
     assert guess(c_int(3)) == c_int
-    assert guess(u'xca') == c_wchar_p
+    assert guess('xca') == c_wchar_p
 
     class Stuff:
         pass
@@ -37,5 +37,5 @@
     import conftest
     dll = CDLL(str(conftest.sofile))
     wcslen = dll.my_wcslen
-    text = u"Some long unicode string"
+    text = "Some long unicode string"
     assert wcslen(text) == len(text)
diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_keepalive.py b/pypy/module/test_lib_pypy/ctypes_tests/test_keepalive.py
--- a/pypy/module/test_lib_pypy/ctypes_tests/test_keepalive.py
+++ b/pypy/module/test_lib_pypy/ctypes_tests/test_keepalive.py
@@ -219,7 +219,7 @@
         x = c_char_p(xs)
         del xs
         import gc; gc.collect()
-        print 'x =', repr(x)
+        print('x = %r' % x)
         assert x.value == 'hellohello'
         assert x._objects == 'hellohello'
         #
@@ -243,8 +243,8 @@
             dat.dsize = 15
             del xs
             import gc; gc.collect()
-            print 'dat.dptr =', repr(dat.dptr)
-            print 'dat._objects =', repr(dat._objects)
+            print('dat.dptr = %r' % dat.dptr)
+            print('dat._objects = %r' % dat._objects)
             assert dat.dptr == "hellohello"
             assert dat._objects.keys() == ['0']
 
@@ -255,7 +255,7 @@
             dat.dptr = xs
             del xs
             import gc; gc.collect()
-            print 'dat.dptr =', repr(dat.dptr)
-            print 'dat._objects =', repr(dat._objects)
+            print('dat.dptr = %r' % dat.dptr)
+            print('dat._objects = %r' % dat._objects)
             assert dat.dptr == "hellohello"
             assert dat._objects.keys() == ['0']
diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_keeprefs.py b/pypy/module/test_lib_pypy/ctypes_tests/test_keeprefs.py
--- a/pypy/module/test_lib_pypy/ctypes_tests/test_keeprefs.py
+++ b/pypy/module/test_lib_pypy/ctypes_tests/test_keeprefs.py
@@ -102,29 +102,29 @@
         x = X()
         i = c_char_p("abc def")
         from sys import getrefcount as grc
-        print "2?", grc(i)
+        print("2?", grc(i))
         x.p = pointer(i)
-        print "3?", grc(i)
+        print("3?", grc(i))
         for i in range(320):
             c_int(99)
             x.p[0]
-        print x.p[0]
+        print(x.p[0])
 ##        del x
-##        print "2?", grc(i)
+##        print("2?", grc(i))
 ##        del i
         import gc
         gc.collect()
         for i in range(320):
             c_int(99)
             x.p[0]
-        print x.p[0]
-        print x.p.contents
-##        print x._objects
+        print(x.p[0])
+        print(x.p.contents)
+##        print(x._objects)
 
         x.p[0] = "spam spam"
 ##        print x.p[0]
-        print "+" * 42
-        print x._objects
+        print("+" * 42)
+        print(x._objects)
 
 class TestPointerToStructure:
     def test(self):
diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_loading.py b/pypy/module/test_lib_pypy/ctypes_tests/test_loading.py
--- a/pypy/module/test_lib_pypy/ctypes_tests/test_loading.py
+++ b/pypy/module/test_lib_pypy/ctypes_tests/test_loading.py
@@ -1,7 +1,7 @@
 import py
 from ctypes import *
 import sys
-import os, StringIO
+import os
 from ctypes.util import find_library
 from ctypes.test import is_resource_enabled
 
@@ -16,8 +16,8 @@
     libc_name = find_library("c")
 
 if True or is_resource_enabled("printing"):
-    print >> sys.stderr, "\tfind_library('c') -> ", find_library('c')
-    print >> sys.stderr, "\tfind_library('m') -> ", find_library('m')
+    print("\tfind_library('c') -> ", find_library('c'), file=sys.stderr)
+    print("\tfind_library('m') -> ", find_library('m'), file=sys.stderr)
 
 class TestLoader:
 
@@ -46,8 +46,8 @@
     if os.name in ("nt", "ce"):
         def test_load_library(self):
             if is_resource_enabled("printing"):
-                print find_library("kernel32")
-                print find_library("user32")
+                print(find_library("kernel32"))
+                print(find_library("user32"))
 
             if os.name == "nt":
                 windll.kernel32.GetModuleHandleW
diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_numbers.py b/pypy/module/test_lib_pypy/ctypes_tests/test_numbers.py
--- a/pypy/module/test_lib_pypy/ctypes_tests/test_numbers.py
+++ b/pypy/module/test_lib_pypy/ctypes_tests/test_numbers.py
@@ -13,10 +13,10 @@
     for t in types:
         fmt = t._type_
         size = struct.calcsize(fmt)
-        a = struct.unpack(fmt, ("\x00"*32)[:size])[0]
-        b = struct.unpack(fmt, ("\xFF"*32)[:size])[0]
-        c = struct.unpack(fmt, ("\x7F"+"\x00"*32)[:size])[0]
-        d = struct.unpack(fmt, ("\x80"+"\xFF"*32)[:size])[0]
+        a = struct.unpack(fmt, (b"\x00"*32)[:size])[0]
+        b = struct.unpack(fmt, (b"\xFF"*32)[:size])[0]
+        c = struct.unpack(fmt, (b"\x7F"+b"\x00"*32)[:size])[0]
+        d = struct.unpack(fmt, (b"\x80"+b"\xFF"*32)[:size])[0]
         result.append((min(a, b, c, d), max(a, b, c, d)))
     return result
 
@@ -99,11 +99,10 @@
 
     def test_floats(self):
         # c_float and c_double can be created from
-        # Python int, long and float
+        # Python int and float
         for t in float_types:
             assert t(2.0).value == 2.0
             assert t(2).value == 2.0
-            assert t(2L).value == 2.0
 
     def test_integers(self):
         # integers cannot be constructed from floats
diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_parameters.py b/pypy/module/test_lib_pypy/ctypes_tests/test_parameters.py
--- a/pypy/module/test_lib_pypy/ctypes_tests/test_parameters.py
+++ b/pypy/module/test_lib_pypy/ctypes_tests/test_parameters.py
@@ -50,7 +50,7 @@
         assert CWCHARP.from_param("abc") == "abcabcabc"
 
     def test_pointer_subclasses(self):
-        from ctypes import *
+        from ctypes import POINTER, c_void_p
 
         Void_pp = POINTER(c_void_p)
         class My_void_p(c_void_p):
@@ -72,8 +72,8 @@
         assert c_char_p.from_param(s)._obj is s
 
         # new in 0.9.1: convert (encode) unicode to ascii
-        assert c_char_p.from_param(u"123")._obj == "123"
-        raises(UnicodeEncodeError, c_char_p.from_param, u"123\377")
+        assert c_char_p.from_param("123")._obj == b"123"
+        raises(UnicodeEncodeError, c_char_p.from_param, "123\377")
 
         raises(TypeError, c_char_p.from_param, 42)
 
@@ -90,16 +90,16 @@
         except ImportError:
 ##            print "(No c_wchar_p)"
             return
-        s = u"123"
+        s = "123"
         if sys.platform == "win32":
             assert c_wchar_p.from_param(s)._obj is s
             raises(TypeError, c_wchar_p.from_param, 42)
 
             # new in 0.9.1: convert (decode) ascii to unicode
-            assert c_wchar_p.from_param("123")._obj == u"123"
-        raises(UnicodeDecodeError, c_wchar_p.from_param, "123\377")
+            assert c_wchar_p.from_param(b"123")._obj == "123"
+        raises(UnicodeDecodeError, c_wchar_p.from_param, b"123\377")
 
-        pa = c_wchar_p.from_param(c_wchar_p(u"123"))
+        pa = c_wchar_p.from_param(c_wchar_p("123"))
         assert type(pa) == c_wchar_p
 
     def test_int_pointers(self):
diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_pointers.py b/pypy/module/test_lib_pypy/ctypes_tests/test_pointers.py
--- a/pypy/module/test_lib_pypy/ctypes_tests/test_pointers.py
+++ b/pypy/module/test_lib_pypy/ctypes_tests/test_pointers.py
@@ -4,8 +4,8 @@
 
 ctype_types = [c_byte, c_ubyte, c_short, c_ushort, c_int, c_uint,
                  c_long, c_ulong, c_longlong, c_ulonglong, c_double, c_float]
-python_types = [int, int, int, int, int, long,
-                int, long, long, long, float, float]
+python_types = [int, int, int, int, int, int,
+                int, int, int, int, float, float]
 
 def setup_module(mod):
     import conftest
@@ -231,12 +231,12 @@
     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:
-            assert c_void_p(0xFFFFFFFFL).value == c_void_p(-1).value
-            assert c_void_p(0xFFFFFFFFFFFFFFFFL).value == c_void_p(-1).value
+            assert c_void_p(0xFFFFFFFF).value == c_void_p(-1).value
+            assert c_void_p(0xFFFFFFFFFFFFFFFF).value == c_void_p(-1).value
         elif sizeof(c_void_p) == 8:
-            assert c_void_p(0xFFFFFFFFL).value == 0xFFFFFFFFL
-            assert c_void_p(0xFFFFFFFFFFFFFFFFL).value == c_void_p(-1).value
-            assert c_void_p(0xFFFFFFFFFFFFFFFFFFFFFFFFL).value == c_void_p(-1).value
+            assert c_void_p(0xFFFFFFFF).value == 0xFFFFFFFF
+            assert c_void_p(0xFFFFFFFFFFFFFFFF).value == c_void_p(-1).value
+            assert c_void_p(0xFFFFFFFFFFFFFFFFFFFFFFFF).value == c_void_p(-1).value
 
         py.test.raises(TypeError, c_void_p, 3.14) # make sure floats are NOT accepted
         py.test.raises(TypeError, c_void_p, object()) # nor other objects
diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_prototypes.py b/pypy/module/test_lib_pypy/ctypes_tests/test_prototypes.py
--- a/pypy/module/test_lib_pypy/ctypes_tests/test_prototypes.py
+++ b/pypy/module/test_lib_pypy/ctypes_tests/test_prototypes.py
@@ -85,7 +85,7 @@
     # View the bits in `a` as unsigned instead.
     import struct
     num_bits = struct.calcsize("P") * 8 # num bits in native machine address
-    a += 1L << num_bits
+    a += 1 << num_bits
     assert a >= 0
     return a
 
@@ -170,7 +170,7 @@
             pass
         else:
             assert None == func(c_wchar_p(None))
-            assert u"123" == func(c_wchar_p(u"123"))
+            assert "123" == func(c_wchar_p("123"))
 
     def test_instance(self):
         func = testdll._testfunc_p_p
@@ -206,24 +206,24 @@
             func.argtypes = POINTER(c_wchar),
 
             assert None == func(None)
-            assert u"123" == func(u"123")
+            assert "123" == func("123")
             assert None == func(c_wchar_p(None))
-            assert u"123" == func(c_wchar_p(u"123"))
+            assert "123" == func(c_wchar_p("123"))
 
-            assert u"123" == func(c_wbuffer(u"123"))
+            assert "123" == func(c_wbuffer("123"))
             ca = c_wchar("a")
-            assert u"a" == func(pointer(ca))[0]
-            assert u"a" == func(byref(ca))[0]
+            assert "a" == func(pointer(ca))[0]
+            assert "a" == func(byref(ca))[0]
 
         def test_c_wchar_p_arg(self):
             func = self.func
             func.restype = c_wchar_p
             func.argtypes = c_wchar_p,
 
-            c_wchar_p.from_param(u"123")
+            c_wchar_p.from_param("123")
 
             assert None == func(None)
-            assert "123" == func(u"123")
+            assert "123" == func("123")
             assert None == func(c_wchar_p(None))
             assert "123" == func(c_wchar_p("123"))
 
diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_slicing.py b/pypy/module/test_lib_pypy/ctypes_tests/test_slicing.py
--- a/pypy/module/test_lib_pypy/ctypes_tests/test_slicing.py
+++ b/pypy/module/test_lib_pypy/ctypes_tests/test_slicing.py
@@ -30,9 +30,9 @@
         from operator import setslice
 
         # TypeError: int expected instead of str instance
-        raises(TypeError, setslice, a, 0, 5, "abcde")
+        raises(TypeError, setslice, a, 0, 5, b"abcde")
         # TypeError: int expected instead of str instance
-        raises(TypeError, setslice, a, 0, 5, ["a", "b", "c", "d", "e"])
+        raises(TypeError, setslice, a, 0, 5, [b"a", b"b", b"c", b"d", b"e"])
         # TypeError: int expected instead of float instance
         raises(TypeError, setslice, a, 0, 5, [1, 2, 3, 4, 3.14])
         # ValueError: Can only assign sequence of same size
@@ -48,7 +48,7 @@
 
         import operator
         raises(TypeError, operator.setslice,
-                          res, 0, 5, u"abcde")
+                          res, 0, 5, "abcde")
         dll.my_free(res)
 
         dll.my_strdup.restype = POINTER(c_byte)
@@ -90,7 +90,7 @@
         pass
     else:
         def test_wchar_ptr(self):
-            s = u"abcdefghijklmnopqrstuvwxyz\0"
+            s = "abcdefghijklmnopqrstuvwxyz\0"
 
             dll.my_wcsdup.restype = POINTER(c_wchar)
             dll.my_wcsdup.argtypes = POINTER(c_wchar),
@@ -100,7 +100,7 @@
 
             import operator
             raises(TypeError, operator.setslice,
-                              res, 0, 5, u"abcde")
+                              res, 0, 5, "abcde")
             dll.my_free(res)
 
             if sizeof(c_wchar) == sizeof(c_short):
diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_strings.py b/pypy/module/test_lib_pypy/ctypes_tests/test_strings.py
--- a/pypy/module/test_lib_pypy/ctypes_tests/test_strings.py
+++ b/pypy/module/test_lib_pypy/ctypes_tests/test_strings.py
@@ -58,17 +58,17 @@
         def test(self):
             BUF = c_wchar * 4
 
-            buf = BUF(u"a", u"b", u"c")
-            assert buf.value == u"abc"
+            buf = BUF("a", "b", "c")
+            assert buf.value == "abc"
 
-            buf.value = u"ABCD"
-            assert buf.value == u"ABCD"
+            buf.value = "ABCD"
+            assert buf.value == "ABCD"
 
-            buf.value = u"x"
-            assert buf.value == u"x"
+            buf.value = "x"
+            assert buf.value == "x"
 
-            buf[1] = u"Z"
-            assert buf.value == u"xZCD"
+            buf[1] = "Z"
+            assert buf.value == "xZCD"
 
 # XXX write real tests for w_char
 
@@ -80,7 +80,7 @@
     for i in items:
         func(arg); func(arg); func(arg); func(arg); func(arg)
     stop = clock()
-    print "%20s: %.2f us" % (msg, ((stop-start)*1e6/5/rep))
+    print("%20s: %.2f us" % (msg, ((stop-start)*1e6/5/rep)))
 
 def check_perf():
     # Construct 5 objects
diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_structures.py b/pypy/module/test_lib_pypy/ctypes_tests/test_structures.py
--- a/pypy/module/test_lib_pypy/ctypes_tests/test_structures.py
+++ b/pypy/module/test_lib_pypy/ctypes_tests/test_structures.py
@@ -275,15 +275,15 @@
             _fields_ = [("name", c_wchar * 12),
                         ("age", c_int)]
 
-        p = PersonW(u"Someone")
+        p = PersonW("Someone")
         assert p.name == "Someone"
 
-        assert PersonW(u"1234567890").name == u"1234567890"
-        assert PersonW(u"12345678901").name == u"12345678901"
+        assert PersonW("1234567890").name == "1234567890"
+        assert PersonW("12345678901").name == "12345678901"
         # exact fit
-        assert PersonW(u"123456789012").name == u"123456789012"
+        assert PersonW("123456789012").name == "123456789012"
         #too long
-        raises(ValueError, PersonW, u"1234567890123")
+        raises(ValueError, PersonW, "1234567890123")
 
     def test_init_errors(self):
         py.test.skip("not implemented error details")
@@ -321,7 +321,7 @@
         # XXX remove this, py.test.raises returns a nice inspectable object
         try:
             func(*args)
-        except Exception, detail:
+        except Exception as detail:
             return detail.__class__, str(detail)
 
 
@@ -441,11 +441,6 @@
         p = pointer(obj)
         assert p.contents._b_base_ is p
 
-    def test_unicode_field_name(self):
-        # setattr autoconverts field names to bytes
-        class X(Structure):
-            _fields_ = [(u"i", c_int)]
-
 class TestPointerMember(BaseCTypesTestChecker):
 
     def test_1(self):
@@ -495,11 +490,11 @@
 
         try:
             Recursive._fields_ = [("next", Recursive)]
-        except AttributeError, details:
+        except AttributeError as details:
             assert ("Structure or union cannot contain itself" in
                             str(details))
         else:
-            raise AssertionError, "Structure or union cannot contain itself"
+            raise AssertionError("Structure or union cannot contain itself")
 
 
     def test_vice_versa(self):
@@ -513,11 +508,11 @@
 
         try:
             Second._fields_ = [("first", First)]
-        except AttributeError, details:
+        except AttributeError as details:
             assert ("_fields_ is final" in
                             str(details))
         else:
-            raise AssertionError, "AttributeError not raised"
+            raise AssertionError("AttributeError not raised")
 
     def test_nonfinal_struct(self):
         class X(Structure):
@@ -544,7 +539,7 @@
             _fields_ = [('x', c_int)]
 
             def __getattr__(self, name):
-                raise AttributeError, name
+                raise AttributeError(name)
 
         x = X()
         assert x.x == 0
diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_unicode.py b/pypy/module/test_lib_pypy/ctypes_tests/test_unicode.py
--- a/pypy/module/test_lib_pypy/ctypes_tests/test_unicode.py
+++ b/pypy/module/test_lib_pypy/ctypes_tests/test_unicode.py
@@ -29,47 +29,47 @@
         def test_ascii_strict(self):
             ctypes.set_conversion_mode("ascii", "strict")
             # no conversions take place with unicode arguments
-            assert wcslen(u"abc") == 3
-            assert wcslen(u"ab\u2070") == 3
+            assert wcslen("abc") == 3
+            assert wcslen("ab\u2070") == 3
             # string args are converted
-            assert wcslen("abc") == 3
-            py.test.raises(ctypes.ArgumentError, wcslen, "ab�")
+            assert wcslen(b"abc") == 3
+            py.test.raises(ctypes.ArgumentError, wcslen, b"aba")
 
         def test_ascii_replace(self):
             ctypes.set_conversion_mode("ascii", "replace")
-            assert wcslen(u"abc") == 3
-            assert wcslen(u"ab\u2070") == 3
             assert wcslen("abc") == 3
-            assert wcslen("ab�") == 3
+            assert wcslen("ab\u2070") == 3
+            assert wcslen(b"abc") == 3
+            assert wcslen(b"ab�") == 3
 
         def test_ascii_ignore(self):
             ctypes.set_conversion_mode("ascii", "ignore")
-            assert wcslen(u"abc") == 3
-            assert wcslen(u"ab\u2070") == 3
+            assert wcslen("abc") == 3
+            assert wcslen("ab\u2070") == 3
             # ignore error mode skips non-ascii characters
-            assert wcslen("abc") == 3
-            assert wcslen("����") == 0
+            assert wcslen(b"abc") == 3
+            assert wcslen(b"����") == 0
 
         def test_latin1_strict(self):
             ctypes.set_conversion_mode("latin-1", "strict")
-            assert wcslen(u"abc") == 3
-            assert wcslen(u"ab\u2070") == 3
             assert wcslen("abc") == 3
-            assert wcslen("����") == 4
+            assert wcslen("ab\u2070") == 3
+            assert wcslen(b"abc") == 3
+            assert wcslen(b"����") == 4
 
         def test_buffers(self):
             ctypes.set_conversion_mode("ascii", "strict")
-            buf = ctypes.create_unicode_buffer("abc")
+            buf = ctypes.create_unicode_buffer(b"abc")
             assert len(buf) == 3+1
 
             ctypes.set_conversion_mode("ascii", "replace")
-            buf = ctypes.create_unicode_buffer("ab���")
-            assert buf[:] == u"ab\uFFFD\uFFFD\uFFFD\0"
+            buf = ctypes.create_unicode_buffer(b"ab���")
+            assert buf[:] == "ab\uFFFD\uFFFD\uFFFD\0"
 
             ctypes.set_conversion_mode("ascii", "ignore")
-            buf = ctypes.create_unicode_buffer("ab���")
+            buf = ctypes.create_unicode_buffer(b"ab���")
             # is that correct? not sure.  But with 'ignore', you get what you pay for..
-            assert buf[:] == u"ab\0\0\0\0"
+            assert buf[:] == "ab\0\0\0\0"
 
     class TestString(TestUnicode):
         def setup_method(self, method):
@@ -84,33 +84,33 @@
 
         def test_ascii_replace(self):
             ctypes.set_conversion_mode("ascii", "strict")
+            assert func(b"abc") == "abc"
             assert func("abc") == "abc"
-            assert func(u"abc") == "abc"
-            raises(ctypes.ArgumentError, func, u"ab�")
+            raises(ctypes.ArgumentError, func, "ab�")
 
         def test_ascii_ignore(self):
             ctypes.set_conversion_mode("ascii", "ignore")
             assert func("abc") == "abc"
-            assert func(u"abc") == "abc"
-            assert func(u"����") == ""
+            assert func("abc") == "abc"
+            assert func("����") == ""
 
         def test_ascii_replace_2(self):
             ctypes.set_conversion_mode("ascii", "replace")
             assert func("abc") == "abc"
-            assert func(u"abc") == "abc"
-            assert func(u"����") == "????"
+            assert func("abc") == "abc"
+            assert func("����") == "????"
 
         def test_buffers(self):
             ctypes.set_conversion_mode("ascii", "strict")
-            buf = ctypes.create_string_buffer(u"abc")
+            buf = ctypes.create_string_buffer("abc")
             assert len(buf) == 3+1
 
             ctypes.set_conversion_mode("ascii", "replace")
-            buf = ctypes.create_string_buffer(u"ab���")
+            buf = ctypes.create_string_buffer("ab���")
             assert buf[:] == "ab???\0"
 
             ctypes.set_conversion_mode("ascii", "ignore")
-            buf = ctypes.create_string_buffer(u"ab���")
+            buf = ctypes.create_string_buffer("ab���")
             # is that correct? not sure.  But with 'ignore', you get what you pay for..
             assert buf[:] == "ab\0\0\0\0"
 


More information about the pypy-commit mailing list