Skip to content

Commit a6a09f9

Browse files
committed
add test for Py_True and Py_False being singletons
1 parent 64c5895 commit a6a09f9

File tree

1 file changed

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

1 file changed

+23
-0
lines changed

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,29 @@ def compile_module(self, name):
5959
type(self).mro()[1].__dict__["test_%s" % name].create_module(name)
6060
super(TestPyBool, self).compile_module(name)
6161

62+
# (tfel): This test actually checks that the wrapped booleans that are
63+
# stored as sulong globals are singletons
64+
test_PyBools_areSingleton = CPyExtFunction(
65+
lambda args: 1,
66+
lambda: (
67+
("True",),
68+
("False",),
69+
),
70+
callfunction="CheckPyTrue",
71+
code="""
72+
static int CheckPyTrue(const char* str) {
73+
if (!strcmp(str, "True")) {
74+
return PyRun_StringFlags("True", Py_eval_input, PyDict_New(), PyDict_New(), NULL) == Py_True;
75+
} else {
76+
return PyRun_StringFlags("False", Py_eval_input, PyDict_New(), PyDict_New(), NULL) == Py_False;
77+
}
78+
}
79+
""",
80+
resultspec="i",
81+
argspec="s",
82+
arguments=["const char* source"],
83+
)
84+
6285
test_PyBool_Check = CPyExtFunction(
6386
lambda args: isinstance(args[0], bool),
6487
lambda: (

0 commit comments

Comments
 (0)