diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index febdfe2..39cce68 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,7 +24,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install flake8 black pytest + pip install -r time_based_storage/requirements-dev.txt cd time_based_storage && pip install -e . - name: Check code formatting with black @@ -38,6 +38,19 @@ jobs: flake8 time_based_storage/src --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics flake8 time_based_storage/tests --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - - name: Run tests + - name: Run tests with coverage run: | - cd time_based_storage && python -m pytest tests/ -v \ No newline at end of file + cd time_based_storage && python -m pytest tests/ -v --cov=src/time_based_storage --cov-report=xml + + - name: Upload coverage reports to Codecov + uses: codecov/codecov-action@v5 + with: + token: ${{ secrets.CODECOV_TOKEN }} + slug: johnburbridge/python-time-based-experiment + + - name: Upload test results to Codecov + if: ${{ !cancelled() }} + uses: codecov/test-results-action@v1 + with: + token: ${{ secrets.CODECOV_TOKEN }} + diff --git a/README.md b/README.md index 75e7d4b..d35eb61 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # Time-Based Storage System [![CI](https://github.com/johnburbridge/python-time-based-experiment/actions/workflows/ci.yml/badge.svg)](https://github.com/johnburbridge/python-time-based-experiment/actions/workflows/ci.yml) +[![codecov](https://codecov.io/gh/johnburbridge/python-time-based-experiment/branch/main/graph/badge.svg)](https://codecov.io/gh/johnburbridge/python-time-based-experiment) A Python package providing two implementations of a time-based storage system for managing events with timestamps. This library is useful for applications that need to efficiently store and query time-based data, such as event logs, time series data, monitoring systems, and schedulers. @@ -180,6 +181,15 @@ cd time_based_storage python -m pytest tests/ -v ``` +Run tests with code coverage: + +```bash +cd time_based_storage +python -m pytest tests/ -v --cov=src/time_based_storage --cov-report=html +``` + +This will generate an HTML coverage report in the `htmlcov` directory. + ## Development ### Setup Development Environment @@ -190,7 +200,7 @@ cd python-time-based-experiment python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate pip install -e time_based_storage/ -pip install pytest black flake8 +pip install -r time_based_storage/requirements-dev.txt ``` ### Code Style diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000..734ef55 --- /dev/null +++ b/codecov.yml @@ -0,0 +1,29 @@ +codecov: + require_ci_to_pass: true + +coverage: + precision: 2 + round: down + range: "70...100" + status: + project: + default: + target: 80% + threshold: 2% + patch: + default: + target: 80% + threshold: 2% + +parsers: + gcov: + branch_detection: + conditional: true + loop: true + method: false + macro: false + +comment: + layout: "reach,diff,flags,files,footer" + behavior: default + require_changes: false diff --git a/time_based_storage/pyproject.toml b/time_based_storage/pyproject.toml index 9b9309c..686cde7 100644 --- a/time_based_storage/pyproject.toml +++ b/time_based_storage/pyproject.toml @@ -27,4 +27,18 @@ extend-exclude = ''' [tool.pytest.ini_options] testpaths = ["tests"] python_files = ["test_*.py"] -addopts = "-v" \ No newline at end of file +addopts = "-v" + +[tool.coverage.run] +source = ["src/time_based_storage"] +omit = ["tests/*"] + +[tool.coverage.report] +exclude_lines = [ + "pragma: no cover", + "def __repr__", + "raise NotImplementedError", + "if __name__ == .__main__.:", + "pass", + "raise ImportError", +] \ No newline at end of file diff --git a/time_based_storage/requirements-dev.txt b/time_based_storage/requirements-dev.txt new file mode 100644 index 0000000..955a846 --- /dev/null +++ b/time_based_storage/requirements-dev.txt @@ -0,0 +1,5 @@ +pytest>=7.0.0 +black>=23.0.0 +flake8>=6.0.0 +pytest-cov>=4.0.0 +codecov>=2.1.12 \ No newline at end of file