forked from mozilla-releng/balrog
/
Makefile
65 lines (56 loc) · 2.09 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
VIRTUALENV ?= /usr/bin/virtualenv
COVERAGE_BIN ?= coverage
# The Python binary to use when running the virtualenv script.
PYTHON ?= python
NOSE ?= $(shell which nosetests)
# When COVERAGE is set, python code coverage reports will be generated
# during test runs.
COVERAGE ?=
VIRTUALENV_DIR ?= $(error VIRTUALENV_DIR must be set when running virtualenv or ci-tests targets)
PYTHONPATH ?= vendor/lib/python
# A pip requirements file describing the dependencies that should be installed
# into the virtualenv.
REQUIREMENTS = requirements/dev.txt
COMPILED_REQUIREMENTS = requirements/compiled.txt
ifdef VERBOSE
NOSE_ARGS += -v
TEST_ARGS += -v
endif
# Append the test directory to the nose args, to avoid picking up files like
# auslib/util/testing.py.
NOSE_ARGS += auslib/test
ALL_PY_FILES := $(shell find . \( -iname "*.py" -or -iname "*.wsgi" \) -not -path "*vendor*")
PYTHON_ENV = PYTHONDONTWRITEBYTECODE=1 PYTHONPATH=$(PYTHONPATH)
# Used to run the tests. Useful for both CI-driven tests and manual ones.
test: test.done
test.done: $(ALL_PY_FILES) $(if $(ALWAYS_RUN_TESTS), FORCE)
@echo Running unit tests
ifdef COVERAGE
$(RM) -r .coverage htmlcov
-$(PYTHON_ENV) $(COVERAGE_BIN) run $(NOSE) $(NOSE_ARGS)
else
-$(PYTHON_ENV) $(NOSE) $(NOSE_ARGS)
endif
@echo Running rules tests
ifdef COVERAGE
-$(COVERAGE_BIN) run -a scripts/test-rules.py $(TEST_ARGS)
$(COVERAGE_BIN) html --include='*auslib*'
else
-$(PYTHON) scripts/test-rules.py $(TEST_ARGS)
endif
touch $@
# Creates a virtualenv containing all the requirements needed to run tests.
PIP_INSTALL = $(VIRTUALENV_DIR)/bin/pip -q install
virtualenv:
$(PYTHON) $(VIRTUALENV) --no-site-packages $(VIRTUALENV_DIR)
$(PIP_INSTALL) -r $(REQUIREMENTS)
$(PIP_INSTALL) -r $(COMPILED_REQUIREMENTS)
test-in-virtualenv: PYTHON=$(VIRTUALENV_DIR)/bin/python
test-in-virtualenv: NOSE=$(VIRTUALENV_DIR)/bin/nosetests
test-in-virtualenv: COVERAGE_BIN=$(VIRTUALENV_DIR)/bin/coverage
test-in-virtualenv: test
# Run the tests, installing any necessary libraries into a virtualenv.
ci-tests: virtualenv test-in-virtualenv
pyflakes: $(ALL_PY_FILES)
pyflakes $(ALL_PY_FILES)
.PHONY: FORCE