Makefile 1.31 KB
Newer Older
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
OMIT=/usr/share/pyshared/*,/usr/local/lib/python*,*__init__.py,test*
COVERAGE_OUTPUT_DIR=coverage
TESTS=`find tests -name test_\*.py`

# Find python coverage version
ifeq ($(findstring python-coverage,$(wildcard /usr/bin/*)), python-coverage)
COVERAGE=/usr/bin/python-coverage
else
COVERAGE=`which coverage`
endif

all:

# Unit tests
test:
	@for t in ${TESTS}; do \
		python test.py $$t; \
	done

# Cleanup
clean:
	rm -rf .coverage ${COVERAGE_OUTPUT_DIR}

distclean: clean
	rm -rf `find -name \*.pyc`

# Code coverage (differs between versions)
coverage: .coverage

ifeq ($(findstring python-coverage,$(wildcard /usr/bin/*)), python-coverage)
.coverage:
	@${COVERAGE} erase
	@rm -f ${COVERAGE_OUTPUT_DIR}/*
	@mkdir -p ${COVERAGE_OUTPUT_DIR} 2>/dev/null || true
	@for t in ${TESTS}; do \
		${COVERAGE} -x test.py $$t; \
		${COVERAGE} combine; \
	done
	@${COVERAGE} html --omit=${OMIT} -d ${COVERAGE_OUTPUT_DIR}
	@rm $@
	@echo "Coverage report created in ${COVERAGE_OUTPUT_DIR}/index.html"
else
.coverage:
	@mkdir -p ${COVERAGE_OUTPUT_DIR} 2>/dev/null || true
	@${COVERAGE} erase
	@for t in ${TESTS}; do \
		${COVERAGE} --omit ${OMIT} -x test.py $$t; \
		${COVERAGE} --omit ${OMIT} -c; \
	done
	@${COVERAGE} html --omit ${OMIT} --dir ${COVERAGE_OUTPUT_DIR}
	@rm $@
	@echo "Coverage report created in ${COVERAGE_OUTPUT_DIR}/index.html"
endif