Skip to content

Commit

Permalink
Introduce Python and C++ code coverage reports and checks
Browse files Browse the repository at this point in the history
  • Loading branch information
alejandrosame committed Aug 21, 2020
1 parent 0ec5071 commit 4853626
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 4 deletions.
9 changes: 9 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
LC_ALL=C.UTF-8
LANG=C.UTF-8

MIN_COVERAGE=80
4 changes: 4 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ wheels/
htmlcov/
.coverage
.coverage.*
.coveragepy
.coveragepy.*
.cache
nosetests.xml
coverage.xml
Expand All @@ -49,3 +51,6 @@ coverage.xml
.mypy_cache/
docs/_build/*
docs/_generate/*
*.gcov
coverage_report/*
!coverage_report/index.html
27 changes: 24 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
include .env # Read .env file

.PHONY: clean clean-test clean-pyc clean-build docs help
.DEFAULT_GOAL := help

Expand Down Expand Up @@ -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 ./
Expand All @@ -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/*
Expand Down
2 changes: 2 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ black = "*"
twine = "*"
sphinx = "*"
sphinx-rtd-theme = "*"
gcovr = "*"
coverage = "*"

[packages]
2 changes: 1 addition & 1 deletion build_PyDP.sh
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions coverage_report/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<title>PyDP code coverage report</title>
</head>
<body>
<iframe src="./python/index.html" onload="this.width=screen.width-50;this.height=(screen.height/2)-100;" style="float:left;"></iframe>
<div style="clear:both; height:20px;"></div>
<iframe src="./cpp/index.html" onload="this.width=screen.width-50;this.height=(screen.height/2)-100;"style="float:left;"></iframe>
</div>

</body>
</html>
6 changes: 6 additions & 0 deletions gcovr.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# .gcovr.cfg to control gcovr
root = bazel-bin/src
filter = src

html-details = yes
output = coverage_report/cpp/index.html

0 comments on commit 4853626

Please sign in to comment.