Skip to content

Commit 148fcc9

Browse files
authored
Explore test coverage (#1281)
* wip use latest wk docker version for update cassettes by default and add coverage. * use uv cache also for test.sh * restore uv cache for python version. * coverage only for py311 * typo. * coverage report. * Update workflow. * Update workflow. * Update workflow. * Update workflow. * Update workflow. * Update workflow. * Update ci workflow. * move logic for fetching latest webknossos version from nightly to test * Update ci. * Update ci. * update ci. * Update ci. * Update ci. * Update ci. * Update ci. * Update ci. * Update ci. * implement requested changes. * use gh actions coverage. * Change working dir. * Update ci. * debuf download artifacts. * Update ci. * Update ci. * Update ci. * remove debug ci step. * Add thresholds.
1 parent db95d6d commit 148fcc9

File tree

5 files changed

+146
-13
lines changed

5 files changed

+146
-13
lines changed

.github/workflows/ci.yml

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ jobs:
180180

181181
- name: Set up Python ${{ matrix.python-version }}
182182
run: uv python install ${{ matrix.python-version }}
183-
183+
184184
- name: Check formatting
185185
if: ${{ matrix.group == 1 && matrix.python-version == '3.11' }}
186186
run: ./format.sh check
@@ -198,17 +198,70 @@ jobs:
198198
sed -i '/def _launch/a\ \ \ \ \ \ \ \ raise Exception("fork is not allowed.")' /home/runner/.local/share/uv/python/cpython-${{ matrix.python-version }}.*-linux-x86_64-gnu/lib/python${{ matrix.python-version }}/multiprocessing/popen_fork.py
199199
cat /home/runner/.local/share/uv/python/cpython-${{ matrix.python-version }}.*-linux-x86_64-gnu/lib/python${{ matrix.python-version }}/multiprocessing/popen_fork.py
200200
201+
- name: Python tests (with coverage)
202+
if: ${{ matrix.python-version == '3.11' }}
203+
timeout-minutes: 30
204+
env:
205+
PYTHON_VERSION: ${{ matrix.python-version }}
206+
COVERAGE_FILE: "~/.local/share/coverage/${{ matrix.group }}.coverage"
207+
run: ./test.sh --splits 3 --group ${{ matrix.group }} --splitting-algorithm least_duration --cov=webknossos --cov-report=
208+
201209
- name: Python tests
210+
if: ${{ matrix.python-version != '3.11' }}
202211
timeout-minutes: 30
203212
env:
204213
PYTHON_VERSION: ${{ matrix.python-version }}
205214
run: ./test.sh --splits 3 --group ${{ matrix.group }} --splitting-algorithm least_duration
206215

216+
- name: Persist coverage reports
217+
if: ${{ matrix.python-version == '3.11' }}
218+
uses: actions/upload-artifact@v4
219+
with:
220+
name: coverage-report-${{ matrix.group }}
221+
path: "~/.local/share/coverage/${{ matrix.group }}.coverage"
222+
retention-days: 1 # Automatically deletes after 1 day
223+
207224
- name: Check if git is dirty
208225
run: |
209226
git diff --no-ext-diff --exit-code
210227
[[ -z $(git status -s) ]]
211228
229+
coverage_report:
230+
needs: [webknossos_linux]
231+
if: success()
232+
runs-on: ubuntu-latest
233+
defaults:
234+
run:
235+
working-directory: webknossos
236+
steps:
237+
- uses: actions/checkout@v3
238+
239+
- name: Install coverage.py
240+
run: pip install coverage
241+
242+
- name: Download all coverage reports
243+
uses: actions/download-artifact@v4
244+
with:
245+
path: ~/coverage-files
246+
247+
- name: Generate coverage report
248+
env:
249+
COVERAGE_FILE: "~/coverage-files/result.coverage"
250+
run: |
251+
coverage combine ~/coverage-files/**/*.coverage
252+
coverage xml -i -o ~/coverage-files/result.xml
253+
254+
- name: Report coverage
255+
uses: orgoro/[email protected]
256+
with:
257+
coverageFile: /home/runner/coverage-files/result.xml
258+
token: ${{ secrets.GITHUB_TOKEN }}
259+
thresholdAll: 0.8
260+
thresholdNew: 0.8
261+
262+
- name: Cleanup temporary files
263+
run: rm -rf ~/coverage-files
264+
212265
webknossos_cli_docker:
213266
needs: [cluster_tools, webknossos_linux]
214267
if: |

.github/workflows/nightly.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ jobs:
3737
git diff --no-ext-diff --quiet --exit-code
3838
[[ -z $(git status -s) ]]
3939
40-
- name: Use currently deployed Webknossos version
41-
run: |
42-
sed -i "s/export DOCKER_TAG=.*$/export DOCKER_TAG=master__$(curl https://webknossos.org/api/buildinfo | jq -r .webknossos.version)/" local_wk_setup.sh
43-
4440
- name: Python tests, refreshing the network snapshots
4541
env:
4642
WK_TOKEN: ${{ secrets.WK_TOKEN }}

webknossos/local_wk_setup.sh

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
function export_vars {
2+
# Fetch current version of webknossos.org this can be replaced with a fixed version for testing
3+
WK_VERSION=$(curl -s https://webknossos.org/api/buildinfo | jq -r '.webknossos.version')
4+
5+
# Export the necessary environment variables
26
export WK_TOKEN=1b88db86331a38c21a0b235794b9e459856490d70408bcffb767f64ade0f83d2bdb4c4e181b9a9a30cdece7cb7c65208cc43b6c1bb5987f5ece00d348b1a905502a266f8fc64f0371cd6559393d72e031d0c2d0cabad58cccf957bb258bc86f05b5dc3d4fff3d5e3d9c0389a6027d861a21e78e3222fb6c5b7944520ef21761e
37
export WK_URL=http://localhost:9000
4-
export DOCKER_TAG=master__32090
8+
export DOCKER_TAG="master__${WK_VERSION}"
59
}
610

711
function ensure_local_test_wk {
@@ -54,13 +58,6 @@ function ensure_local_test_wk {
5458
fi
5559

5660
curl -s -X POST -H "X-Auth-Token: $WK_TOKEN" localhost:9000/data/triggers/checkInboxBlocking
57-
58-
WK_ORG_VERSION="$(curl -s https://webknossos.org/api/buildinfo | tr ',"' "\n" | sed -n '/version/{n;n;p;q;}')"
59-
LOCAL_VERSION="$(curl -s http://localhost:9000/api/buildinfo | tr ',"' "\n" | sed -n '/version/{n;n;p;q;}')"
60-
61-
if [ "$WK_ORG_VERSION" != "$LOCAL_VERSION" ]; then
62-
echo "The local webknossos version is $LOCAL_VERSION, differing from the webknossos.org version $WK_ORG_VERSION"
63-
fi
6461
}
6562

6663

webknossos/pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,15 @@ all = [
8888
[tool.uv]
8989
extra-index-url = ["https://pypi.scm.io/simple"]
9090
dev-dependencies = [
91+
"coverage>=7.8.0",
9192
"fsspec ~=2024.6.0",
9293
"hypothesis ~=6.35.0",
9394
"icecream ~=2.1.1",
9495
"inducoapi ~=2.0.2",
9596
"jsonschema ~=4.6.0",
9697
"mypy ~=1.15.0",
9798
"pytest ~=8.3.2",
99+
"pytest-cov>=6.0.0",
98100
"pytest-custom-exit-code ~=0.3.0",
99101
"pytest-split ~=0.10.0",
100102
"pytest-sugar ~=1.0.0",

0 commit comments

Comments
 (0)