From ce92652ece6098d8cd228ad4fb3e0f1d89b4a181 Mon Sep 17 00:00:00 2001 From: Mohamed Nasser Date: Mon, 16 Sep 2024 15:06:43 +0300 Subject: [PATCH 1/7] Added code coverage workflow --- .github/workflows/test-coverage.yaml | 41 +++ coverage.xml | 366 +++++++++++++++++++++++++++ poetry.lock | 2 +- pyproject.toml | 2 + 4 files changed, 410 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/test-coverage.yaml create mode 100644 coverage.xml diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml new file mode 100644 index 0000000..8634ded --- /dev/null +++ b/.github/workflows/test-coverage.yaml @@ -0,0 +1,41 @@ +name: Test Coverage + +on: + push + pull_request + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - name: Check out repository code + uses: actions/checkout@v3 + + - name: Install Python 3.10 + uses: actions/setup-python@v4 + with: + python-version: '3.10' + + - name: Install Poetry + uses: Gr1N/setup-poetry@v8 + with: + poetry-version: '1.8.3' + + - name: Install dependencies + run: poetry install + + - name: Run tests coverage + run: | + poetry run pytest + poetry run coverage report + poetry run coverage xml + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} + file: coverage.xml + flags: unittests + name: codecov-umbrella + fail_ci_if_error: true diff --git a/coverage.xml b/coverage.xml new file mode 100644 index 0000000..fe4d210 --- /dev/null +++ b/coverage.xml @@ -0,0 +1,366 @@ + + + + + + C:\opensource\OSIPI\pypi + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/poetry.lock b/poetry.lock index 8056b5a..ca4c254 100644 --- a/poetry.lock +++ b/poetry.lock @@ -2522,4 +2522,4 @@ type = ["pytest-mypy"] [metadata] lock-version = "2.0" python-versions = "^3.9" -content-hash = "608e89b569d110e0ca49063cde4d915ed83b59b633806f5190f219f5218ed69c" +content-hash = "0c11643e5fa1754a4ac302b0313336b90a8f81181cffbb55fa2e27b8e099ada1" diff --git a/pyproject.toml b/pyproject.toml index ed0db06..a91ce00 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -58,6 +58,8 @@ matplotlib = "3.9.0" requests = "^2.32.3" semantic-version = "^2.10.0" toml = "^0.10.2" +coverage = "^7.6.1" +pytest-cov = "^5.0.0" [tool.setuptools.packages.find] where = [ "src",] From bf1a876af4793ed7ee6ef42c64d3e719bcd6a25a Mon Sep 17 00:00:00 2001 From: Mohamed Nasser Date: Mon, 16 Sep 2024 15:08:07 +0300 Subject: [PATCH 2/7] Update test-coverage.yaml --- .github/workflows/test-coverage.yaml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml index 8634ded..ff93506 100644 --- a/.github/workflows/test-coverage.yaml +++ b/.github/workflows/test-coverage.yaml @@ -1,8 +1,6 @@ name: Test Coverage -on: - push - pull_request +on: [push, pull_request] jobs: test: From 0b9dd17cfca12d9ec5c2e3ff01c761ea96623481 Mon Sep 17 00:00:00 2001 From: Mohamed Nasser Date: Mon, 16 Sep 2024 15:19:44 +0300 Subject: [PATCH 3/7] correct command --- .github/workflows/test-coverage.yaml | 2 +- coverage.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml index ff93506..b6fb029 100644 --- a/.github/workflows/test-coverage.yaml +++ b/.github/workflows/test-coverage.yaml @@ -25,7 +25,7 @@ jobs: - name: Run tests coverage run: | - poetry run pytest + poetry run coverage run -m pytest poetry run coverage report poetry run coverage xml diff --git a/coverage.xml b/coverage.xml index fe4d210..9ec597d 100644 --- a/coverage.xml +++ b/coverage.xml @@ -1,5 +1,5 @@ - + From ba8c37dc9327d1e5869cb83105bea78a6aed1682 Mon Sep 17 00:00:00 2001 From: Mohamed Nasser Date: Tue, 1 Oct 2024 20:14:24 +0300 Subject: [PATCH 4/7] Added check coverage as a pre_commit-hook --- .github/workflows/test-coverage.yaml | 39 --- .pre-commit-config.yaml | 8 + check_coverage.py | 19 ++ coverage.xml | 366 --------------------------- pyproject.toml | 7 + 5 files changed, 34 insertions(+), 405 deletions(-) delete mode 100644 .github/workflows/test-coverage.yaml create mode 100644 check_coverage.py delete mode 100644 coverage.xml diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml deleted file mode 100644 index b6fb029..0000000 --- a/.github/workflows/test-coverage.yaml +++ /dev/null @@ -1,39 +0,0 @@ -name: Test Coverage - -on: [push, pull_request] - -jobs: - test: - runs-on: ubuntu-latest - - steps: - - name: Check out repository code - uses: actions/checkout@v3 - - - name: Install Python 3.10 - uses: actions/setup-python@v4 - with: - python-version: '3.10' - - - name: Install Poetry - uses: Gr1N/setup-poetry@v8 - with: - poetry-version: '1.8.3' - - - name: Install dependencies - run: poetry install - - - name: Run tests coverage - run: | - poetry run coverage run -m pytest - poetry run coverage report - poetry run coverage xml - - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v4 - with: - token: ${{ secrets.CODECOV_TOKEN }} - file: coverage.xml - flags: unittests - name: codecov-umbrella - fail_ci_if_error: true diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4a2ca8a..5104b17 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -11,3 +11,11 @@ repos: - id: trailing-whitespace - id: end-of-file-fixer - id: check-yaml + + - repo: local + hooks: + - id: custom-script-py + name: Check Coverage + entry: poetry run python check_coverage.py + language: system + pass_filenames: false diff --git a/check_coverage.py b/check_coverage.py new file mode 100644 index 0000000..24f7dac --- /dev/null +++ b/check_coverage.py @@ -0,0 +1,19 @@ +import subprocess +import sys + + +def run_coverage(): + try: + # Run tests with coverage + subprocess.run(["poetry", "run", "coverage", "run", "-m", "pytest"], check=True) + # Generate coverage report and check threshold + subprocess.run(["poetry", "run", "coverage", "report", "--fail-under=95"], check=True) + except subprocess.CalledProcessError as e: + print(f"Coverage check failed: {e}") + sys.exit(1) + + +if __name__ == "__main__": + print("Running coverage check...") + run_coverage() + print("Coverage check passed.") diff --git a/coverage.xml b/coverage.xml deleted file mode 100644 index 9ec597d..0000000 --- a/coverage.xml +++ /dev/null @@ -1,366 +0,0 @@ - - - - - - C:\opensource\OSIPI\pypi - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/pyproject.toml b/pyproject.toml index a91ce00..47e5d66 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -50,6 +50,11 @@ line-ending = "auto" docstring-code-format = true docstring-code-line-length = 100 +[tool.coverage.run] +omit = [ + "tests/*" +] + [tool.poetry.dependencies] python = "^3.9" numpy = "^1.21.2" @@ -61,6 +66,8 @@ toml = "^0.10.2" coverage = "^7.6.1" pytest-cov = "^5.0.0" + + [tool.setuptools.packages.find] where = [ "src",] From 8b0a45c3790c1c1b37b2ba8dddd2a3802e8ef882 Mon Sep 17 00:00:00 2001 From: Mohamed Nasser Date: Tue, 1 Oct 2024 21:45:10 +0300 Subject: [PATCH 5/7] mark hook as check only --- .pre-commit-config.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5104b17..fe2018b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -19,3 +19,5 @@ repos: entry: poetry run python check_coverage.py language: system pass_filenames: false + args: + - --check From eb7f93fc02427c50ac273d4693efc0c5df2ee792 Mon Sep 17 00:00:00 2001 From: Mohamed Nasser Date: Tue, 1 Oct 2024 21:48:12 +0300 Subject: [PATCH 6/7] mark it as fix --- .pre-commit-config.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fe2018b..54fe615 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -19,5 +19,4 @@ repos: entry: poetry run python check_coverage.py language: system pass_filenames: false - args: - - --check + args: [--fix] From 75eb77176c215712503ddf0e3f24cc3b82abbc91 Mon Sep 17 00:00:00 2001 From: Mohamed Nasser Date: Sat, 5 Oct 2024 02:24:58 +0300 Subject: [PATCH 7/7] Update check_coverage.py --- check_coverage.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/check_coverage.py b/check_coverage.py index 24f7dac..e7b3dad 100644 --- a/check_coverage.py +++ b/check_coverage.py @@ -1,5 +1,4 @@ import subprocess -import sys def run_coverage(): @@ -10,10 +9,3 @@ def run_coverage(): subprocess.run(["poetry", "run", "coverage", "report", "--fail-under=95"], check=True) except subprocess.CalledProcessError as e: print(f"Coverage check failed: {e}") - sys.exit(1) - - -if __name__ == "__main__": - print("Running coverage check...") - run_coverage() - print("Coverage check passed.")