Author: Amaury Forgeot d'Arc <[email protected]>
Branch: py3k
Changeset: r54867:7c743ad72f55
Date: 2012-05-02 00:59 +0200
http://bitbucket.org/pypy/pypy/changeset/7c743ad72f55/
Log: Adapt many cpyext tests to python3.
diff --git a/pypy/module/cpyext/dictobject.py b/pypy/module/cpyext/dictobject.py
--- a/pypy/module/cpyext/dictobject.py
+++ b/pypy/module/cpyext/dictobject.py
@@ -111,19 +111,19 @@
def PyDict_Keys(space, w_obj):
"""Return a PyListObject containing all the keys from the dictionary,
as in the dictionary method dict.keys()."""
- return space.call_method(w_obj, "keys")
+ return space.call_function(space.w_list, space.call_method(w_obj, "keys"))
@cpython_api([PyObject], PyObject)
def PyDict_Values(space, w_obj):
"""Return a PyListObject containing all the values from the
dictionary p, as in the dictionary method dict.values()."""
- return space.call_method(w_obj, "values")
+ return space.call_function(space.w_list, space.call_method(w_obj,
"values"))
@cpython_api([PyObject], PyObject)
def PyDict_Items(space, w_obj):
"""Return a PyListObject containing all the items from the
dictionary, as in the dictionary method dict.items()."""
- return space.call_method(w_obj, "items")
+ return space.call_function(space.w_list, space.call_method(w_obj, "items"))
@cpython_api([PyObject, Py_ssize_tP, PyObjectP, PyObjectP], rffi.INT_real,
error=CANNOT_FAIL)
def PyDict_Next(space, w_dict, ppos, pkey, pvalue):
diff --git a/pypy/module/cpyext/eval.py b/pypy/module/cpyext/eval.py
--- a/pypy/module/cpyext/eval.py
+++ b/pypy/module/cpyext/eval.py
@@ -94,7 +94,7 @@
Py_eval_input = 258
def compile_string(space, source, filename, start, flags=0):
- w_source = space.wrap(source)
+ w_source = space.wrapbytes(source)
start = rffi.cast(lltype.Signed, start)
if start == Py_file_input:
mode = 'exec'
diff --git a/pypy/module/cpyext/funcobject.py b/pypy/module/cpyext/funcobject.py
--- a/pypy/module/cpyext/funcobject.py
+++ b/pypy/module/cpyext/funcobject.py
@@ -116,9 +116,10 @@
return [space.str_w(w_item) for w_item in space.fixedview(w_list)]
@cpython_api([rffi.INT_real, rffi.INT_real, rffi.INT_real, rffi.INT_real,
+ rffi.INT_real,
PyObject, PyObject, PyObject, PyObject, PyObject, PyObject,
PyObject, PyObject, rffi.INT_real, PyObject], PyCodeObject)
-def PyCode_New(space, argcount, nlocals, stacksize, flags,
+def PyCode_New(space, argcount, kwonlyargcount, nlocals, stacksize, flags,
w_code, w_consts, w_names, w_varnames, w_freevars, w_cellvars,
w_filename, w_funcname, firstlineno, w_lnotab):
"""Return a new code object. If you need a dummy code object to
@@ -147,6 +148,7 @@
"""Creates a new empty code object with the specified source location."""
return space.wrap(PyCode(space,
argcount=0,
+ kwonlyargcount=0,
nlocals=0,
stacksize=0,
flags=0,
diff --git a/pypy/module/cpyext/import_.py b/pypy/module/cpyext/import_.py
--- a/pypy/module/cpyext/import_.py
+++ b/pypy/module/cpyext/import_.py
@@ -24,7 +24,7 @@
w_builtin = space.getitem(w_globals, space.wrap('__builtins__'))
else:
# No globals -- use standard builtins, and fake globals
- w_builtin = space.getbuiltinmodule('__builtin__')
+ w_builtin = space.getbuiltinmodule('builtins')
w_globals = space.newdict()
space.setitem(w_globals, space.wrap("__builtins__"), w_builtin)
@@ -121,5 +121,6 @@
pathname = code.co_filename
w_mod = importing.add_module(space, w_name)
space.setattr(w_mod, space.wrap('__file__'), space.wrap(pathname))
- importing.exec_code_module(space, w_mod, code, pathname)
+ cpathname = importing.make_compiled_pathname(pathname)
+ importing.exec_code_module(space, w_mod, code, pathname, cpathname)
return w_mod
diff --git a/pypy/module/cpyext/intobject.py b/pypy/module/cpyext/intobject.py
--- a/pypy/module/cpyext/intobject.py
+++ b/pypy/module/cpyext/intobject.py
@@ -76,12 +76,8 @@
unsigned long. This function does not check for overflow.
"""
w_int = space.int(w_obj)
- if space.is_true(space.isinstance(w_int, space.w_int)):
- num = space.int_w(w_int)
- return r_uint(num)
- else:
- num = space.bigint_w(w_int)
- return num.uintmask()
+ num = space.bigint_w(w_int)
+ return num.uintmask()
@cpython_api([PyObject], lltype.Signed, error=CANNOT_FAIL)
def PyInt_AS_LONG(space, w_int):
diff --git a/pypy/module/cpyext/longobject.py b/pypy/module/cpyext/longobject.py
--- a/pypy/module/cpyext/longobject.py
+++ b/pypy/module/cpyext/longobject.py
@@ -9,7 +9,7 @@
from pypy.rlib.rarithmetic import intmask
-PyLong_Check, PyLong_CheckExact = build_type_checkers("Long")
+PyLong_Check, PyLong_CheckExact = build_type_checkers("Long", "w_int")
@cpython_api([lltype.Signed], PyObject)
def PyLong_FromLong(space, val):
diff --git a/pypy/module/cpyext/mapping.py b/pypy/module/cpyext/mapping.py
--- a/pypy/module/cpyext/mapping.py
+++ b/pypy/module/cpyext/mapping.py
@@ -22,20 +22,23 @@
def PyMapping_Keys(space, w_obj):
"""On success, return a list of the keys in object o. On failure, return
NULL.
This is equivalent to the Python expression o.keys()."""
- return space.call_method(w_obj, "keys")
+ return space.call_function(space.w_list,
+ space.call_method(w_obj, "keys"))
@cpython_api([PyObject], PyObject)
def PyMapping_Values(space, w_obj):
"""On success, return a list of the values in object o. On failure, return
NULL. This is equivalent to the Python expression o.values()."""
- return space.call_method(w_obj, "values")
+ return space.call_function(space.w_list,
+ space.call_method(w_obj, "values"))
@cpython_api([PyObject], PyObject)
def PyMapping_Items(space, w_obj):
"""On success, return a list of the items in object o, where each item is
a tuple
containing a key-value pair. On failure, return NULL. This is equivalent
to
the Python expression o.items()."""
- return space.call_method(w_obj, "items")
+ return space.call_function(space.w_list,
+ space.call_method(w_obj, "items"))
@cpython_api([PyObject, CONST_STRING], PyObject)
def PyMapping_GetItemString(space, w_obj, key):
diff --git a/pypy/module/cpyext/object.py b/pypy/module/cpyext/object.py
--- a/pypy/module/cpyext/object.py
+++ b/pypy/module/cpyext/object.py
@@ -249,26 +249,6 @@
function."""
return space.call_function(space.w_unicode, w_obj)
-@cpython_api([PyObject, PyObject], rffi.INT_real, error=-1)
-def PyObject_Compare(space, w_o1, w_o2):
- """
- Compare the values of o1 and o2 using a routine provided by o1, if one
- exists, otherwise with a routine provided by o2. Returns the result of the
- comparison on success. On error, the value returned is undefined; use
- PyErr_Occurred() to detect an error. This is equivalent to the Python
- expression cmp(o1, o2)."""
- return space.int_w(space.cmp(w_o1, w_o2))
-
-@cpython_api([PyObject, PyObject, rffi.INTP], rffi.INT_real, error=-1)
-def PyObject_Cmp(space, w_o1, w_o2, result):
- """Compare the values of o1 and o2 using a routine provided by o1, if one
- exists, otherwise with a routine provided by o2. The result of the
- comparison is returned in result. Returns -1 on failure. This is the
- equivalent of the Python statement result = cmp(o1, o2)."""
- res = space.int_w(space.cmp(w_o1, w_o2))
- result[0] = rffi.cast(rffi.INT, res)
- return 0
-
@cpython_api([PyObject, PyObject, rffi.INT_real], PyObject)
def PyObject_RichCompare(space, w_o1, w_o2, opid_int):
"""Compare the values of o1 and o2 using the operation specified by opid,
diff --git a/pypy/module/cpyext/pyfile.py b/pypy/module/cpyext/pyfile.py
--- a/pypy/module/cpyext/pyfile.py
+++ b/pypy/module/cpyext/pyfile.py
@@ -1,6 +1,6 @@
from pypy.rpython.lltypesystem import rffi, lltype
from pypy.module.cpyext.api import (
- cpython_api, CANNOT_FAIL, CONST_STRING, FILEP, build_type_checkers)
+ cpython_api, CANNOT_FAIL, CONST_STRING, FILEP)
from pypy.module.cpyext.pyobject import PyObject, borrow_from
from pypy.module.cpyext.object import Py_PRINT_RAW
from pypy.interpreter.error import OperationError
@@ -38,9 +38,9 @@
On success, return a new file object that is opened on the file given by
filename, with a file mode given by mode, where mode has the same
semantics as the standard C routine fopen(). On failure, return NULL."""
- w_filename = space.wrap(rffi.charp2str(filename))
+ w_filename = space.wrapbytes(rffi.charp2str(filename))
w_mode = space.wrap(rffi.charp2str(mode))
- return space.call_method(space.builtin, 'file', w_filename, w_mode)
+ return space.call_method(space.builtin, 'open', w_filename, w_mode)
@cpython_api([FILEP, CONST_STRING, CONST_STRING, rffi.VOIDP], PyObject)
def PyFile_FromFile(space, fp, name, mode, close):
diff --git a/pypy/module/cpyext/structmember.py
b/pypy/module/cpyext/structmember.py
--- a/pypy/module/cpyext/structmember.py
+++ b/pypy/module/cpyext/structmember.py
@@ -55,7 +55,7 @@
if member_type == T_STRING:
result = rffi.cast(rffi.CCHARPP, addr)
if result[0]:
- w_result = PyString_FromString(space, result[0])
+ w_result = PyUnicode_FromString(space, result[0])
else:
w_result = space.w_None
elif member_type == T_STRING_INPLACE:
diff --git a/pypy/module/cpyext/test/foo.c b/pypy/module/cpyext/test/foo.c
--- a/pypy/module/cpyext/test/foo.c
+++ b/pypy/module/cpyext/test/foo.c
@@ -89,7 +89,7 @@
static PyObject *
foo_get_name(PyObject *self, void *closure)
{
- return PyString_FromStringAndSize("Foo Example", 11);
+ return PyUnicode_FromStringAndSize("Foo Example", 11);
}
static PyObject *
diff --git a/pypy/module/cpyext/test/test_cell.py
b/pypy/module/cpyext/test/test_cell.py
--- a/pypy/module/cpyext/test/test_cell.py
+++ b/pypy/module/cpyext/test/test_cell.py
@@ -16,5 +16,5 @@
return o
return g
- cell_type = type(f(0).func_closure[0])
+ cell_type = type(f(0).__closure__[0])
assert d["cell"] is cell_type
diff --git a/pypy/module/cpyext/test/test_dictobject.py
b/pypy/module/cpyext/test/test_dictobject.py
--- a/pypy/module/cpyext/test/test_dictobject.py
+++ b/pypy/module/cpyext/test/test_dictobject.py
@@ -139,9 +139,13 @@
api.Py_DecRef(py_dict) # release borrowed references
assert space.eq_w(space.newlist(keys_w),
- space.call_method(w_dict, "keys"))
+ space.call_function(
+ space.w_list,
+ space.call_method(w_dict, "keys")))
assert space.eq_w(space.newlist(values_w),
- space.call_method(w_dict, "values"))
+ space.call_function(
+ space.w_list,
+ space.call_method(w_dict, "values")))
def test_dictproxy(self, space, api):
w_dict = space.sys.get('modules')
diff --git a/pypy/module/cpyext/test/test_eval.py
b/pypy/module/cpyext/test/test_eval.py
--- a/pypy/module/cpyext/test/test_eval.py
+++ b/pypy/module/cpyext/test/test_eval.py
@@ -117,7 +117,7 @@
flags = lltype.malloc(PyCompilerFlags, flavor='raw')
flags.c_cf_flags = rffi.cast(rffi.INT, consts.PyCF_SOURCE_IS_UTF8)
w_globals = space.newdict()
- buf = rffi.str2charp("a = u'caf\xc3\xa9'")
+ buf = rffi.str2charp("a = 'caf\xc3\xa9'")
try:
api.PyRun_StringFlags(buf, Py_single_input,
w_globals, w_globals, flags)
@@ -229,7 +229,7 @@
module = self.import_extension('foo', [
("call_func", "METH_VARARGS",
"""
- PyObject *t = PyString_FromString("t");
+ PyObject *t = PyUnicode_FromString("t");
PyObject *res = PyObject_CallFunctionObjArgs(
PyTuple_GetItem(args, 0),
Py_None, NULL);
@@ -238,8 +238,8 @@
"""),
("call_method", "METH_VARARGS",
"""
- PyObject *t = PyString_FromString("t");
- PyObject *count = PyString_FromString("count");
+ PyObject *t = PyUnicode_FromString("t");
+ PyObject *count = PyUnicode_FromString("count");
PyObject *res = PyObject_CallMethodObjArgs(
PyTuple_GetItem(args, 0),
count, t, NULL);
@@ -277,15 +277,15 @@
mod = module.exec_code(code)
assert mod.__name__ == "cpyext_test_modname"
assert mod.__file__ == "someFile"
- print dir(mod)
- print mod.__dict__
+ print(dir(mod))
+ print(mod.__dict__)
assert mod.f(42) == 47
mod = module.exec_code_ex(code)
assert mod.__name__ == "cpyext_test_modname"
assert mod.__file__ == "otherFile"
- print dir(mod)
- print mod.__dict__
+ print(dir(mod))
+ print(mod.__dict__)
assert mod.f(42) == 47
def test_merge_compiler_flags(self):
@@ -301,7 +301,7 @@
assert module.get_flags() == (0, 0)
ns = {'module':module}
- exec """from __future__ import division \nif 1:
+ exec("""from __future__ import division \nif 1:
def nested_flags():
- return module.get_flags()""" in ns
+ return module.get_flags()""", ns)
assert ns['nested_flags']() == (1, 0x2000) # CO_FUTURE_DIVISION
diff --git a/pypy/module/cpyext/test/test_funcobject.py
b/pypy/module/cpyext/test/test_funcobject.py
--- a/pypy/module/cpyext/test/test_funcobject.py
+++ b/pypy/module/cpyext/test/test_funcobject.py
@@ -29,8 +29,8 @@
return C().method
""")
- w_function = space.getattr(w_method, space.wrap("im_func"))
- w_self = space.getattr(w_method, space.wrap("im_self"))
+ w_function = space.getattr(w_method, space.wrap("__func__"))
+ w_self = space.getattr(w_method, space.wrap("__self__"))
assert space.is_w(api.PyMethod_Function(w_method), w_function)
assert space.is_w(api.PyMethod_Self(w_method), w_self)
diff --git a/pypy/module/cpyext/test/test_getargs.py
b/pypy/module/cpyext/test/test_getargs.py
--- a/pypy/module/cpyext/test/test_getargs.py
+++ b/pypy/module/cpyext/test/test_getargs.py
@@ -126,37 +126,22 @@
PyBuffer_Release(&buf);
return result;
''')
- assert 'foo\0bar\0baz' == pybuffer('foo\0bar\0baz')
-
-
- def test_pyarg_parse_string_old_buffer(self):
- pybuffer = self.import_parser(
- '''
- Py_buffer buf;
- PyObject *result;
- if (!PyArg_ParseTuple(args, "s*", &buf)) {
- return NULL;
- }
- result = PyString_FromStringAndSize(buf.buf, buf.len);
- PyBuffer_Release(&buf);
- return result;
- ''')
- assert 'foo\0bar\0baz' == pybuffer(buffer('foo\0bar\0baz'))
+ assert b'foo\0bar\0baz' == pybuffer('foo\0bar\0baz')
def test_pyarg_parse_charbuf_and_length(self):
"""
- The `t#` format specifier can be used to parse a read-only 8-bit
+ The `s#` format specifier can be used to parse a read-only 8-bit
character buffer into a char* and int giving its length in bytes.
"""
charbuf = self.import_parser(
'''
char *buf;
int len;
- if (!PyArg_ParseTuple(args, "t#", &buf, &len)) {
+ if (!PyArg_ParseTuple(args, "s#", &buf, &len)) {
return NULL;
}
return PyString_FromStringAndSize(buf, len);
''')
raises(TypeError, "charbuf(10)")
- assert 'foo\0bar\0baz' == charbuf('foo\0bar\0baz')
+ assert b'foo\0bar\0baz' == charbuf('foo\0bar\0baz')
diff --git a/pypy/module/cpyext/test/test_import.py
b/pypy/module/cpyext/test/test_import.py
--- a/pypy/module/cpyext/test/test_import.py
+++ b/pypy/module/cpyext/test/test_import.py
@@ -4,9 +4,9 @@
class TestImport(BaseApiTest):
def test_import(self, space, api):
- pdb = api.PyImport_Import(space.wrap("pdb"))
- assert pdb
- assert space.getattr(pdb, space.wrap("pm"))
+ inspect = api.PyImport_Import(space.wrap("inspect"))
+ assert inspect
+ assert space.getattr(inspect, space.wrap("ismethod"))
def test_addmodule(self, space, api):
with rffi.scoped_str2charp("sys") as modname:
@@ -19,7 +19,7 @@
space.wrap('__name__'))) == 'foobar'
def test_getmoduledict(self, space, api):
- testmod = "_functools"
+ testmod = "contextlib"
w_pre_dict = api.PyImport_GetModuleDict()
assert not space.is_true(space.contains(w_pre_dict,
space.wrap(testmod)))
@@ -32,10 +32,10 @@
assert space.is_true(space.contains(w_dict, space.wrap(testmod)))
def test_reload(self, space, api):
- pdb = api.PyImport_Import(space.wrap("pdb"))
- space.delattr(pdb, space.wrap("set_trace"))
- pdb = api.PyImport_ReloadModule(pdb)
- assert space.getattr(pdb, space.wrap("set_trace"))
+ inspect = api.PyImport_Import(space.wrap("inspect"))
+ space.delattr(inspect, space.wrap("getframeinfo"))
+ inspect = api.PyImport_ReloadModule(inspect)
+ assert space.getattr(inspect, space.wrap("getframeinfo"))
class AppTestImportLogic(AppTestCpythonExtensionBase):
def test_import_logic(self):
diff --git a/pypy/module/cpyext/test/test_intobject.py
b/pypy/module/cpyext/test/test_intobject.py
--- a/pypy/module/cpyext/test/test_intobject.py
+++ b/pypy/module/cpyext/test/test_intobject.py
@@ -64,7 +64,7 @@
])
values = module.values()
types = [type(x) for x in values]
- assert types == [int, long, int, int]
+ assert types == [int, int, int, int]
def test_int_subtype(self):
module = self.import_extension(
diff --git a/pypy/module/cpyext/test/test_listobject.py
b/pypy/module/cpyext/test/test_listobject.py
--- a/pypy/module/cpyext/test/test_listobject.py
+++ b/pypy/module/cpyext/test/test_listobject.py
@@ -125,11 +125,11 @@
assert len(l) == 1
assert l[0] == 14
- l = range(6)
+ l = list(range(6))
module.setslice(l, ['a'])
assert l == [0, 'a', 4, 5]
- l = range(6)
+ l = list(range(6))
module.setslice(l, None)
assert l == [0, 4, 5]
diff --git a/pypy/module/cpyext/test/test_longobject.py
b/pypy/module/cpyext/test/test_longobject.py
--- a/pypy/module/cpyext/test/test_longobject.py
+++ b/pypy/module/cpyext/test/test_longobject.py
@@ -158,7 +158,7 @@
int little_endian, is_signed;
if (!PyArg_ParseTuple(args, "ii", &little_endian, &is_signed))
return NULL;
- return _PyLong_FromByteArray("\x9A\xBC", 2,
+ return _PyLong_FromByteArray("\\x9A\\xBC", 2,
little_endian, is_signed);
"""),
])
diff --git a/pypy/module/cpyext/test/test_memoryobject.py
b/pypy/module/cpyext/test/test_memoryobject.py
--- a/pypy/module/cpyext/test/test_memoryobject.py
+++ b/pypy/module/cpyext/test/test_memoryobject.py
@@ -7,7 +7,7 @@
space.wrap((2, 7)))):
py.test.skip("unsupported before Python 2.7")
- w_hello = space.wrap("hello")
+ w_hello = space.wrapbytes("hello")
w_view = api.PyMemoryView_FromObject(w_hello)
w_bytes = space.call_method(w_view, "tobytes")
assert space.unwrap(w_bytes) == "hello"
diff --git a/pypy/module/cpyext/test/test_methodobject.py
b/pypy/module/cpyext/test/test_methodobject.py
--- a/pypy/module/cpyext/test/test_methodobject.py
+++ b/pypy/module/cpyext/test/test_methodobject.py
@@ -44,7 +44,7 @@
'''
if(PyCFunction_Check(args)) {
PyCFunctionObject* func = (PyCFunctionObject*)args;
- return PyString_FromString(func->m_ml->ml_name);
+ return PyUnicode_FromString(func->m_ml->ml_name);
}
else {
Py_RETURN_FALSE;
@@ -108,7 +108,7 @@
ml.c_ml_meth = rffi.cast(PyCFunction_typedef,
c_func.get_llhelper(space))
- method = api.PyDescr_NewMethod(space.w_str, ml)
+ method = api.PyDescr_NewMethod(space.w_unicode, ml)
assert repr(method).startswith(
"<built-in method 'func' of 'str' object ")
diff --git a/pypy/module/cpyext/test/test_object.py
b/pypy/module/cpyext/test/test_object.py
--- a/pypy/module/cpyext/test/test_object.py
+++ b/pypy/module/cpyext/test/test_object.py
@@ -169,28 +169,6 @@
def test_type(self, space, api):
assert api.PyObject_Type(space.wrap(72)) is space.w_int
- def test_compare(self, space, api):
- assert api.PyObject_Compare(space.wrap(42), space.wrap(72)) == -1
- assert api.PyObject_Compare(space.wrap(72), space.wrap(42)) == 1
- assert api.PyObject_Compare(space.wrap("a"), space.wrap("a")) == 0
-
- def test_cmp(self, space, api):
- w = space.wrap
- with lltype.scoped_alloc(rffi.INTP.TO, 1) as ptr:
- assert api.PyObject_Cmp(w(42), w(72), ptr) == 0
- assert ptr[0] == -1
- assert api.PyObject_Cmp(w("a"), w("a"), ptr) == 0
- assert ptr[0] == 0
- assert api.PyObject_Cmp(w(u"\xe9"), w("\xe9"), ptr) < 0
- assert api.PyErr_Occurred()
- api.PyErr_Clear()
-
- def test_unicode(self, space, api):
- assert space.unwrap(api.PyObject_Unicode(space.wrap([]))) == u"[]"
- assert space.unwrap(api.PyObject_Unicode(space.wrap("e"))) == u"e"
- assert api.PyObject_Unicode(space.wrap("\xe9")) is None
- api.PyErr_Clear()
-
def test_dir(self, space, api):
w_dir = api.PyObject_Dir(space.sys)
assert space.isinstance_w(w_dir, space.w_list)
@@ -212,7 +190,6 @@
assert module.typecheck(1, int)
assert module.typecheck('foo', str)
assert module.typecheck('foo', object)
- assert module.typecheck(1L, long)
assert module.typecheck(True, bool)
assert module.typecheck(1.2, float)
assert module.typecheck(int, type)
@@ -224,7 +201,7 @@
PyObject *fname = PyTuple_GetItem(args, 0);
PyObject *obj = PyTuple_GetItem(args, 1);
- FILE *fp = fopen(PyString_AsString(fname), "wb");
+ FILE *fp = fopen(_PyUnicode_AsString(fname), "wb");
int ret;
if (fp == NULL)
Py_RETURN_NONE;
@@ -291,7 +268,7 @@
return result;
""")])
result = module.fillinfo()
- assert "hello, world." == result
+ assert b"hello, world." == result
def test_fillWithObject(self):
@@ -339,7 +316,7 @@
return result;
""")])
result = module.fillinfo()
- assert "hello, world." == result
+ assert b"hello, world." == result
class AppTestPyBuffer_Release(AppTestCpythonExtensionBase):
diff --git a/pypy/module/cpyext/test/test_pyerrors.py
b/pypy/module/cpyext/test/test_pyerrors.py
--- a/pypy/module/cpyext/test/test_pyerrors.py
+++ b/pypy/module/cpyext/test/test_pyerrors.py
@@ -192,7 +192,7 @@
prologue="#include <errno.h>")
try:
module.set_from_errno()
- except OSError, e:
+ except OSError as e:
assert e.errno == errno.EBADF
assert e.strerror == os.strerror(errno.EBADF)
assert e.filename == None
@@ -214,7 +214,7 @@
prologue="#include <errno.h>")
try:
module.set_from_errno()
- except OSError, e:
+ except OSError as e:
assert e.filename == "blyf"
assert e.errno == errno.EBADF
assert e.strerror == os.strerror(errno.EBADF)
@@ -251,7 +251,7 @@
])
try:
raise ValueError(5)
- except ValueError, old_exc:
+ except ValueError as old_exc:
new_exc = TypeError("TEST")
orig_sys_exc_info = sys.exc_info()
orig_exc_info = module.getset_exc_info(new_exc.__class__,
diff --git a/pypy/module/cpyext/test/test_pyfile.py
b/pypy/module/cpyext/test/test_pyfile.py
--- a/pypy/module/cpyext/test/test_pyfile.py
+++ b/pypy/module/cpyext/test/test_pyfile.py
@@ -14,11 +14,7 @@
rffi.free_charp(filename)
rffi.free_charp(mode)
- assert api.PyFile_Check(w_file)
- assert api.PyFile_CheckExact(w_file)
- assert not api.PyFile_Check(space.wrap("text"))
-
- space.call_method(w_file, "write", space.wrap("text"))
+ space.call_method(w_file, "write", space.wrapbytes("text"))
space.call_method(w_file, "close")
assert (udir / "_test_file").read() == "text"
diff --git a/pypy/module/cpyext/test/test_thread.py
b/pypy/module/cpyext/test/test_thread.py
--- a/pypy/module/cpyext/test/test_thread.py
+++ b/pypy/module/cpyext/test/test_thread.py
@@ -73,17 +73,17 @@
raises(ValueError, module.test_key, key)
# Same test, in another thread.
result = []
- import thread, time
+ import _thread, time
def in_thread():
try:
module.test_key(key)
raises(ValueError, module.test_key, key)
- except Exception, e:
+ except Exception as e:
result.append(e)
else:
result.append(True)
- thread.start_new_thread(in_thread, ())
+ _thread.start_new_thread(in_thread, ())
while not result:
- print "."
+ print(".")
time.sleep(.5)
assert result == [True]
diff --git a/pypy/module/cpyext/test/test_typeobject.py
b/pypy/module/cpyext/test/test_typeobject.py
--- a/pypy/module/cpyext/test/test_typeobject.py
+++ b/pypy/module/cpyext/test/test_typeobject.py
@@ -121,8 +121,8 @@
module = self.import_module(name='foo')
obj = module.new()
# call __new__
- newobj = module.UnicodeSubtype(u"xyz")
- assert newobj == u"xyz"
+ newobj = module.UnicodeSubtype("xyz")
+ assert newobj == "xyz"
assert isinstance(newobj, module.UnicodeSubtype)
assert isinstance(module.fooType(), module.fooType)
@@ -134,7 +134,7 @@
class fuu2(fuu):
def baz(self):
return self
- assert fuu2(u"abc").baz().escape()
+ assert fuu2("abc").baz().escape()
raises(TypeError, module.fooType.object_member.__get__, 1)
def test_init(self):
@@ -181,11 +181,9 @@
assert sre_compile.MAGIC == module.MAGIC
import re
import time
- s = u"Foo " * 1000 + u"Bar"
- prog = re.compile(ur"Foo.*Bar")
+ s = "Foo " * 1000 + "Bar"
+ prog = re.compile(r"Foo.*Bar")
assert prog.match(s)
- m = re.search(u"xyz", u"xyzxyz")
- assert m
m = re.search("xyz", "xyzxyz")
assert m
assert "groupdict" in dir(m)
@@ -208,10 +206,10 @@
cmpr = module.CmpType()
# should not crash
- cmpr < 4
- cmpr <= 4
- cmpr > 4
- cmpr >= 4
+ raises(TypeError, "cmpr < 4")
+ raises(TypeError, "cmpr <= 4")
+ raises(TypeError, "cmpr > 4")
+ raises(TypeError, "cmpr >= 4")
assert cmpr.__le__(4) is NotImplemented
diff --git a/pypy/module/cpyext/test/test_weakref.py
b/pypy/module/cpyext/test/test_weakref.py
--- a/pypy/module/cpyext/test/test_weakref.py
+++ b/pypy/module/cpyext/test/test_weakref.py
@@ -18,7 +18,7 @@
def test_proxy(self, space, api):
w_obj = space.w_Warning # some weakrefable object
w_proxy = api.PyWeakref_NewProxy(w_obj, None)
- assert space.unwrap(space.str(w_proxy)) == "<type
'exceptions.Warning'>"
+ assert space.unwrap(space.str(w_proxy)) == "<class
'exceptions.Warning'>"
assert space.unwrap(space.repr(w_proxy)).startswith('<weak')
def test_weakref_lockobject(self, space, api):
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit