WIP tests for venv
This commit is contained in:
parent
57457cbafb
commit
42e0692eab
2 changed files with 75 additions and 0 deletions
8
.gitignore
vendored
Normal file
8
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
.pytest_cache/
|
||||||
|
.tox/
|
||||||
|
build/
|
||||||
|
/module.*
|
||||||
|
/setup.py
|
||||||
|
/test_foo.py
|
||||||
|
/tox.ini
|
||||||
|
/venv/
|
||||||
67
tests-venv
Executable file
67
tests-venv
Executable file
|
|
@ -0,0 +1,67 @@
|
||||||
|
#!/bin/sh -eux
|
||||||
|
|
||||||
|
# TODO set this from outside depending on the package
|
||||||
|
VERSION=3.7
|
||||||
|
PYTHON=python$VERSION
|
||||||
|
|
||||||
|
# clean from possible older runs
|
||||||
|
rm -rf venv .tox __pycache__ .pytest* test_*.py *.pyx *.c *.so || :
|
||||||
|
|
||||||
|
# check the we can create the venv
|
||||||
|
$PYTHON -m venv venv
|
||||||
|
|
||||||
|
# and activate it
|
||||||
|
source venv/bin/activate
|
||||||
|
|
||||||
|
# run python in it
|
||||||
|
python -c 'import sys; print(sys.version)' | head -n1 | grep $VERSION
|
||||||
|
|
||||||
|
# install packages with pip
|
||||||
|
python -m pip install pytest
|
||||||
|
|
||||||
|
# run tests
|
||||||
|
cat > test_foo.py << EOF
|
||||||
|
def test_foo():
|
||||||
|
assert True
|
||||||
|
EOF
|
||||||
|
|
||||||
|
python -m pytest -v test_foo.py
|
||||||
|
|
||||||
|
# check that we can do extension modules
|
||||||
|
cat > module.pyx << EOF
|
||||||
|
cdef int add(int a, int b):
|
||||||
|
return a + b
|
||||||
|
|
||||||
|
def two():
|
||||||
|
cdef int a = 1
|
||||||
|
cdef int b = 1
|
||||||
|
return add(a, b)
|
||||||
|
EOF
|
||||||
|
|
||||||
|
cat > setup.py << EOF
|
||||||
|
from setuptools import setup
|
||||||
|
from Cython.Build import cythonize
|
||||||
|
|
||||||
|
setup(ext_modules = cythonize('module.pyx'))
|
||||||
|
EOF
|
||||||
|
|
||||||
|
python -m pip install Cython
|
||||||
|
python setup.py build_ext --inplace
|
||||||
|
|
||||||
|
python -c 'import module; print(module.two())' | grep '^2$'
|
||||||
|
|
||||||
|
# deactivate has unset variable, it's known
|
||||||
|
set +u
|
||||||
|
deactivate
|
||||||
|
set -u
|
||||||
|
|
||||||
|
# use it with tox
|
||||||
|
cat > tox.ini << EOF
|
||||||
|
[tox]
|
||||||
|
skipsdist = True
|
||||||
|
[testenv]
|
||||||
|
deps = pytest
|
||||||
|
commands = python -m pytest -v test_foo.py
|
||||||
|
EOF
|
||||||
|
|
||||||
|
tox -e py${VERSION/./}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue