tests: Switch to unit2 test runner, with coverage

This means test files are imported as modules, not run as scripts. THey
can still be run individually if so desired. Test coverage is measured,
and an html report generated in htmlcov/. Test cases are automativally
discovered, so they need not be listed twice. An overall
passed/failed/skipped summary is printed, rather than for each file.

Arguments passed to ./test are passed on to unit2. For instance

    ./test -v

will print each test name as it is run.
pull/180/head
Alex Willmer 7 years ago
parent 7b8fef5284
commit dc60f05a40

2
.gitignore vendored

@ -1,7 +1,9 @@
.coverage
.venv .venv
**/.DS_Store **/.DS_Store
MANIFEST MANIFEST
build/ build/
dist/ dist/
docs/_build docs/_build
htmlcov/
*.egg-info *.egg-info

@ -12,7 +12,7 @@ install:
- pip install -r dev_requirements.txt - pip install -r dev_requirements.txt
script: script:
- MITOGEN_LOG_LEVEL=debug PYTHONPATH=. ${TRAVIS_BUILD_DIR}/test.sh - MITOGEN_LOG_LEVEL=debug PYTHONPATH=. ${TRAVIS_BUILD_DIR}/test
services: services:
- docker - docker

@ -1,3 +1,10 @@
[coverage:run]
branch = true
source =
mitogen
omit =
mitogen/compat/*
[flake8] [flake8]
ignore = E402,E128,W503 ignore = E402,E128,W503
exclude = mitogen/compat exclude = mitogen/compat

11
test

@ -0,0 +1,11 @@
#/bin/sh
UNIT2="$(which unit2)"
coverage erase
coverage run "${UNIT2}" discover \
--start-directory "tests" \
--pattern '*_test.py' \
"$@"
coverage html
echo coverage report is at "file://$(pwd)/htmlcov/index.html"

@ -1,63 +0,0 @@
#!/bin/bash
timeout()
{
python -c '
import subprocess
import sys
import time
deadline = time.time() + float(sys.argv[1])
proc = subprocess.Popen(sys.argv[2:])
while time.time() < deadline and proc.poll() is None:
time.sleep(1.0)
if proc.poll() is not None:
sys.exit(proc.returncode)
proc.terminate()
print
print >> sys.stderr, "Timeout! Command was:", sys.argv[2:]
print
sys.exit(1)
' "$@"
}
trap 'sigint' INT
sigint()
{
echo "SIGINT received, stopping.."
exit 1
}
run_test()
{
echo "Running $1.."
timeout 10 python $1 || fail=$?
}
run_test tests/ansible_helpers_test.py
run_test tests/call_error_test.py
run_test tests/call_function_test.py
run_test tests/channel_test.py
run_test tests/fakessh_test.py
run_test tests/first_stage_test.py
run_test tests/fork_test.py
run_test tests/id_allocation_test.py
run_test tests/importer_test.py
run_test tests/latch_test.py
run_test tests/local_test.py
run_test tests/master_test.py
run_test tests/module_finder_test.py
run_test tests/nested_test.py
run_test tests/parent_test.py
run_test tests/receiver_test.py
run_test tests/responder_test.py
run_test tests/router_test.py
run_test tests/select_test.py
run_test tests/ssh_test.py
run_test tests/utils_test.py
if [ "$fail" ]; then
echo "AT LEAST ONE TEST FAILED" >&2
exit 1
fi

@ -27,4 +27,4 @@ and run the tests there.
1. Build the virtual environment ``virtualenv ../venv`` 1. Build the virtual environment ``virtualenv ../venv``
1. Enable the virtual environment we just built ``source ../venv/bin/activate`` 1. Enable the virtual environment we just built ``source ../venv/bin/activate``
1. Install Mitogen in pip editable mode ``pip install -e .`` 1. Install Mitogen in pip editable mode ``pip install -e .``
1. Run ``test.sh`` 1. Run ``test``

@ -8,7 +8,7 @@ deps =
-r{toxinidir}/dev_requirements.txt -r{toxinidir}/dev_requirements.txt
commands = commands =
{posargs:./test.sh} {posargs:./test}
[testenv:docs] [testenv:docs]
basepython = python basepython = python

Loading…
Cancel
Save