Makefile 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. OMIT=/usr/share/pyshared/*,/usr/local/lib/python*,*__init__.py,test*
  2. COVERAGE_OUTPUT_DIR=coverage
  3. TESTS=`find tests -name test_\*.py`
  4. # Find python coverage version
  5. ifeq ($(findstring python-coverage,$(wildcard /usr/bin/*)), python-coverage)
  6. COVERAGE=/usr/bin/python-coverage
  7. else
  8. COVERAGE=`which coverage`
  9. endif
  10. all:
  11. # Unit tests
  12. test:
  13. @for t in ${TESTS}; do \
  14. python test.py $$t; \
  15. done
  16. # Cleanup
  17. clean:
  18. rm -rf .coverage ${COVERAGE_OUTPUT_DIR}
  19. distclean: clean
  20. rm -rf `find -name \*.pyc`
  21. # Code coverage (differs between versions)
  22. coverage: .coverage
  23. ifeq ($(findstring python-coverage,$(wildcard /usr/bin/*)), python-coverage)
  24. .coverage:
  25. @${COVERAGE} erase
  26. @rm -f ${COVERAGE_OUTPUT_DIR}/*
  27. @mkdir -p ${COVERAGE_OUTPUT_DIR} 2>/dev/null || true
  28. @for t in ${TESTS}; do \
  29. ${COVERAGE} -x test.py $$t; \
  30. ${COVERAGE} combine; \
  31. done
  32. @${COVERAGE} html --omit=${OMIT} -d ${COVERAGE_OUTPUT_DIR}
  33. @rm $@
  34. @echo "Coverage report created in ${COVERAGE_OUTPUT_DIR}/index.html"
  35. else
  36. .coverage:
  37. @mkdir -p ${COVERAGE_OUTPUT_DIR} 2>/dev/null || true
  38. @${COVERAGE} erase
  39. @for t in ${TESTS}; do \
  40. ${COVERAGE} --omit ${OMIT} -x test.py $$t; \
  41. ${COVERAGE} --omit ${OMIT} -c; \
  42. done
  43. @${COVERAGE} html --omit ${OMIT} --dir ${COVERAGE_OUTPUT_DIR}
  44. @rm $@
  45. @echo "Coverage report created in ${COVERAGE_OUTPUT_DIR}/index.html"
  46. endif