aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew McNulty <amcn102@gmail.com>2024-05-08 14:51:25 +0200
committerAndrew McNulty <amcn102@gmail.com>2024-06-11 19:47:31 +0200
commitd1abdce88fa263b6e532901564e44ca510df1065 (patch)
tree30e7de1076b4fd147c0b2d8bec666ed0f5aebdba
parent141100e482e440dd08ea8b5b042927cac968f112 (diff)
downloadmeson-d1abdce88fa263b6e532901564e44ca510df1065.zip
meson-d1abdce88fa263b6e532901564e44ca510df1065.tar.gz
meson-d1abdce88fa263b6e532901564e44ca510df1065.tar.bz2
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.
-rw-r--r--test cases/python/9 extmodule limited api/limited.c14
-rw-r--r--test cases/python/9 extmodule limited api/meson.build7
-rw-r--r--test cases/python/9 extmodule limited api/test_limited.py6
3 files changed, 25 insertions, 2 deletions
diff --git a/test cases/python/9 extmodule limited api/limited.c b/test cases/python/9 extmodule limited api/limited.c
index 0d1c718..b977419 100644
--- a/test cases/python/9 extmodule limited api/limited.c
+++ b/test cases/python/9 extmodule limited api/limited.c
@@ -6,12 +6,22 @@
#error Wrong value for Py_LIMITED_API
#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 = {
PyModuleDef_HEAD_INIT,
- "limited_api_test",
+ "limited",
NULL,
-1,
- NULL
+ methods
};
PyMODINIT_FUNC PyInit_limited(void) {
diff --git a/test cases/python/9 extmodule limited api/meson.build b/test cases/python/9 extmodule limited api/meson.build
index 68afc96..bdf1b7b 100644
--- a/test cases/python/9 extmodule limited api/meson.build
+++ b/test cases/python/9 extmodule limited api/meson.build
@@ -14,3 +14,10 @@ ext_mod = py.extension_module('not_limited',
'not_limited.c',
install: true,
)
+
+test('load-test',
+ py,
+ args: [files('test_limited.py')],
+ env: { 'PYTHONPATH': meson.current_build_dir() },
+ workdir: meson.current_source_dir()
+)
diff --git a/test cases/python/9 extmodule limited api/test_limited.py b/test cases/python/9 extmodule limited api/test_limited.py
new file mode 100644
index 0000000..fcbf67b
--- /dev/null
+++ b/test cases/python/9 extmodule limited api/test_limited.py
@@ -0,0 +1,6 @@
+from limited import hello
+
+def test_hello():
+ assert hello() == "hello world"
+
+test_hello()