churchyard / tests / python

Forked from tests/python 5 years ago
Clone
dbd8442
#!/bin/sh -eux
dbd8442
dbd8442
# TODO set this from outside depending on the package
dbd8442
VERSION=3.7
dbd8442
PYTHON=python$VERSION
dbd8442
dbd8442
# clean from possible older runs
dbd8442
rm -rf venv .tox __pycache__ .pytest* test_*.py *.pyx *.c *.so || :
dbd8442
dbd8442
# check the we can create the venv
dbd8442
$PYTHON -m venv venv
dbd8442
dbd8442
# and activate it
dbd8442
source venv/bin/activate
dbd8442
dbd8442
# run python in it
dbd8442
python -c 'import sys; print(sys.version)' | head -n1 | grep $VERSION
dbd8442
dbd8442
# install packages with pip
dbd8442
python -m pip install pytest
dbd8442
dbd8442
# run tests
dbd8442
cat > test_foo.py << EOF
dbd8442
def test_foo():
dbd8442
    assert True
dbd8442
EOF
dbd8442
dbd8442
python -m pytest -v test_foo.py
dbd8442
dbd8442
# check that we can do extension modules
dbd8442
cat > module.pyx << EOF
dbd8442
cdef int add(int a, int b):
dbd8442
    return a + b
dbd8442
dbd8442
def two():
dbd8442
    cdef int a = 1
dbd8442
    cdef int b = 1
dbd8442
    return add(a, b)
dbd8442
EOF
dbd8442
dbd8442
cat > setup.py << EOF
dbd8442
from setuptools import setup
dbd8442
from Cython.Build import cythonize
dbd8442
dbd8442
setup(ext_modules = cythonize('module.pyx'))
dbd8442
EOF
dbd8442
dbd8442
python -m pip install Cython
dbd8442
python setup.py build_ext --inplace
dbd8442
dbd8442
python -c 'import module; print(module.two())' | grep '^2$'
dbd8442
dbd8442
# deactivate has unset variable, it's known
dbd8442
set +u
dbd8442
deactivate
dbd8442
set -u
dbd8442
dbd8442
# use it with tox
dbd8442
cat > tox.ini << EOF
dbd8442
[tox]
dbd8442
skipsdist = True
dbd8442
[testenv]
dbd8442
deps = pytest
dbd8442
commands = python -m pytest -v test_foo.py
dbd8442
EOF
dbd8442
dbd8442
tox -e py${VERSION/./}