Skip to content

Commit f0d0f68

Browse files
fangererqunaibit
authored andcommitted
add a test case
1 parent d1c54d1 commit f0d0f68

File tree

1 file changed

+25
-0
lines changed
  • graalpython/com.oracle.graal.python.test/src/tests/cpyext

1 file changed

+25
-0
lines changed

graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_descr.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,31 @@ def _reference_classmethod(args):
4848

4949
class TestDescrObject(object):
5050

51+
def test_new_classmethod(self):
52+
53+
TestNewClassMethod = CPyExtType("TestNewClassMethod",
54+
"""
55+
static PyObject * c_void_p_from_param(PyObject *self, PyObject *value) {
56+
/* just returns self which should be the class */
57+
return self;
58+
}
59+
static PyMethodDef c_void_p_method = { "from_param", c_void_p_from_param, METH_O };
60+
""",
61+
post_ready_code="""
62+
PyObject *meth = PyDescr_NewClassMethod(&TestNewClassMethodType, &c_void_p_method);
63+
if (!meth) {
64+
return NULL;
65+
}
66+
int x = PyDict_SetItemString(TestNewClassMethodType.tp_dict, c_void_p_method.ml_name, meth);
67+
Py_DECREF(meth);
68+
if (x == -1) {
69+
return NULL;
70+
}
71+
""",
72+
)
73+
74+
tester = TestNewClassMethod()
75+
assert tester.from_param(123) == TestNewClassMethod
5176

5277
def test_new_descr(self):
5378
C = CPyExtType("C_",

0 commit comments

Comments
 (0)