Skip to content

Commit 1abe818

Browse files
committed
Add test for parsing args with format 'O'.
1 parent a43e8fc commit 1abe818

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,16 @@ def _reference_typecheck(args, expected_type):
5454
return args[0][0]
5555

5656

57+
def _reference_parse_O(args):
58+
assert isinstance(args[0], tuple)
59+
assert isinstance(args[1], dict)
60+
if args[0]:
61+
return args[0][0]
62+
elif "arg0" in args[1]:
63+
return args[1]["arg0"]
64+
raise TypeError
65+
66+
5767
class Indexable:
5868
def __int__(self):
5969
return 456
@@ -107,6 +117,32 @@ def compile_module(self, name):
107117
cmpfunc=unhandled_error_compare
108118
)
109119

120+
test_parseargs_O = CPyExtFunction(
121+
_reference_parse_O,
122+
lambda: (
123+
(('helloworld', ), dict()),
124+
(tuple(), {"arg0": 'helloworld'}),
125+
(tuple(), dict()),
126+
(tuple(), {"arg1": 'helloworld'}),
127+
),
128+
code='''
129+
static PyObject* wrap_PyArg_ParseTupleAndKeywords(PyObject* argTuple, PyObject* kwargs) {
130+
PyObject* out = NULL;
131+
static char *kwdnames[] = {"arg0", NULL};
132+
if (PyArg_ParseTupleAndKeywords(argTuple, kwargs, "O", kwdnames, &out) == 0) {
133+
return NULL;
134+
}
135+
Py_XINCREF(out);
136+
return out;
137+
}
138+
''',
139+
resultspec="O",
140+
argspec="OO",
141+
arguments=["PyObject* argTuple", "PyObject* kwargs"],
142+
callfunction="wrap_PyArg_ParseTupleAndKeywords",
143+
cmpfunc=unhandled_error_compare
144+
)
145+
110146
test_parseargs_O_conv = CPyExtFunction(
111147
lambda args: True if args[0][0] else False,
112148
lambda: (

0 commit comments

Comments
 (0)