From df96ca4f3666ec6fd0ae05a1e0bb43073276353c Mon Sep 17 00:00:00 2001 From: Kevin van Zonneveld Date: Wed, 27 Nov 2024 13:02:07 +0100 Subject: [PATCH 1/6] Add comprehensive coverage reporting and thresholds --- .github/workflows/ci.yml | 66 ++++++++++++++++++++++++++++++++++++++-- README.md | 29 ++++++++++++++++++ pyproject.toml | 23 +++++++++++++- 3 files changed, 114 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bbab26f..89fea05 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,7 +8,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, windows-latest] - python-version: ["3.9", "3.10", "3.11", "3.12"] + python-version: ['3.9', '3.10', '3.11', '3.12'] steps: - uses: actions/checkout@v3 @@ -18,7 +18,7 @@ jobs: with: python-version: ${{ matrix.python-version }} architecture: x64 - cache: "pip" + cache: 'pip' - name: Install Poetry manager run: pip install --upgrade poetry @@ -28,4 +28,64 @@ jobs: - name: Test with pytest run: | - poetry run pytest --cov=transloadit tests + poetry run pytest --cov=transloadit \ + --cov-report=xml \ + --cov-report=term-missing \ + --cov-fail-under=65 \ + tests + + - name: Upload coverage reports + if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.12' + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} + files: ./coverage.xml + flags: unittests + name: python-sdk + fail_ci_if_error: true + + coverage: + needs: python + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.12' + architecture: x64 + cache: 'pip' + + - name: Install Poetry manager + run: pip install --upgrade poetry + + - name: Install Dependencies + run: poetry install + + - name: Generate coverage report + run: | + poetry run pytest --cov=transloadit \ + --cov-report=json \ + --cov-report=html \ + tests + + - name: Check coverage thresholds + run: | + COVERAGE=$(poetry run coverage report | grep TOTAL | awk '{print $4}' | sed 's/%//') + THRESHOLD=65 + + if (( $(echo "$COVERAGE < $THRESHOLD" | bc -l) )); then + echo "Coverage ($COVERAGE%) is below threshold ($THRESHOLD%)" + exit 1 + else + echo "Coverage ($COVERAGE%) meets threshold ($THRESHOLD%)" + fi + + - name: Upload coverage artifacts + uses: actions/upload-artifact@v4 + with: + name: coverage-reports + path: | + coverage.json + htmlcov/ diff --git a/README.md b/README.md index b10d3a4..53c5457 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ [![Build status](https://github.com/transloadit/python-sdk/actions/workflows/ci.yml/badge.svg)](https://github.com/transloadit/python-sdk/actions/workflows/ci.yml) +[![Coverage](https://codecov.io/gh/transloadit/python-sdk/branch/main/graph/badge.svg)](https://codecov.io/gh/transloadit/python-sdk) # Transloadit python-sdk @@ -42,3 +43,31 @@ For fully working examples, take a look at [`examples/`](https://github.com/tran ## Documentation See [readthedocs](https://transloadit.readthedocs.io) for full API documentation. + +## Development + +### Testing + +Run tests with: + +```bash +poetry run pytest +``` + +### Code Coverage + +We maintain code coverage to ensure reliability. The current minimum coverage threshold is 65%. + +Coverage reports are: + +- Generated locally in the `htmlcov` directory +- Uploaded to Codecov for tracking +- Enforced in CI (builds will fail if coverage drops below threshold) + +View the coverage report locally by opening `htmlcov/index.html` in your browser. + +Generate a coverage report with: + +```bash +poetry run pytest --cov=transloadit --cov-report=html tests +``` diff --git a/pyproject.toml b/pyproject.toml index b44923c..99d051d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [tool.poetry] name = "pytransloadit" version = "1.0.0" -description = "A Python Integration for Transloadit’s file uploading and encoding service." +description = "A Python Integration for Transloadit's file uploading and encoding service." authors = ["Ifedapo Olarewaju"] maintainers = ["Florian Kuenzig", "Arnaud Limbourg"] license = "MIT" @@ -44,3 +44,24 @@ sphinx-autobuild = "^2021.3.14" [build-system] requires = ["poetry-core"] build-backend = "poetry.core.masonry.api" + +[tool.pytest.ini_options] +addopts = "--cov=transloadit --cov-report=term-missing" +testpaths = ["tests"] + +[tool.coverage.run] +source = ["transloadit"] +branch = true + +[tool.coverage.report] +exclude_lines = [ + "pragma: no cover", + "def __repr__", + "if self.debug:", + "raise NotImplementedError", + "if __name__ == .__main__.:", + "pass", + "raise ImportError", +] +ignore_errors = true +fail_under = 65 From f57d9a5084e97305d422add9e672be782b8af88a Mon Sep 17 00:00:00 2001 From: Kevin van Zonneveld Date: Wed, 27 Nov 2024 13:07:20 +0100 Subject: [PATCH 2/6] Update ci.yml --- .github/workflows/ci.yml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 89fea05..a711890 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,7 +20,14 @@ jobs: architecture: x64 cache: 'pip' - - name: Install Poetry manager + - name: Install Poetry (Windows) + if: runner.os == 'Windows' + run: | + (Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | python - + echo "$HOME\AppData\Roaming\Python\Scripts" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append + + - name: Install Poetry (Unix) + if: runner.os != 'Windows' run: pip install --upgrade poetry - name: Install Dependencies @@ -57,7 +64,7 @@ jobs: architecture: x64 cache: 'pip' - - name: Install Poetry manager + - name: Install Poetry run: pip install --upgrade poetry - name: Install Dependencies From b911654308189d3a03310e7539141b7bc351c777 Mon Sep 17 00:00:00 2001 From: Kevin van Zonneveld Date: Wed, 27 Nov 2024 13:10:14 +0100 Subject: [PATCH 3/6] Update ci.yml --- .github/workflows/ci.yml | 48 ++++++++-------------------------------- 1 file changed, 9 insertions(+), 39 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a711890..b03d992 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,14 +33,21 @@ jobs: - name: Install Dependencies run: poetry install - - name: Test with pytest + - name: Test with coverage + if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.12' run: | poetry run pytest --cov=transloadit \ --cov-report=xml \ + --cov-report=json \ + --cov-report=html \ --cov-report=term-missing \ --cov-fail-under=65 \ tests + - name: Test without coverage + if: matrix.os != 'ubuntu-latest' || matrix.python-version != '3.12' + run: poetry run pytest tests + - name: Upload coverage reports if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.12' uses: codecov/codecov-action@v4 @@ -51,45 +58,8 @@ jobs: name: python-sdk fail_ci_if_error: true - coverage: - needs: python - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: '3.12' - architecture: x64 - cache: 'pip' - - - name: Install Poetry - run: pip install --upgrade poetry - - - name: Install Dependencies - run: poetry install - - - name: Generate coverage report - run: | - poetry run pytest --cov=transloadit \ - --cov-report=json \ - --cov-report=html \ - tests - - - name: Check coverage thresholds - run: | - COVERAGE=$(poetry run coverage report | grep TOTAL | awk '{print $4}' | sed 's/%//') - THRESHOLD=65 - - if (( $(echo "$COVERAGE < $THRESHOLD" | bc -l) )); then - echo "Coverage ($COVERAGE%) is below threshold ($THRESHOLD%)" - exit 1 - else - echo "Coverage ($COVERAGE%) meets threshold ($THRESHOLD%)" - fi - - name: Upload coverage artifacts + if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.12' uses: actions/upload-artifact@v4 with: name: coverage-reports From e5fc6e75edb6b00923dd212a9172b5e319795286 Mon Sep 17 00:00:00 2001 From: Kevin van Zonneveld Date: Thu, 28 Nov 2024 13:19:07 +0100 Subject: [PATCH 4/6] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9cc2662..b1bc7ea 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ For fully working examples, take a look at [`examples/`](https://github.com/tran See [readthedocs](https://transloadit.readthedocs.io) for full API documentation. -## Development +## Contributing ### Testing From dac9dc13334d17be2a092bb439fb15ccf81ef1b9 Mon Sep 17 00:00:00 2001 From: Kevin van Zonneveld Date: Thu, 28 Nov 2024 13:19:24 +0100 Subject: [PATCH 5/6] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b1bc7ea..56d8bce 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ See [readthedocs](https://transloadit.readthedocs.io) for full API documentation ## Contributing -### Testing +### Running tests If you have a global installation of `poetry`, you can run the tests with: From f7d2d5b46d2641c489df7d22b8f08693954fa979 Mon Sep 17 00:00:00 2001 From: Kevin van Zonneveld Date: Thu, 28 Nov 2024 13:19:42 +0100 Subject: [PATCH 6/6] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 56d8bce..4c9a243 100644 --- a/README.md +++ b/README.md @@ -72,4 +72,4 @@ Generate a coverage report with: poetry run pytest --cov=transloadit --cov-report=html tests ``` -Then iew the coverage report locally by opening `htmlcov/index.html` in your browser. \ No newline at end of file +Then view the coverage report locally by opening `htmlcov/index.html` in your browser. \ No newline at end of file