Skip to content
This repository was archived by the owner on Apr 30, 2021. It is now read-only.

Commit 19e09e4

Browse files
committed
Add a Makefile to allow testing of the existing code.
A small makefile allows the invocation of the test modules, so that we can exercise the system and make sure that it does sensible things when it's run - or at least that it doesn't regress.
1 parent 6c7dae6 commit 19e09e4

1 file changed

Lines changed: 77 additions & 0 deletions

File tree

Makefile

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Common User Targets:
2+
#
3+
# make tests
4+
# - Sxecute the tests
5+
#
6+
# make shell
7+
# - Set up the environment and drop to a shell (re-uses existing shells if they
8+
# have already been set up).
9+
# Use ctrl-d or `exit` to leave the shell.
10+
#
11+
# PYTHON_TOOL=python2 make <target>
12+
# - Build the target requested, using python 2
13+
#
14+
#
15+
# Assumptions:
16+
# * Python 3 is installed as `python3`. Use the PYTHON_TOOL variable to test using a
17+
# specific python binary.
18+
# * The 'virtualenv' tool is installed.
19+
#
20+
21+
22+
PYTHON_TOOL ?= python3
23+
ACTIVATE = source venv/${PYTHON_TOOL}/bin/activate
24+
25+
.PHONY: tests venv
26+
27+
TEST_MODULES = ${patsubst tests/%.py,%,$(wildcard tests/test_*.py)}
28+
29+
ifeq (${NOCOLOUR},)
30+
COL_NOTICE = "\\e[35m"
31+
COL_GOOD = "\\e[32m"
32+
COL_RESET = "\\e[0m"
33+
else
34+
COL_NOTICE = ""
35+
COL_GOOD = ""
36+
COL_RESET = ""
37+
endif
38+
39+
NOTICE = @notice() { printf "\n${COL_NOTICE}+++ %s${COL_RESET}\n" "$$@"; } && notice
40+
GOOD = @notice() { printf "\n${COL_GOOD}+++ %s${COL_RESET}\n" "$$@"; } && notice
41+
42+
43+
tests: test_testable
44+
${NOTICE} "Running tests"
45+
@# Note: We cd into the tests directory, so that we are testing the installed version, not
46+
@# the version in the repository.
47+
${ACTIVATE} && cd tests && python -munittest -v ${TEST_MODULES}
48+
${GOOD} "Tests passed"
49+
50+
venv: venv/successful-${PYTHON_TOOL}
51+
52+
venv/successful-${PYTHON_TOOL}:
53+
${NOTICE} "Build the virtualenv we will test within (for ${PYTHON_TOOL})"
54+
-rm -rf venv
55+
mkdir -p venv
56+
virtualenv -p ${PYTHON_TOOL} venv/${PYTHON_TOOL}
57+
touch venv/successful-${PYTHON_TOOL}
58+
59+
test_installable: venv
60+
${NOTICE} "Check that we can install the product"
61+
${ACTIVATE} && python setup.py install
62+
63+
test_testable: test_installable
64+
${NOTICE} "Install the test requirements"
65+
${ACTIVATE} && pip install -r requirements-test.txt
66+
67+
clean:
68+
${NOTICE} "Cleaning temporary files"
69+
-rm -rf venv dist build
70+
-find . -name '*.pyc' -delete
71+
-find . -name '__pycache__' -delete
72+
${GOOD} "Cleaned"
73+
74+
shell: venv
75+
${NOTICE} "Running shell; use ctrl-d or `exit` to leave"
76+
bash -i <<<"${ACTIVATE} && exec < /dev/tty"
77+
${GOOD} "Returned to user shell"

0 commit comments

Comments
 (0)