Skip to content

Commit 48f7143

Browse files
authored
test+build: adds test coverage and step in actions to comment on pull requests with coverage. (#219)
1 parent d843da5 commit 48f7143

File tree

7 files changed

+42
-7
lines changed

7 files changed

+42
-7
lines changed

.github/workflows/check_n_push_image.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ jobs:
6464
make docker-image DOCKER_TAG=${{ secrets.DOCKER_HUB_USERNAME }}/codeplag-ubuntu22.04:${{ steps.get_version.outputs.version }}
6565
docker image save --output /tmp/codeplag-ubuntu22.04.tar ${{ secrets.DOCKER_HUB_USERNAME }}/codeplag-ubuntu22.04:${{ steps.get_version.outputs.version }}
6666
67+
- name: Pytest coverage comment
68+
uses: MishaKav/pytest-coverage-comment@v1
69+
with:
70+
pytest-xml-coverage-path: ./test/unit/pytest-coverage.xml
71+
6772
- name: Run autotests
6873
run: |
6974
export $(cat .env | xargs)

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
# Environment variables
55
.env
66

7-
# Developmnt environmemt
7+
# Development and environment
88
.vscode
99
.python-version
1010
docs/notebooks/.ipynb_checkpoints/
11+
test/unit/pytest-coverage.xml
1112

1213
# Build
1314
__pycache__

Makefile

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
UTIL_VERSION := 0.5.14
1+
UTIL_VERSION := 0.5.15
22
UTIL_NAME := codeplag
33
PWD := $(shell pwd)
44

@@ -33,6 +33,7 @@ DOCKER_SUB_FILES := docker/base_ubuntu2204.dockerfile \
3333

3434
PYTHON_REQUIRED_LIBS := $(shell python3 setup.py --install-requirements)
3535
PYTHON_BUILD_LIBS := $(shell python3 setup.py --build-requirements)
36+
PYTHON_TEST_LIBS := $(shell python3 setup.py --test-requirements)
3637

3738

3839
ifeq ($(IS_DEVELOPED), 1)
@@ -49,6 +50,7 @@ substitute = @sed \
4950
-e "s|@DEVEL_SUFFIX@|${DEVEL_SUFFIX}|g" \
5051
-e "s|@PYTHON_REQUIRED_LIBS@|${PYTHON_REQUIRED_LIBS}|g" \
5152
-e "s|@PYTHON_BUILD_LIBS@|${PYTHON_BUILD_LIBS}|g" \
53+
-e "s|@PYTHON_TEST_LIBS@|${PYTHON_TEST_LIBS}|g" \
5254
-e "s|@LOGS_PATH@|${LOGS_PATH}|g" \
5355
-e "s|@LIB_PATH@|${LIB_PATH}|g" \
5456
-e "s|@CONFIG_PATH@|${CONFIG_PATH}|g" \
@@ -127,12 +129,11 @@ package: substitute-debian
127129
)
128130

129131
test: substitute-sources
130-
pytest test/unit -vv
131-
pytest test/misc -vv
132+
pytest test/unit test/misc --cov=src/ --cov-report xml --cov-report term
132133
make clean-cache
133134

134135
autotest:
135-
pytest test/auto -vv
136+
pytest test/auto
136137
make clean-cache
137138

138139
pre-commit:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103

104104
- Testing for analyzers with pytest lib (required preinstalled pytest framework).
105105
```
106-
$ pip3 install pytest==8.3.4 pytest-mock==3.14.0
106+
$ pip3 install $(python3 setup.py --test-requirements)
107107
$ make test
108108
```
109109

docker/test_ubuntu2204.dockerfile.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ ENV DEBIAN_FRONTEND=noninteractive
44

55
RUN apt-get update
66
RUN apt-get install -y debhelper
7-
RUN pip3 install pytest==8.3.4 pytest-mock==3.14.0 @PYTHON_BUILD_LIBS@
7+
RUN pip3 install @PYTHON_TEST_LIBS@ @PYTHON_BUILD_LIBS@
88
RUN mkdir -p @LOGS_PATH@
99

1010
# TODO: Move to middle docker file or make another solution
1111
ADD setup.py /usr/src/@UTIL_NAME@/setup.py
12+
ADD pyproject.toml /usr/src/@UTIL_NAME@/pyproject.toml
1213
ADD src/ /usr/src/@UTIL_NAME@/src
1314
ADD README.md /usr/src/@UTIL_NAME@/README.md
1415
ADD LICENSE /usr/src/@UTIL_NAME@/LICENSE

pyproject.toml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,22 @@ typeCheckingMode = "basic"
5959

6060
[build-system]
6161
requires = ["setuptools", "Cython"]
62+
63+
[tool.coverage.run]
64+
branch = true
65+
66+
[tool.coverage.report]
67+
include_namespace_packages = true
68+
precision = 2
69+
70+
[tool.coverage.xml]
71+
output = "test/unit/pytest-coverage.xml"
72+
73+
[tool.pytest.ini_options]
74+
addopts = "-vv"
75+
python_files = ["test_*.py"]
76+
python_classes = ["Test*"]
77+
python_functions = ["test_*"]
78+
pythonpath = [
79+
"src",
80+
]

setup.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
"setuptools~=75.8.1",
1010
"Jinja2~=3.1.5",
1111
)
12+
TEST_REQUIREMENTS: tuple[str, ...] = (
13+
"pytest~=8.3.4",
14+
"pytest-mock~=3.14.0",
15+
"pytest-cov~=6.0.0",
16+
)
1217
INSTALL_REQUIREMENTS: tuple[str, ...] = (
1318
"argcomplete~=3.5.3",
1419
"numpy~=1.26.4",
@@ -32,6 +37,9 @@
3237
if "--build-requirements" in sys.argv:
3338
print(" ".join(BUILD_REQUIREMENTS))
3439
sys.exit(0)
40+
if "--test-requirements" in sys.argv:
41+
print(" ".join(TEST_REQUIREMENTS))
42+
sys.exit(0)
3543
elif "--install-requirements" in sys.argv:
3644
print(" ".join(INSTALL_REQUIREMENTS))
3745
sys.exit(0)

0 commit comments

Comments
 (0)