From 4853626c8670ec2b811bca2ee05e45b05d768fbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20S=C3=A1nchez=20Medina?= Date: Fri, 21 Aug 2020 16:09:10 +0100 Subject: [PATCH 1/3] Introduce Python and C++ code coverage reports and checks --- .coveragerc | 9 +++++++++ .env | 2 ++ .github/workflows/tests.yml | 4 ++++ .gitignore | 5 +++++ Makefile | 27 ++++++++++++++++++++++++--- Pipfile | 2 ++ build_PyDP.sh | 2 +- coverage_report/index.html | 13 +++++++++++++ gcovr.cfg | 6 ++++++ 9 files changed, 66 insertions(+), 4 deletions(-) create mode 100644 .coveragerc create mode 100644 coverage_report/index.html create mode 100644 gcovr.cfg diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 00000000..b98d5d39 --- /dev/null +++ b/.coveragerc @@ -0,0 +1,9 @@ +# .coveragerc to control coverage.py +[run] +branch = True +data_file = .coveragepy.dat +source = pydp + +[html] +directory = coverage_report/python +title = Python code coverage report diff --git a/.env b/.env index ad82af13..ce98bbc5 100644 --- a/.env +++ b/.env @@ -1,2 +1,4 @@ LC_ALL=C.UTF-8 LANG=C.UTF-8 + +MIN_COVERAGE=80 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 45675898..b251ef05 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -36,3 +36,7 @@ jobs: - name: Run tests run: | make run-tests-only + - name: Check code coverage tests + run: | + make check-coverage-python + make check-coverage-cpp diff --git a/.gitignore b/.gitignore index 3f031637..8390c6fb 100644 --- a/.gitignore +++ b/.gitignore @@ -40,6 +40,8 @@ wheels/ htmlcov/ .coverage .coverage.* +.coveragepy +.coveragepy.* .cache nosetests.xml coverage.xml @@ -49,3 +51,6 @@ coverage.xml .mypy_cache/ docs/_build/* docs/_generate/* +*.gcov +coverage_report/* +!coverage_report/index.html diff --git a/Makefile b/Makefile index ba6c489f..39c91c5a 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,5 @@ +include .env # Read .env file + .PHONY: clean clean-test clean-pyc clean-build docs help .DEFAULT_GOAL := help @@ -51,6 +53,7 @@ clean-test: ## remove test and coverage artifacts rm -f .coverage rm -fr htmlcov/ rm -fr .pytest_cache + find . -name '*.gcov' -exec rm -fr {} + format-style-python: ## format Python files code style in-place @ pipenv run black ./ @@ -71,10 +74,28 @@ check-style-cpp: ## check for C++ code style in-place ( echo "\e[33mRun \e[34mmake format-style-cpp\e[33m to fix style errors.\e[0m"; \ exit 1 ) -run-tests-only: install ## run tests without style tests - pipenv run pytest tests +check-coverage-python: ## check for Python code coverage + @ echo "\e[36mChecking Python code coverage with MIN_COVERAGE=${MIN_COVERAGE}.\e[0m" && \ + pipenv run coverage report --fail-under ${MIN_COVERAGE} || \ + ( echo "\e[33mRun \e[34mmake show-coverage\e[33m to see a detailed HTML coverage report.\e[0m"; \ + exit 1 ) + +check-coverage-cpp: ## check for C++ code coverage + @ echo "\e[36mChecking C++ code style with MIN_COVERAGE=${MIN_COVERAGE}.\e[0m" && \ + pipenv run gcovr --print-summary --fail-under-line ${MIN_COVERAGE} || \ + ( echo "\e[33mRun \e[34mmake show-coverage\e[33m to see a detailed HTML coverage report.\e[0m"; \ + exit 1 ) + +run-tests-only: install ## run tests with coverage generation and without style tests + pipenv run coverage run -m pytest tests + +test: check-style-python check-style-cpp run-tests-only check-coverage-python check-coverage-cpp ## check style and run tests -test: check-style-python check-style-cpp run-tests-only ## check style and run tests +show-coverage: ## report code coverage + echo "\e[36mGenerating code coverage HTML report.\e[0m" + pipenv run coverage html -d coverage_report/python + pipenv run gcovr --html-details coverage_report/cpp/index.html + $(BROWSER) coverage_report/index.html release: dist ## package and upload a release twine upload dist/* diff --git a/Pipfile b/Pipfile index 976a58f3..6a598275 100644 --- a/Pipfile +++ b/Pipfile @@ -11,5 +11,7 @@ black = "*" twine = "*" sphinx = "*" sphinx-rtd-theme = "*" +gcovr = "*" +coverage = "*" [packages] diff --git a/build_PyDP.sh b/build_PyDP.sh index 3227b180..65cc4fc6 100755 --- a/build_PyDP.sh +++ b/build_PyDP.sh @@ -1,6 +1,6 @@ #!/bin/bash pipenv install --dev --skip-lock -bazel build src/python:bindings_test --verbose_failures +bazel coverage src/python:bindings_test --verbose_failures find ./ -name _pydp.so -print0 | xargs -0 -I {} rm {} cp -f ./bazel-bin/src/bindings/_pydp.so ./pydp diff --git a/coverage_report/index.html b/coverage_report/index.html new file mode 100644 index 00000000..66af7159 --- /dev/null +++ b/coverage_report/index.html @@ -0,0 +1,13 @@ + + + + PyDP code coverage report + + + +
+ + + + + diff --git a/gcovr.cfg b/gcovr.cfg new file mode 100644 index 00000000..bd15477e --- /dev/null +++ b/gcovr.cfg @@ -0,0 +1,6 @@ +# .gcovr.cfg to control gcovr +root = bazel-bin/src +filter = src + +html-details = yes +output = coverage_report/cpp/index.html From f7695328e2ac8aaea44e18b17646df696fb4574c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20S=C3=A1nchez=20Medina?= Date: Fri, 21 Aug 2020 16:36:09 +0100 Subject: [PATCH 2/3] Ensure cpp code coverare report folder exists --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 39c91c5a..a9d0f83f 100644 --- a/Makefile +++ b/Makefile @@ -82,6 +82,7 @@ check-coverage-python: ## check for Python code coverage check-coverage-cpp: ## check for C++ code coverage @ echo "\e[36mChecking C++ code style with MIN_COVERAGE=${MIN_COVERAGE}.\e[0m" && \ + mkdir -p coverage_report/cpp && \ pipenv run gcovr --print-summary --fail-under-line ${MIN_COVERAGE} || \ ( echo "\e[33mRun \e[34mmake show-coverage\e[33m to see a detailed HTML coverage report.\e[0m"; \ exit 1 ) From 7d88671831ff804f989765d6c360ead467b954cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20S=C3=A1nchez=20Medina?= Date: Fri, 21 Aug 2020 21:08:54 +0100 Subject: [PATCH 3/3] Split code coverage checks into two CI steps --- .github/workflows/tests.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index b251ef05..460a0d0b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -36,7 +36,9 @@ jobs: - name: Run tests run: | make run-tests-only - - name: Check code coverage tests + - name: Check Python code coverage run: | make check-coverage-python + - name: Check C++ code coverage + run: | make check-coverage-cpp