Python: add load test to limited API test

Based on the example in GH issue #13167, the limited API test has been
extended with a test to load the compiled module to ensure it can be
loaded correctly.
pull/13171/head
Andrew McNulty 7 months ago
parent 141100e482
commit d1abdce88f
  1. 14
      test cases/python/9 extmodule limited api/limited.c
  2. 7
      test cases/python/9 extmodule limited api/meson.build
  3. 6
      test cases/python/9 extmodule limited api/test_limited.py

@ -6,12 +6,22 @@
#error Wrong value for Py_LIMITED_API #error Wrong value for Py_LIMITED_API
#endif #endif
static PyObject *
hello(PyObject * Py_UNUSED(self), PyObject * Py_UNUSED(args)) {
return PyUnicode_FromString("hello world");
}
static struct PyMethodDef methods[] = {
{ "hello", hello, METH_NOARGS, NULL },
{ NULL, NULL, 0, NULL },
};
static struct PyModuleDef limited_module = { static struct PyModuleDef limited_module = {
PyModuleDef_HEAD_INIT, PyModuleDef_HEAD_INIT,
"limited_api_test", "limited",
NULL, NULL,
-1, -1,
NULL methods
}; };
PyMODINIT_FUNC PyInit_limited(void) { PyMODINIT_FUNC PyInit_limited(void) {

@ -14,3 +14,10 @@ ext_mod = py.extension_module('not_limited',
'not_limited.c', 'not_limited.c',
install: true, install: true,
) )
test('load-test',
py,
args: [files('test_limited.py')],
env: { 'PYTHONPATH': meson.current_build_dir() },
workdir: meson.current_source_dir()
)

@ -0,0 +1,6 @@
from limited import hello
def test_hello():
assert hello() == "hello world"
test_hello()
Loading…
Cancel
Save