Skip to content

Commit 18bddfd

Browse files
committed
tests: build a minimal project with each interpreter
1 parent d68f0ef commit 18bddfd

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed

tests/forty-two/forty-two.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <Python.h>
2+
3+
static PyObject * answer(PyObject *self, PyObject *args)
4+
{
5+
return PyLong_FromLong(42);
6+
}
7+
8+
/* Module initialization */
9+
static PyMethodDef module_methods[] = {
10+
{"answer", (PyCFunction)answer, METH_NOARGS, "The answer."},
11+
{NULL} /* Sentinel */
12+
};
13+
14+
PyMODINIT_FUNC PyInit_forty_two(void)
15+
{
16+
static struct PyModuleDef moduledef = {
17+
PyModuleDef_HEAD_INIT, "forty_two", "The answer module", -1, module_methods,
18+
};
19+
return PyModule_Create(&moduledef);
20+
}

tests/forty-two/pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["setuptools"]
3+
build-backend = "setuptools.build_meta"

tests/forty-two/setup.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from setuptools import setup, Extension
2+
3+
setup(
4+
name="forty_two",
5+
version="0.1.0",
6+
python_requires=">=3.6",
7+
ext_modules=[Extension("forty_two", sources=["forty-two.c"])],
8+
)

tests/run_tests.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,29 @@ for PYTHON in /opt/python/*/bin/python; do
4040
LINK_VERSION=$(${LINK_PREFIX}${PYVERS} -V)
4141
REAL_VERSION=$(${PYTHON} -V)
4242
test "${LINK_VERSION}" = "${REAL_VERSION}"
43+
44+
# check a simple project can be built
45+
SRC_DIR=/tmp/forty-two-${IMPLEMENTATION}${PYVERS}
46+
DIST_DIR=/tmp/dist-${IMPLEMENTATION}${PYVERS}
47+
cp -rf ${MY_DIR}/forty-two ${SRC_DIR}
48+
PY_ABI_TAGS=$(basename $(dirname $(dirname $PYTHON)))
49+
EXPECTED_WHEEL_NAME=forty_two-0.1.0-${PY_ABI_TAGS}-linux_${AUDITWHEEL_ARCH}.whl
50+
${PYTHON} -m build -w -o ${DIST_DIR} ${SRC_DIR}
51+
if [ ! -f ${DIST_DIR}/${EXPECTED_WHEEL_NAME} ]; then
52+
echo "unexcpected wheel built: '$(basename $(find ${DIST_DIR} -name '*.whl'))' instead of '${EXPECTED_WHEEL_NAME}'"
53+
exit 1
54+
fi
55+
auditwheel repair --only-plat -w ${DIST_DIR} ${DIST_DIR}/${EXPECTED_WHEEL_NAME}
56+
REPAIRED_WHEEL=$(find ${DIST_DIR} -name "forty_two-0.1.0-${PY_ABI_TAGS}-*${AUDITWHEEL_POLICY}_${AUDITWHEEL_ARCH}*.whl")
57+
if [ ! -f "${REPAIRED_WHEEL}" ]; then
58+
echo "invalid repaired wheel name"
59+
exit 1
60+
fi
61+
${PYTHON} -m pip install ${REPAIRED_WHEEL}
62+
if [ "$(${PYTHON} -c 'import forty_two; print(forty_two.answer())')" != "42" ]; then
63+
echo "invalid answer, expecting 42"
64+
exit 1
65+
fi
4366
done
4467

4568
# minimal tests for tools that should be present

0 commit comments

Comments
 (0)