Author: Ronan Lamy
Branch:
Changeset: r91659:5a8f2cdedcd0
Date: 2017-06-29 19:25 +0100
http://bitbucket.org/pypy/pypy/changeset/5a8f2cdedcd0/
Log:Don't use magical api object in pypy.module.cpyext.test.test_number
diff --git a/pypy/module/cpyext/number.py b/pypy/module/cpyext/number.py
--- a/pypy/module/cpyext/number.py
+++ b/pypy/module/cpyext/number.py
@@ -95,53 +95,58 @@
def func_rename(newname):
return lambda func: func_with_new_name(func, newname)
-def make_numbermethod(name, spacemeth):
+def make_numbermethod(cname, spacemeth):
@cpython_api([PyObject, PyObject], PyObject)
-@func_rename('PyNumber_%s' % (name,))
+@func_rename(cname)
def PyNumber_Method(space, w_o1, w_o2):
meth = getattr(space, spacemeth)
return meth(w_o1, w_o2)
+return PyNumber_Method
def make_unary_numbermethod(name, spacemeth):
@cpython_api([PyObject], PyObject)
-@func_rename('PyNumber_%s' % (name,))
+@func_rename(cname)
def PyNumber_Method(space, w_o1):
meth = getattr(space, spacemeth)
return meth(w_o1)
+return PyNumber_Method
-def make_inplace_numbermethod(name, spacemeth):
+def make_inplace_numbermethod(cname, spacemeth):
spacemeth = 'inplace_' + spacemeth.rstrip('_')
@cpython_api([PyObject, PyObject], PyObject)
-@func_rename('PyNumber_InPlace%s' % (name,))
+@func_rename(cname)
def PyNumber_Method(space, w_o1, w_o2):
meth = getattr(space, spacemeth)
return meth(w_o1, w_o2)
+return PyNumber_Method
for name, spacemeth in [
-('Add', 'add'),
-('Subtract', 'sub'),
-('Multiply', 'mul'),
-('Divide', 'div'),
-('FloorDivide', 'floordiv'),
-('TrueDivide', 'truediv'),
-('Remainder', 'mod'),
-('Lshift', 'lshift'),
-('Rshift', 'rshift'),
-('And', 'and_'),
-('Xor', 'xor'),
-('Or', 'or_'),
-('Divmod', 'divmod'),
-]:
-make_numbermethod(name, spacemeth)
+('Add', 'add'),
+('Subtract', 'sub'),
+('Multiply', 'mul'),
+('Divide', 'div'),
+('FloorDivide', 'floordiv'),
+('TrueDivide', 'truediv'),
+('Remainder', 'mod'),
+('Lshift', 'lshift'),
+('Rshift', 'rshift'),
+('And', 'and_'),
+('Xor', 'xor'),
+('Or', 'or_'),
+('Divmod', 'divmod')]:
+cname = 'PyNumber_%s' % (name,)
+globals()[cname] = make_numbermethod(cname, spacemeth)
if name != 'Divmod':
-make_inplace_numbermethod(name, spacemeth)
+cname = 'PyNumber_InPlace%s' % (name,)
+globals()[cname] = make_inplace_numbermethod(cname, spacemeth)
for name, spacemeth in [
-('Negative', 'neg'),
-('Positive', 'pos'),
-('Absolute', 'abs'),
-('Invert', 'invert')]:
-make_unary_numbermethod(name, spacemeth)
+('Negative', 'neg'),
+('Positive', 'pos'),
+('Absolute', 'abs'),
+('Invert', 'invert')]:
+cname = 'PyNumber_%s' % (name,)
+globals()[cname] = make_unary_numbermethod(cname, spacemeth)
@cpython_api([PyObject, PyObject, PyObject], PyObject)
def PyNumber_Power(space, w_o1, w_o2, w_o3):
diff --git a/pypy/module/cpyext/test/test_number.py
b/pypy/module/cpyext/test/test_number.py
--- a/pypy/module/cpyext/test/test_number.py
+++ b/pypy/module/cpyext/test/test_number.py
@@ -1,53 +1,64 @@
import py
+import pytest
from rpython.rtyper.lltypesystem import lltype
+from pypy.interpreter.error import OperationError
from pypy.module.cpyext.test.test_api import BaseApiTest
-from pypy.module.cpyext.pyobject import PyObjectP, from_ref, make_ref,
Py_DecRef
+from pypy.module.cpyext.pyobject import (
+PyObjectP, from_ref, make_ref, Py_DecRef)
from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
+from pypy.module.cpyext.number import (
+PyIndex_Check, PyNumber_Check, PyNumber_Long, PyNumber_Int,
+PyNumber_Index, PyNumber_Coerce, PyNumber_CoerceEx, PyNumber_Add,
+PyNumber_Multiply, PyNumber_InPlaceMultiply, PyNumber_Absolute,
+PyNumber_Power, PyNumber_InPlacePower)
+from pypy.module.cpyext.floatobject import PyFloat_Check
+from pypy.module.cpyext.intobject import PyInt_CheckExact
+from pypy.module.cpyext.longobject import PyLong_CheckExact
+from pypy.module.cpyext.object import PyObject_Size
class TestIterator(BaseApiTest):
-def test_check(self, space, api):
-assert api.PyIndex_Check(space.wrap(12))
-assert api.PyIndex_Check(space.wraplong(-12L))
-assert not api.PyIndex_Check(space.wrap(12.1))
-assert not api.PyIndex_Check(space.wrap('12'))
+def test_check(self, space):
+assert PyIndex_Check(space, space.wrap(12))
+assert PyIndex_Check(space, space.wraplong(-12L))
+assert not PyIndex_Check(space, space.wrap(12.1))
+assert not PyIndex_Check(space, space.wrap('12'))
-assert api.PyNumber_Check(space.wrap(12))
-assert api.PyNumber_Check(space.wraplong(-12L))
-