Skip to content

Commit 2811e0b

Browse files
committed
enabled PyObject_RichCompare tests
1 parent c5465b1 commit 2811e0b

File tree

1 file changed

+43
-26
lines changed

1 file changed

+43
-26
lines changed

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

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -324,36 +324,53 @@ def forgiving_set_item(args):
324324
lambda: ([], {}, 0, 123, b"ello")
325325
)
326326

327-
# richcompare_args = ([ ([], [], i) for i in range(6) ] +
328-
# [ (12, 24, i) for i in range(6) ] +
329-
# [ ("aa", "ba", i) for i in range(6) ])
327+
richcompare_args = lambda: (([], [], 0),
328+
([], [], 1),
329+
([], [], 2),
330+
([], [], 3),
331+
([], [], 4),
332+
([], [], 5),
333+
(12, 24, 0),
334+
(12, 24, 1),
335+
(12, 24, 2),
336+
(12, 24, 3),
337+
(12, 24, 4),
338+
(12, 24, 5),
339+
("aa", "ba", 0),
340+
("aa", "ba", 1),
341+
("aa", "ba", 2),
342+
("aa", "ba", 3),
343+
("aa", "ba", 4),
344+
("aa", "ba", 5))
330345

331-
# def richcompare(args):
332-
# return eval("%r %s %r" % (args[0], ["<", "<=", "==", "!=", ">", ">="][args[2]], args[1]))
346+
def richcompare(args):
347+
return eval("%r %s %r" % (args[0], ["<", "<=", "==", "!=", ">", ">="][args[2]], args[1]))
333348

334-
# test_PyObject_RichCompare = CPyExtFunction(
335-
# richcompare,
336-
# richcompare_args,
337-
# arguments=["PyObject* left", "PyObject* right", "int op"],
338-
# argspec="OOi",
339-
# )
349+
test_PyObject_RichCompare = CPyExtFunction(
350+
richcompare,
351+
richcompare_args,
352+
arguments=["PyObject* left", "PyObject* right", "int op"],
353+
argspec="OOi",
354+
resultspec="O",
355+
)
340356

341-
# def richcompare_bool(args):
342-
# try:
343-
# if eval("%r %s %r" % (args[0], ["<", "<=", "==", "!=", ">", ">="][args[2]], args[1])):
344-
# return 1
345-
# else:
346-
# return 0
347-
# except:
348-
# return -1
357+
def richcompare_bool(args):
358+
try:
359+
if eval("%r %s %r" % (args[0], ["<", "<=", "==", "!=", ">", ">="][args[2]], args[1])):
360+
return 1
361+
else:
362+
return 0
363+
except:
364+
return -1
349365

350-
# test_PyObject_RichCompareBool = CPyExtFunction(
351-
# richcompare_bool,
352-
# richcompare_args,
353-
# arguments=["PyObject* left", "PyObject* right", "int op"],
354-
# argspec="OOi",
355-
# resultspec="i",
356-
# )
366+
test_PyObject_RichCompareBool = CPyExtFunction(
367+
richcompare_bool,
368+
richcompare_args,
369+
arguments=["PyObject* left", "PyObject* right", "int op"],
370+
argspec="OOi",
371+
resultspec="i",
372+
)
373+
357374
__PyObject_GetAttrString_ARGS = (
358375
(MyObject(), "foo"),
359376
([], "__len__"),

0 commit comments

Comments
 (0)