Skip to content

Commit 4853626

Browse files
committed
Introduce Python and C++ code coverage reports and checks
1 parent 0ec5071 commit 4853626

9 files changed

Lines changed: 66 additions & 4 deletions

File tree

.coveragerc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# .coveragerc to control coverage.py
2+
[run]
3+
branch = True
4+
data_file = .coveragepy.dat
5+
source = pydp
6+
7+
[html]
8+
directory = coverage_report/python
9+
title = Python code coverage report

.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
LC_ALL=C.UTF-8
22
LANG=C.UTF-8
3+
4+
MIN_COVERAGE=80

.github/workflows/tests.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,7 @@ jobs:
3636
- name: Run tests
3737
run: |
3838
make run-tests-only
39+
- name: Check code coverage tests
40+
run: |
41+
make check-coverage-python
42+
make check-coverage-cpp

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ wheels/
4040
htmlcov/
4141
.coverage
4242
.coverage.*
43+
.coveragepy
44+
.coveragepy.*
4345
.cache
4446
nosetests.xml
4547
coverage.xml
@@ -49,3 +51,6 @@ coverage.xml
4951
.mypy_cache/
5052
docs/_build/*
5153
docs/_generate/*
54+
*.gcov
55+
coverage_report/*
56+
!coverage_report/index.html

Makefile

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
include .env # Read .env file
2+
13
.PHONY: clean clean-test clean-pyc clean-build docs help
24
.DEFAULT_GOAL := help
35

@@ -51,6 +53,7 @@ clean-test: ## remove test and coverage artifacts
5153
rm -f .coverage
5254
rm -fr htmlcov/
5355
rm -fr .pytest_cache
56+
find . -name '*.gcov' -exec rm -fr {} +
5457

5558
format-style-python: ## format Python files code style in-place
5659
@ pipenv run black ./
@@ -71,10 +74,28 @@ check-style-cpp: ## check for C++ code style in-place
7174
( echo "\e[33mRun \e[34mmake format-style-cpp\e[33m to fix style errors.\e[0m"; \
7275
exit 1 )
7376

74-
run-tests-only: install ## run tests without style tests
75-
pipenv run pytest tests
77+
check-coverage-python: ## check for Python code coverage
78+
@ echo "\e[36mChecking Python code coverage with MIN_COVERAGE=${MIN_COVERAGE}.\e[0m" && \
79+
pipenv run coverage report --fail-under ${MIN_COVERAGE} || \
80+
( echo "\e[33mRun \e[34mmake show-coverage\e[33m to see a detailed HTML coverage report.\e[0m"; \
81+
exit 1 )
82+
83+
check-coverage-cpp: ## check for C++ code coverage
84+
@ echo "\e[36mChecking C++ code style with MIN_COVERAGE=${MIN_COVERAGE}.\e[0m" && \
85+
pipenv run gcovr --print-summary --fail-under-line ${MIN_COVERAGE} || \
86+
( echo "\e[33mRun \e[34mmake show-coverage\e[33m to see a detailed HTML coverage report.\e[0m"; \
87+
exit 1 )
88+
89+
run-tests-only: install ## run tests with coverage generation and without style tests
90+
pipenv run coverage run -m pytest tests
91+
92+
test: check-style-python check-style-cpp run-tests-only check-coverage-python check-coverage-cpp ## check style and run tests
7693

77-
test: check-style-python check-style-cpp run-tests-only ## check style and run tests
94+
show-coverage: ## report code coverage
95+
echo "\e[36mGenerating code coverage HTML report.\e[0m"
96+
pipenv run coverage html -d coverage_report/python
97+
pipenv run gcovr --html-details coverage_report/cpp/index.html
98+
$(BROWSER) coverage_report/index.html
7899

79100
release: dist ## package and upload a release
80101
twine upload dist/*

Pipfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,7 @@ black = "*"
1111
twine = "*"
1212
sphinx = "*"
1313
sphinx-rtd-theme = "*"
14+
gcovr = "*"
15+
coverage = "*"
1416

1517
[packages]

build_PyDP.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

33
pipenv install --dev --skip-lock
4-
bazel build src/python:bindings_test --verbose_failures
4+
bazel coverage src/python:bindings_test --verbose_failures
55
find ./ -name _pydp.so -print0 | xargs -0 -I {} rm {}
66
cp -f ./bazel-bin/src/bindings/_pydp.so ./pydp

coverage_report/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>PyDP code coverage report</title>
5+
</head>
6+
<body>
7+
<iframe src="./python/index.html" onload="this.width=screen.width-50;this.height=(screen.height/2)-100;" style="float:left;"></iframe>
8+
<div style="clear:both; height:20px;"></div>
9+
<iframe src="./cpp/index.html" onload="this.width=screen.width-50;this.height=(screen.height/2)-100;"style="float:left;"></iframe>
10+
</div>
11+
12+
</body>
13+
</html>

gcovr.cfg

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# .gcovr.cfg to control gcovr
2+
root = bazel-bin/src
3+
filter = src
4+
5+
html-details = yes
6+
output = coverage_report/cpp/index.html

0 commit comments

Comments
 (0)