Skip to content

Commit 9679179

Browse files
qunaibitsteve-s
authored andcommitted
add test
1 parent 9f1dbea commit 9679179

File tree

1 file changed

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

1 file changed

+30
-0
lines changed

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,36 @@ def test_slots(self):
571571
assert tester.year == 1, "year was %s "% tester.year
572572
assert tester.is_binary_compatible()
573573

574+
def test_subclasses(self):
575+
TestSubclasses = CPyExtType(
576+
'TestSubclasses',
577+
'''
578+
static PyObject* create_type(PyObject* unused, PyObject* args) {
579+
PyObject* bases;
580+
if (!PyArg_ParseTuple(args, "O", &bases))
581+
return NULL;
582+
PyType_Slot slots[] = {
583+
{ 0 }
584+
};
585+
PyType_Spec spec = { "DynamicType", sizeof(PyObject), 0, Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, slots };
586+
PyObject* result = PyType_FromSpecWithBases(&spec, bases);
587+
return result;
588+
}
589+
''',
590+
tp_methods='{"create_type", (PyCFunction)create_type, METH_VARARGS | METH_STATIC, ""}'
591+
)
592+
593+
class ManagedBase:
594+
pass
595+
DynamicType = TestSubclasses.create_type((ManagedBase,))
596+
assert ManagedBase.__subclasses__() == [DynamicType]
597+
598+
def add(a, b):
599+
return 42
600+
ManagedBase.__add__ = add
601+
foo = DynamicType()
602+
assert foo + foo == 42
603+
574604
def test_tp_name(self):
575605
TestTpName = CPyExtType("TestTpName",
576606
'''

0 commit comments

Comments
 (0)