Skip to content

Commit

Permalink
tests: add a test for cython structured_sources
Browse files Browse the repository at this point in the history
  • Loading branch information
dcbaker committed Mar 2, 2022
1 parent a8e530d commit f4fc2c8
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 0 deletions.
16 changes: 16 additions & 0 deletions test cases/cython/4 structured sources/gen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env python3

import argparse


def main() -> None:
parser = argparse.ArgumentParser()
parser.add_argument('out')
args = parser.parse_args()

with open(args.out, 'w') as f:
f.write('cpdef int generate(int in_)\n')


if __name__ == '__main__':
main()
Empty file.
2 changes: 2 additions & 0 deletions test cases/cython/4 structured sources/gen/gen.pyx
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cpdef int generate(int in_):
return in_ + 1
4 changes: 4 additions & 0 deletions test cases/cython/4 structured sources/lib.pyx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from gen import generated

cpdef int foo(int in_):
return generated(in_)
30 changes: 30 additions & 0 deletions test cases/cython/4 structured sources/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
project('structured 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

gen = custom_target(
'gen.pyd',
output : ['gen.pyd'],
command : ['gen.py', '@OUTPUT@'],
)

py3.extension_module(
'lib',
structured_sources(
'lib.pyx',
{'gen' : [gen, 'gen/gen.pyx', 'gen/__init__.pyd']},
),
dependencies : py3_dep,
)

test(
'lib',
py3,
args : [files('test.py')],
env : ['PYTHONPATH=' + meson.current_build_dir()]
)
9 changes: 9 additions & 0 deletions test cases/cython/4 structured sources/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import lib


def main() -> int:
return int(lib.generate(1)) == 2


if __name__ == "__main__":
exit(main())

0 comments on commit f4fc2c8

Please sign in to comment.