diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2016-02-26 21:21:53 +0200 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2016-02-26 21:21:53 +0200 |
commit | ea60a22cd5a2613652942e48e143d7a3da68bbc0 (patch) | |
tree | ae351eb81558c49dd7fc76c5ca380e6b6fc99774 /test cases | |
parent | 003696fc27e1f560a8448cc5998443696a162927 (diff) | |
parent | efceac497fa2702124398b2712761015d9a1c78a (diff) | |
download | meson-ea60a22cd5a2613652942e48e143d7a3da68bbc0.zip meson-ea60a22cd5a2613652942e48e143d7a3da68bbc0.tar.gz meson-ea60a22cd5a2613652942e48e143d7a3da68bbc0.tar.bz2 |
Merge Python 3 module support.
Diffstat (limited to 'test cases')
-rw-r--r-- | test cases/python3/1 basic/gluon/__init__.py | 0 | ||||
-rw-r--r-- | test cases/python3/1 basic/gluon/gluonator.py | 2 | ||||
-rw-r--r-- | test cases/python3/1 basic/meson.build | 9 | ||||
-rwxr-xr-x | test cases/python3/1 basic/prog.py | 9 | ||||
-rw-r--r-- | test cases/python3/1 basic/subdir/meson.build | 5 | ||||
-rwxr-xr-x | test cases/python3/1 basic/subdir/subprog.py | 12 | ||||
-rwxr-xr-x | test cases/python3/2 extmodule/blaster.py | 14 | ||||
-rw-r--r-- | test cases/python3/2 extmodule/ext/meson.build | 17 | ||||
-rw-r--r-- | test cases/python3/2 extmodule/ext/tachyon_module.c | 49 | ||||
-rw-r--r-- | test cases/python3/2 extmodule/meson.build | 12 | ||||
-rwxr-xr-x | test cases/python3/3 cython/cytest.py | 23 | ||||
-rw-r--r-- | test cases/python3/3 cython/libdir/cstorer.pxd | 9 | ||||
-rw-r--r-- | test cases/python3/3 cython/libdir/meson.build | 23 | ||||
-rw-r--r-- | test cases/python3/3 cython/libdir/storer.c | 24 | ||||
-rw-r--r-- | test cases/python3/3 cython/libdir/storer.h | 8 | ||||
-rw-r--r-- | test cases/python3/3 cython/libdir/storer.pyx | 16 | ||||
-rw-r--r-- | test cases/python3/3 cython/meson.build | 17 |
17 files changed, 249 insertions, 0 deletions
diff --git a/test cases/python3/1 basic/gluon/__init__.py b/test cases/python3/1 basic/gluon/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test cases/python3/1 basic/gluon/__init__.py diff --git a/test cases/python3/1 basic/gluon/gluonator.py b/test cases/python3/1 basic/gluon/gluonator.py new file mode 100644 index 0000000..b53d6de --- /dev/null +++ b/test cases/python3/1 basic/gluon/gluonator.py @@ -0,0 +1,2 @@ +def gluoninate(): + return 42 diff --git a/test cases/python3/1 basic/meson.build b/test cases/python3/1 basic/meson.build new file mode 100644 index 0000000..badd3e5 --- /dev/null +++ b/test cases/python3/1 basic/meson.build @@ -0,0 +1,9 @@ +project('python sample', 'c') + +py3 = find_program('python3') + +main = files('prog.py') + +test('toplevel', py3, args : main) + +subdir('subdir') diff --git a/test cases/python3/1 basic/prog.py b/test cases/python3/1 basic/prog.py new file mode 100755 index 0000000..9d95aea --- /dev/null +++ b/test cases/python3/1 basic/prog.py @@ -0,0 +1,9 @@ +#!/usr/bin/env python3 + +from gluon import gluonator +import sys + +print('Running mainprog from root dir.') + +if gluonator.gluoninate() != 42: + sys.exit(1) diff --git a/test cases/python3/1 basic/subdir/meson.build b/test cases/python3/1 basic/subdir/meson.build new file mode 100644 index 0000000..3f275ad --- /dev/null +++ b/test cases/python3/1 basic/subdir/meson.build @@ -0,0 +1,5 @@ +submain = find_program('subprog.py') + +test('subdir', + submain, + env : 'PYTHONPATH=' + meson.source_root()) diff --git a/test cases/python3/1 basic/subdir/subprog.py b/test cases/python3/1 basic/subdir/subprog.py new file mode 100755 index 0000000..08652f0 --- /dev/null +++ b/test cases/python3/1 basic/subdir/subprog.py @@ -0,0 +1,12 @@ +#!/usr/bin/env python3 + +# In order to run this program, PYTHONPATH must be set to +# point to source root. + +from gluon import gluonator +import sys + +print('Running mainprog from subdir.') + +if gluonator.gluoninate() != 42: + sys.exit(1) diff --git a/test cases/python3/2 extmodule/blaster.py b/test cases/python3/2 extmodule/blaster.py new file mode 100755 index 0000000..7e1eae6 --- /dev/null +++ b/test cases/python3/2 extmodule/blaster.py @@ -0,0 +1,14 @@ +#!/usr/bin/env python3 + +import tachyon +import sys + +result = tachyon.phaserize('shoot') + +if not isinstance(result, int): + print('Returned result not an integer.') + sys.exit(1) + +if result != 1: + print('Returned result {} is not 1.'.format(result)) + sys.exit(1) diff --git a/test cases/python3/2 extmodule/ext/meson.build b/test cases/python3/2 extmodule/ext/meson.build new file mode 100644 index 0000000..7d67953 --- /dev/null +++ b/test cases/python3/2 extmodule/ext/meson.build @@ -0,0 +1,17 @@ +if host_machine.system() == 'darwin' + # Default suffix is 'dylib' but Python does not use for extensions. + suffix = 'so' +elif host_machine.system() == 'windows' + # On Windows the extension is pyd for some unexplainable reason. + suffix = 'pyd' +else + suffix = [] +endif + +pylib = shared_library('tachyon', + 'tachyon_module.c', + dependencies : py3_dep, + name_prefix : '', + name_suffix : suffix) + +pypathdir = meson.current_build_dir() diff --git a/test cases/python3/2 extmodule/ext/tachyon_module.c b/test cases/python3/2 extmodule/ext/tachyon_module.c new file mode 100644 index 0000000..b2592e4 --- /dev/null +++ b/test cases/python3/2 extmodule/ext/tachyon_module.c @@ -0,0 +1,49 @@ +/* + Copyright 2016 The Meson development team + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +/* A very simple Python extension module. */ + +#include <Python.h> +#include <string.h> + +static PyObject* phaserize(PyObject *self, PyObject *args) { + const char *message; + int result; + + if(!PyArg_ParseTuple(args, "s", &message)) + return NULL; + + result = strcmp(message, "shoot") ? 0 : 1; + return PyLong_FromLong(result); +} + +static PyMethodDef TachyonMethods[] = { + {"phaserize", phaserize, METH_VARARGS, + "Shoot tachyon cannons."}, + {NULL, NULL, 0, NULL} +}; + +static struct PyModuleDef tachyonmodule = { + PyModuleDef_HEAD_INIT, + "tachyon", + NULL, + -1, + TachyonMethods +}; + +PyMODINIT_FUNC PyInit_tachyon(void) { + return PyModule_Create(&tachyonmodule); +} diff --git a/test cases/python3/2 extmodule/meson.build b/test cases/python3/2 extmodule/meson.build new file mode 100644 index 0000000..858bbea --- /dev/null +++ b/test cases/python3/2 extmodule/meson.build @@ -0,0 +1,12 @@ +project('Python extension module', 'c', + default_options : ['buildtype=release']) +# Because Windows Python ships only with optimized libs, +# we must build this project the same way. + +py3_dep = dependency('python3') + +subdir('ext') + +test('extmod', + find_program('blaster.py'), + env : ['PYTHONPATH=' + pypathdir]) diff --git a/test cases/python3/3 cython/cytest.py b/test cases/python3/3 cython/cytest.py new file mode 100755 index 0000000..43443dc --- /dev/null +++ b/test cases/python3/3 cython/cytest.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 + +from storer import Storer +import sys + +s = Storer() + +if s.get_value() != 0: + print('Initial value incorrect.') + sys.exit(1) + +s.set_value(42) + +if s.get_value() != 42: + print('Setting value failed.') + sys.exit(1) + +try: + s.set_value('not a number') + print('Using wrong argument type did not fail.') + sys.exit(1) +except TypeError: + pass diff --git a/test cases/python3/3 cython/libdir/cstorer.pxd b/test cases/python3/3 cython/libdir/cstorer.pxd new file mode 100644 index 0000000..7b730fc --- /dev/null +++ b/test cases/python3/3 cython/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/test cases/python3/3 cython/libdir/meson.build b/test cases/python3/3 cython/libdir/meson.build new file mode 100644 index 0000000..5c0352e --- /dev/null +++ b/test cases/python3/3 cython/libdir/meson.build @@ -0,0 +1,23 @@ +if host_machine.system() == 'darwin' + # Default suffix is 'dylib' but Python does not use for extensions. + suffix = 'so' +elif host_machine.system() == 'windows' + # On Windows the extension is pyd for some unexplainable reason. + suffix = 'pyd' +else + suffix = [] +endif + +pyx_c = custom_target('storer_pyx', + output : 'storer_pyx.c', + input : 'storer.pyx', + command : [cython, '@INPUT@', '-o', '@OUTPUT@'], +) + +slib = shared_library('storer', + 'storer.c', pyx_c, + name_prefix : '', + name_suffix : suffix, + dependencies : py3_dep) + +pydir = meson.current_build_dir() diff --git a/test cases/python3/3 cython/libdir/storer.c b/test cases/python3/3 cython/libdir/storer.c new file mode 100644 index 0000000..0199bb8 --- /dev/null +++ b/test cases/python3/3 cython/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/test cases/python3/3 cython/libdir/storer.h b/test cases/python3/3 cython/libdir/storer.h new file mode 100644 index 0000000..4f71917 --- /dev/null +++ b/test cases/python3/3 cython/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/test cases/python3/3 cython/libdir/storer.pyx b/test cases/python3/3 cython/libdir/storer.pyx new file mode 100644 index 0000000..ed551dc --- /dev/null +++ b/test cases/python3/3 cython/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/test cases/python3/3 cython/meson.build b/test cases/python3/3 cython/meson.build new file mode 100644 index 0000000..cd245c7 --- /dev/null +++ b/test cases/python3/3 cython/meson.build @@ -0,0 +1,17 @@ +project('cython', 'c', + default_options : ['warning_level=3']) + +cython = find_program('cython3', required : false) + +if cython.found() + py3_dep = dependency('python3') + + subdir('libdir') + + test('cython tester', + find_program('cytest.py'), + env : ['PYTHONPATH=' + pydir] + ) +else + message('Cython not found, skipping test.') +endif |