cython: Add a test for generated files

pull/8706/head
Dylan Baker 4 years ago
parent 74ed27f776
commit a2fc2e2165
  1. 2
      test cases/cython/2 generated sources/configure.pyx.in
  2. 2
      test cases/cython/2 generated sources/g.in
  3. 14
      test cases/cython/2 generated sources/gen.py
  4. 12
      test cases/cython/2 generated sources/generator.py
  5. 61
      test cases/cython/2 generated sources/meson.build
  6. 13
      test cases/cython/2 generated sources/test.py

@ -0,0 +1,2 @@
cpdef func():
return "Hello, World!"

@ -0,0 +1,2 @@
cpdef func():
return "Hello, World!"

@ -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!"
'''))

@ -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())

@ -0,0 +1,61 @@
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()]
)
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()]
)

@ -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!'
Loading…
Cancel
Save