aboutsummaryrefslogtreecommitdiffstats
path: root/meson/test cases/cython
diff options
context:
space:
mode:
authorAngelos Mouzakitis <a.mouzakitis@virtualopensystems.com>2023-10-10 14:33:42 +0000
committerAngelos Mouzakitis <a.mouzakitis@virtualopensystems.com>2023-10-10 14:33:42 +0000
commitaf1a266670d040d2f4083ff309d732d648afba2a (patch)
tree2fc46203448ddcc6f81546d379abfaeb323575e9 /meson/test cases/cython
parente02cda008591317b1625707ff8e115a4841aa889 (diff)
Add submodule dependency filesHEADmaster
Change-Id: Iaf8d18082d3991dec7c0ebbea540f092188eb4ec
Diffstat (limited to 'meson/test cases/cython')
-rwxr-xr-xmeson/test cases/cython/1 basic/cytest.py19
-rw-r--r--meson/test cases/cython/1 basic/libdir/cstorer.pxd9
-rw-r--r--meson/test cases/cython/1 basic/libdir/meson.build8
-rw-r--r--meson/test cases/cython/1 basic/libdir/storer.c24
-rw-r--r--meson/test cases/cython/1 basic/libdir/storer.h8
-rw-r--r--meson/test cases/cython/1 basic/libdir/storer.pyx16
-rw-r--r--meson/test cases/cython/1 basic/meson.build20
-rw-r--r--meson/test cases/cython/2 generated sources/configure.pyx.in2
-rw-r--r--meson/test cases/cython/2 generated sources/g.in2
-rw-r--r--meson/test cases/cython/2 generated sources/gen.py14
-rwxr-xr-xmeson/test cases/cython/2 generated sources/generator.py12
-rw-r--r--meson/test cases/cython/2 generated sources/libdir/gen.py14
-rw-r--r--meson/test cases/cython/2 generated sources/libdir/meson.build10
-rw-r--r--meson/test cases/cython/2 generated sources/meson.build80
-rw-r--r--meson/test cases/cython/2 generated sources/test.py13
15 files changed, 251 insertions, 0 deletions
diff --git a/meson/test cases/cython/1 basic/cytest.py b/meson/test cases/cython/1 basic/cytest.py
new file mode 100755
index 000000000..c08ffeed3
--- /dev/null
+++ b/meson/test cases/cython/1 basic/cytest.py
@@ -0,0 +1,19 @@
+#!/usr/bin/env python3
+
+from storer import Storer
+
+s = Storer()
+
+if s.get_value() != 0:
+ raise SystemExit('Initial value incorrect.')
+
+s.set_value(42)
+
+if s.get_value() != 42:
+ raise SystemExit('Setting value failed.')
+
+try:
+ s.set_value('not a number')
+ raise SystemExit('Using wrong argument type did not fail.')
+except TypeError:
+ pass
diff --git a/meson/test cases/cython/1 basic/libdir/cstorer.pxd b/meson/test cases/cython/1 basic/libdir/cstorer.pxd
new file mode 100644
index 000000000..7b730fc75
--- /dev/null
+++ b/meson/test cases/cython/1 basic/libdir/cstorer.pxd
@@ -0,0 +1,9 @@
+
+cdef extern from "storer.h":
+ ctypedef struct Storer:
+ pass
+
+ Storer* storer_new();
+ void storer_destroy(Storer *s);
+ int storer_get_value(Storer *s);
+ void storer_set_value(Storer *s, int v);
diff --git a/meson/test cases/cython/1 basic/libdir/meson.build b/meson/test cases/cython/1 basic/libdir/meson.build
new file mode 100644
index 000000000..144bb1f14
--- /dev/null
+++ b/meson/test cases/cython/1 basic/libdir/meson.build
@@ -0,0 +1,8 @@
+slib = py3.extension_module(
+ 'storer',
+ 'storer.pyx',
+ 'storer.c',
+ dependencies : py3_dep
+)
+
+pydir = meson.current_build_dir()
diff --git a/meson/test cases/cython/1 basic/libdir/storer.c b/meson/test cases/cython/1 basic/libdir/storer.c
new file mode 100644
index 000000000..0199bb850
--- /dev/null
+++ b/meson/test cases/cython/1 basic/libdir/storer.c
@@ -0,0 +1,24 @@
+#include"storer.h"
+#include<stdlib.h>
+
+struct _Storer {
+ int value;
+};
+
+Storer* storer_new() {
+ Storer *s = malloc(sizeof(struct _Storer));
+ s->value = 0;
+ return s;
+}
+
+void storer_destroy(Storer *s) {
+ free(s);
+}
+
+int storer_get_value(Storer *s) {
+ return s->value;
+}
+
+void storer_set_value(Storer *s, int v) {
+ s->value = v;
+}
diff --git a/meson/test cases/cython/1 basic/libdir/storer.h b/meson/test cases/cython/1 basic/libdir/storer.h
new file mode 100644
index 000000000..4f7191711
--- /dev/null
+++ b/meson/test cases/cython/1 basic/libdir/storer.h
@@ -0,0 +1,8 @@
+#pragma once
+
+typedef struct _Storer Storer;
+
+Storer* storer_new();
+void storer_destroy(Storer *s);
+int storer_get_value(Storer *s);
+void storer_set_value(Storer *s, int v);
diff --git a/meson/test cases/cython/1 basic/libdir/storer.pyx b/meson/test cases/cython/1 basic/libdir/storer.pyx
new file mode 100644
index 000000000..ed551dc5f
--- /dev/null
+++ b/meson/test cases/cython/1 basic/libdir/storer.pyx
@@ -0,0 +1,16 @@
+cimport cstorer
+
+cdef class Storer:
+ cdef cstorer.Storer* _c_storer
+
+ def __cinit__(self):
+ self._c_storer = cstorer.storer_new()
+
+ def __dealloc__(self):
+ cstorer.storer_destroy(self._c_storer)
+
+ cpdef int get_value(self):
+ return cstorer.storer_get_value(self._c_storer)
+
+ cpdef set_value(self, int value):
+ cstorer.storer_set_value(self._c_storer, value)
diff --git a/meson/test cases/cython/1 basic/meson.build b/meson/test cases/cython/1 basic/meson.build
new file mode 100644
index 000000000..8c24e2312
--- /dev/null
+++ b/meson/test cases/cython/1 basic/meson.build
@@ -0,0 +1,20 @@
+project(
+ 'basic cython project',
+ ['cython', 'c'],
+ default_options : ['warning_level=3']
+)
+
+py_mod = import('python')
+py3 = py_mod.find_installation()
+py3_dep = py3.dependency(required : false)
+if not py3_dep.found()
+ error('MESON_SKIP_TEST: Python library not found.')
+endif
+
+subdir('libdir')
+
+test('cython tester',
+ py3,
+ args : files('cytest.py'),
+ env : ['PYTHONPATH=' + pydir]
+)
diff --git a/meson/test cases/cython/2 generated sources/configure.pyx.in b/meson/test cases/cython/2 generated sources/configure.pyx.in
new file mode 100644
index 000000000..1c44f6d42
--- /dev/null
+++ b/meson/test cases/cython/2 generated sources/configure.pyx.in
@@ -0,0 +1,2 @@
+cpdef func():
+ return "Hello, World!"
diff --git a/meson/test cases/cython/2 generated sources/g.in b/meson/test cases/cython/2 generated sources/g.in
new file mode 100644
index 000000000..1c44f6d42
--- /dev/null
+++ b/meson/test cases/cython/2 generated sources/g.in
@@ -0,0 +1,2 @@
+cpdef func():
+ return "Hello, World!"
diff --git a/meson/test cases/cython/2 generated sources/gen.py b/meson/test cases/cython/2 generated sources/gen.py
new file mode 100644
index 000000000..5c0a82d56
--- /dev/null
+++ b/meson/test cases/cython/2 generated sources/gen.py
@@ -0,0 +1,14 @@
+# SPDX-License-Identifier: Apache-2.0
+
+import argparse
+import textwrap
+
+parser = argparse.ArgumentParser()
+parser.add_argument('output')
+args = parser.parse_args()
+
+with open(args.output, 'w') as f:
+ f.write(textwrap.dedent('''\
+ cpdef func():
+ return "Hello, World!"
+ '''))
diff --git a/meson/test cases/cython/2 generated sources/generator.py b/meson/test cases/cython/2 generated sources/generator.py
new file mode 100755
index 000000000..77de85569
--- /dev/null
+++ b/meson/test cases/cython/2 generated sources/generator.py
@@ -0,0 +1,12 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: Apache-2.0
+
+import argparse
+
+parser = argparse.ArgumentParser()
+parser.add_argument('input')
+parser.add_argument('output')
+args = parser.parse_args()
+
+with open(args.input, 'r') as i, open(args.output, 'w') as o:
+ o.write(i.read())
diff --git a/meson/test cases/cython/2 generated sources/libdir/gen.py b/meson/test cases/cython/2 generated sources/libdir/gen.py
new file mode 100644
index 000000000..5c0a82d56
--- /dev/null
+++ b/meson/test cases/cython/2 generated sources/libdir/gen.py
@@ -0,0 +1,14 @@
+# SPDX-License-Identifier: Apache-2.0
+
+import argparse
+import textwrap
+
+parser = argparse.ArgumentParser()
+parser.add_argument('output')
+args = parser.parse_args()
+
+with open(args.output, 'w') as f:
+ f.write(textwrap.dedent('''\
+ cpdef func():
+ return "Hello, World!"
+ '''))
diff --git a/meson/test cases/cython/2 generated sources/libdir/meson.build b/meson/test cases/cython/2 generated sources/libdir/meson.build
new file mode 100644
index 000000000..e9259bdad
--- /dev/null
+++ b/meson/test cases/cython/2 generated sources/libdir/meson.build
@@ -0,0 +1,10 @@
+ct2 = custom_target(
+ 'ct2',
+ input : 'gen.py',
+ output : 'ct2.pyx',
+ command : [py3, '@INPUT@', '@OUTPUT@'],
+)
+
+ct2_ext = py3.extension_module('ct2', ct2, dependencies : py3_dep)
+
+pydir = meson.current_build_dir()
diff --git a/meson/test cases/cython/2 generated sources/meson.build b/meson/test cases/cython/2 generated sources/meson.build
new file mode 100644
index 000000000..cfe62602d
--- /dev/null
+++ b/meson/test cases/cython/2 generated sources/meson.build
@@ -0,0 +1,80 @@
+project(
+ 'generated cython sources',
+ ['cython'],
+)
+
+py_mod = import('python')
+py3 = py_mod.find_installation('python3')
+py3_dep = py3.dependency(required : false)
+if not py3_dep.found()
+ error('MESON_SKIP_TEST: Python library not found.')
+endif
+
+ct = custom_target(
+ 'ct',
+ input : 'gen.py',
+ output : 'ct.pyx',
+ command : [py3, '@INPUT@', '@OUTPUT@'],
+)
+
+ct_ext = py3.extension_module('ct', ct, dependencies : py3_dep)
+
+test(
+ 'custom target',
+ py3,
+ args : [files('test.py'), 'ct'],
+ env : ['PYTHONPATH=' + meson.current_build_dir()]
+)
+
+# Test a CustomTargetIndex
+cti = custom_target(
+ 'cti',
+ input : 'gen.py',
+ output : 'cti.pyx',
+ command : [py3, '@INPUT@', '@OUTPUT@'],
+)
+
+cti_ext = py3.extension_module('cti', cti[0], dependencies : py3_dep)
+
+cf = configure_file(
+ input : 'configure.pyx.in',
+ output : 'cf.pyx',
+ copy : true,
+)
+
+cf_ext = py3.extension_module('cf', cf, dependencies : py3_dep)
+
+test(
+ 'configure file',
+ py3,
+ args : [files('test.py'), 'cf'],
+ env : ['PYTHONPATH=' + meson.current_build_dir()]
+)
+
+gen = generator(
+ find_program('generator.py'),
+ arguments : ['@INPUT@', '@OUTPUT@'],
+ output : '@BASENAME@.pyx',
+)
+
+g_ext = py3.extension_module(
+ 'g',
+ gen.process('g.in'),
+ dependencies : py3_dep,
+)
+
+test(
+ 'generator',
+ py3,
+ args : [files('test.py'), 'g'],
+ env : ['PYTHONPATH=' + meson.current_build_dir()]
+)
+
+subdir('libdir')
+
+test(
+ 'custom target in subdir',
+ py3,
+ args : [files('test.py'), 'ct2'],
+ env : ['PYTHONPATH=' + pydir]
+)
diff --git a/meson/test cases/cython/2 generated sources/test.py b/meson/test cases/cython/2 generated sources/test.py
new file mode 100644
index 000000000..307283f26
--- /dev/null
+++ b/meson/test cases/cython/2 generated sources/test.py
@@ -0,0 +1,13 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: Apache-2.0
+
+import argparse
+import importlib
+
+parser = argparse.ArgumentParser()
+parser.add_argument('mod')
+args = parser.parse_args()
+
+mod = importlib.import_module(args.mod)
+
+assert mod.func() == 'Hello, World!'