Skip to content

Commit 0043221

Browse files
committed
add test case
1 parent b9edd79 commit 0043221

File tree

1 file changed

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

1 file changed

+26
-0
lines changed

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,32 @@ def test_new(self):
204204
tester = TestNew()
205205
assert tester.get_none() is None
206206

207+
def test_init(self):
208+
TestInit = CPyExtType("TestInit",
209+
'''static PyObject* testnew_new(PyTypeObject* cls, PyObject* a, PyObject* b) {
210+
PyObject* obj;
211+
TestInitObject* typedObj;
212+
obj = PyBaseObject_Type.tp_new(cls, a, b);
213+
214+
typedObj = ((TestInitObject*)obj);
215+
typedObj->dict = (PyDictObject*) PyDict_Type.tp_new(&PyDict_Type, a, b);
216+
PyDict_Type.tp_init((PyObject*) typedObj->dict, a, b);
217+
PyDict_SetItemString((PyObject*) typedObj->dict, "test", PyLong_FromLong(42));
218+
219+
Py_XINCREF(obj);
220+
return obj;
221+
}
222+
static PyObject* get_dict_item(PyObject* self) {
223+
return PyDict_GetItemString((PyObject*) ((TestInitObject*)self)->dict, "test");
224+
}
225+
''',
226+
cmembers="PyDictObject *dict;",
227+
tp_new="testnew_new",
228+
tp_methods='{"get_dict_item", (PyCFunction)get_dict_item, METH_NOARGS, ""}'
229+
)
230+
tester = TestInit()
231+
assert tester.get_dict_item() == 42
232+
207233
def test_slots(self):
208234
TestSlots = CPyExtType("TestSlots",
209235
'''

0 commit comments

Comments
 (0)