From 88857f15982a90f7f2cc541585ac0df5609674ed Mon Sep 17 00:00:00 2001 From: Ivo De Decker Date: Fri, 12 Apr 2019 11:48:06 +0000 Subject: [PATCH] Add test coverage Based on patches by Niels Thykier to add coverage to britney. --- .coveragerc | 1 + .gitlab-ci.yml | 6 +++++- debian/control | 2 ++ debian/rules | 16 +++++++++++++++- debian/run-ci | 8 ++++++++ integration-tests/dak-coverage.sh | 10 ++++++++++ setup/dak-setup.sh | 7 ++++++- 7 files changed, 47 insertions(+), 3 deletions(-) create mode 100755 integration-tests/dak-coverage.sh diff --git a/.coveragerc b/.coveragerc index 7a7ee8ab..56ec1ee0 100644 --- a/.coveragerc +++ b/.coveragerc @@ -5,3 +5,4 @@ omit = */lib/python*/* */dist-packages/* */tests/* +source = . diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a3893ff7..c72df5d8 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -11,7 +11,10 @@ test stretch: test buster: <<: *template image: debian:buster - script: debian/run-ci + script: debian/run-ci --with-coverage + artifacts: + paths: + - coverage flake8: <<: *template @@ -28,6 +31,7 @@ pages: - apt-get install -y python-epydoc - mkdir -p public/epydoc - epydoc -q --html --graph all --css blue -n DAK -o public/epydoc --include-log --show-imports dak dakweb + - mv coverage public/coverage artifacts: paths: - public diff --git a/debian/control b/debian/control index 9e62c0eb..0414826b 100644 --- a/debian/control +++ b/debian/control @@ -11,11 +11,13 @@ Build-Depends: alembic, postgresql-11-debversion | postgresql-9.6-debversion | postgresql-9.4-debversion, python-all-dev, python-apt, + python-coverage, python-debian, python-debianbts, python-ldap, python-psycopg2, python-pytest, + python-pytest-cov, python-rrdtool, python-sqlalchemy, python-tabulate, diff --git a/debian/rules b/debian/rules index d51e29f3..3dce13de 100755 --- a/debian/rules +++ b/debian/rules @@ -7,6 +7,10 @@ ifneq ($(JENKINS_EXPORTS_DIR),) PYBUILD_EXTRA_ARGS = --junit-xml=$(JENKINS_EXPORTS_DIR)/test-results/tests.xml endif +ifeq ($(RUN_COVERAGE),y) +PYTEST_COV_OPTIONS = --cov-branch --cov --cov-report= +endif + override_dh_auto_test: ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS))) ifneq ($(JENKINS_EXPORTS_DIR),) @@ -14,8 +18,18 @@ ifneq ($(JENKINS_EXPORTS_DIR),) endif mkdir -p debian/test-gnupghome make -C tests/fixtures/packages - GNUPGHOME=$$(pwd)/debian/test-gnupghome py.test -v daklib tests $(PYBUILD_EXTRA_ARGS) + GNUPGHOME=$$(pwd)/debian/test-gnupghome py.test -v $(PYTEST_COV_OPTIONS) daklib tests $(PYBUILD_EXTRA_ARGS) +ifeq ($(RUN_COVERAGE),y) + python-coverage combine --append +endif ./integration-tests/run-tests + +ifeq ($(RUN_COVERAGE),y) + python-coverage combine --append + python-coverage report -m + echo + python-coverage html -d coverage +endif endif # Replace with "debian/test-gnupghome/" in d/clean once diff --git a/debian/run-ci b/debian/run-ci index 61170c24..1dbac0d3 100755 --- a/debian/run-ci +++ b/debian/run-ci @@ -16,6 +16,14 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +if [ "x$1" = "x--with-coverage" ]; then + RUN_COVERAGE=y +else + RUN_COVERAGE= +fi + +export RUN_COVERAGE + set -eu if [ ! -f dak/dak.py ]; then diff --git a/integration-tests/dak-coverage.sh b/integration-tests/dak-coverage.sh new file mode 100755 index 00000000..a9ca1ee1 --- /dev/null +++ b/integration-tests/dak-coverage.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +# wrapper to collect coverage info when running dak + +if [ "$RUN_COVERAGE" = "y" ] +then + exec python-coverage run --rcfile "${DAK_ROOT}/.coveragerc" --parallel-mode "${DAK_ROOT}/dak/dak.py" "$@" +else + exec "${DAK_ROOT}/dak/dak.py" "$@" +fi diff --git a/setup/dak-setup.sh b/setup/dak-setup.sh index 09161fc6..001e5448 100755 --- a/setup/dak-setup.sh +++ b/setup/dak-setup.sh @@ -75,7 +75,12 @@ dak-setup() { (cd ${setupdir}; ./init_minimal_conf | $USER_CMD tee ${DAK_CONFIG} >/dev/null) $USER_CMD echo 'DB::Role "dak";' | tee -a ${DAK_CONFIG} >/dev/null - ln -s ${DAK_ROOT}/dak/dak.py ${DAKBASE}/bin/dak + if [[ ! -v DAK_INTEGRATION_TEST ]]; then + ln -s ${DAK_ROOT}/dak/dak.py ${DAKBASE}/bin/dak + else + # wrapper to collect coverage information + ln -s ${DAK_ROOT}/integration-tests/dak-coverage.sh ${DAKBASE}/bin/dak + fi # Update the database schema $USER_CMD ${DAK_ROOT}/dak/dak.py update-db --yes -- GitLab