Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[run]
branch = True
parallel = False
source =
src

[report]
show_missing = True
skip_covered = False
exclude_lines =
pragma: no cover
if __name__ == .__main__.:
# Add project-specific exclusions as needed

omit =
tests/*
**/__init__.py

[html]
directory = htmlcov
84 changes: 84 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: Code Coverage

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

permissions:
contents: read

jobs:
test:
runs-on: ubuntu-latest
env:
# Probably unnecessary, if we install the code as a package
PYTHONPATH: src
# Set your thresholds here
OVERALL_COVERAGE_FAIL_UNDER: "60"
DIFF_COVER_FAIL_UNDER: "70"
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # needed for diff-cover to compare against main

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: "pip"

- name: Install test deps
run: |
python -m pip install --upgrade pip
pip install coverage diff-cover

- name: Prepare for tests
run: sh prepare_for_tests.sh

- name: Run unit tests with coverage
run: |
pip install -e ".[dev]"
coverage run --rcfile=.coveragerc --source=src -m unittest discover tests
coverage report -m --fail-under="${OVERALL_COVERAGE_FAIL_UNDER}"
coverage xml -o coverage.xml
coverage html -d htmlcov

- name: Diff coverage for PR changes
if: ${{ github.event_name == 'pull_request' }}
run: |
# Ensure main is available for comparison
git fetch origin main:refs/remotes/origin/main

# Compute coverage on changed lines only and fail if under threshold
diff-cover coverage.xml \
--compare-branch=origin/main \
--fail-under="${DIFF_COVER_FAIL_UNDER}" \
--html-report diffcov.html > diffcov.txt || RC=$?

# Attach a concise summary to the job summary
{
echo "## Diff Coverage Summary"
echo ""
echo "\`diff-cover --fail-under=${DIFF_COVER_FAIL_UNDER}\` against origin/main"
echo ""
echo '```'
cat diffcov.txt
echo '```'
} >> "$GITHUB_STEP_SUMMARY"

# Exit with diff-cover status if it failed
exit ${RC:-0}

- name: Upload HTML reports
if: always()
uses: actions/upload-artifact@v4
with:
name: coverage-reports
path: |
htmlcov/
diffcov.html
coverage.xml
if-no-files-found: ignore
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ target
build
dist
gen
.coverage
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ This library is released under the Apache V2 License.

Read the [Documentation](https://lionweb.io/lionweb-python)

We support Python 3.9 to 3.13

## Linting

```
Expand Down Expand Up @@ -47,4 +49,15 @@ twine upload dist/*
```
sh prepare_for_tests.sh # to be run just once
PYTHONPATH=src python -m unittest discover tests
```

You can measure coverage like this:
```
PYTHONPATH=src coverage run -m unittest discover tests
```

And then generate a report with:
```
coverage html
# report generated under htmlcov/index.html
```
12 changes: 10 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,16 @@ description = "A Python package for working with LionWeb"
readme = "README.md"
authors = [{ name = "Federico Tomassetti", email = "[email protected]" }]
license = { file = "LICENSE.txt" }
requires-python = ">=3.8"
requires-python = ">=3.9"
dependencies = [
"requests",
"pydantic"
"pydantic",
"typing_extensions>=4.8",
]

[project.optional-dependencies]
dev = [
"coverage",
"diff-cover",
"testcontainers>=4.0",
]
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ certifi==2025.1.31
cfgv==3.4.0
charset-normalizer==3.4.1
click==8.1.8
coverage==7.10.6
decorator==5.2.1
distlib==0.3.9
distro==1.9.0
Expand Down Expand Up @@ -47,6 +48,7 @@ mypy==1.15.0
mypy-extensions==1.0.0
nh3==0.2.20
nodeenv==1.9.1
numpy==2.0.2
packaging==24.2
parso==0.8.4
pathspec==0.12.1
Expand Down
2 changes: 1 addition & 1 deletion tests/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM node
ARG lionwebServerCommitId=64aeb0de69bbb39626e7f107ba26eb0061063c9c
ARG lionwebServerCommitId=e6549d62a4728a91e1ca31afb9b5341b47b88c99
RUN mkdir lionweb-server
WORKDIR lionweb-server
RUN git init
Expand Down