Skip to content

Commit 888314e

Browse files
chore: Ensure code has >= 90% coverage (#4)
* test: Fix pytest-cov collection warning * chore: Enforce 90% in pre-push hook * chore: Add linting to hooks and CI * chore: Ensure hooks and CI meet 90% coverage
1 parent 640b481 commit 888314e

File tree

7 files changed

+255
-17
lines changed

7 files changed

+255
-17
lines changed

.github/hooks/pre-commit

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
11
#!/bin/sh
22

33
formatting_results=$(poetry run black --check --line-length 100 . 2>&1 > /dev/null)
4+
if [[ "$?" == "0" ]]; then
5+
echo "✅ Formatting"
6+
else
7+
echo "❌ Formatting"
8+
echo "$formatting_results"
9+
exit 1
10+
fi
11+
12+
linting_results=$(poetry run pylint src tests)
413
if [[ "$?" == "0" ]]; then
514
echo "✅ Linting"
615
else
716
echo "❌ Linting"
8-
echo "$formatting_results"
17+
echo "$linting_results"
918
exit 1
1019
fi
1120

12-
unit_test_results=$(poetry run pytest --no-header --no-summary -qq tests/unit)
21+
unit_test_results=$(poetry run pytest --no-header --no-summary -qq tests/unit --cov-fail-under=90)
1322
if [[ "$?" == "0" ]]; then
1423
echo "✅ Unit Tests"
1524
else

.github/hooks/pre-push

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#!/bin/sh
22

3-
integration_test_results=$(poetry run pytest --no-header --no-summary -qq tests/integration)
3+
test_results=$(poetry run pytest --no-header -qq tests --cov-fail-under=90)
44
if [[ "$?" == "0" ]]; then
55
echo "✅ Integration Tests"
66
else
77
echo "❌ Integration Tests"
8-
echo "$integration_test_results"
8+
echo "$test_results"
99
exit 1
1010
fi

.github/workflows/ci.yml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Scan and Test Source Code
1+
name: Scan, Lint and Test Source Code
22

33
on:
44
workflow_dispatch:
@@ -29,7 +29,7 @@ jobs:
2929
with:
3030
sarif_file: snyk.sarif
3131

32-
pytest-run:
32+
code-check:
3333
runs-on: ubuntu-latest
3434

3535
steps:
@@ -47,8 +47,11 @@ jobs:
4747
- name: Install Python Dependencies
4848
run: poetry install
4949

50-
- name: Run Unit Tests
51-
run: poetry run pytest tests/unit
50+
- name: Check Formatting
51+
run: poetry run black --check --line-length 100 .
5252

53-
- name: Run Integration Tests
54-
run: poetry run pytest tests/integration
53+
- name: Lint Code
54+
run: poetry run pylint src tests
55+
56+
- name: Run Unit and Integration Tests
57+
run: poetry run pytest tests --cov-fail-under=90

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
</div>
1010

11+
[![linting: pylint](https://img.shields.io/badge/linting-pylint-yellowgreen)](https://github.com/pylint-dev/pylint)
12+
1113
## 🎧 Quick Start
1214

1315
Ensure [Python](https://www.python.org/downloads) and [Python Poetry](https://python-poetry.org/docs/#installation) are installed.
@@ -54,7 +56,7 @@ git config --local core.hooksPath .github/hooks/
5456
git config --local commit.template .github/.gitmessage
5557
```
5658

57-
These will ensure commit messages are consistent, code is correctly formatted, and tests before committing or pushing.
59+
These will ensure commit messages are consistent, code is correctly formatted and linted, and tests before committing or pushing.
5860

5961
Style decisions are based on the [Google Python Style Guide](https://google.github.io/styleguide/pyguide.html).
6062

poetry.lock

Lines changed: 222 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,18 @@ pytest-cov = "^4.1.0"
2929

3030
[tool.poetry.group.dev.dependencies]
3131
black = "^23.9.1"
32+
pylint = "^2.17.5"
3233

3334
[tool.black]
3435
line-length = 100
3536

37+
[tool.pylint.main]
38+
score = "n"
39+
no-docstring-rgx = "^_|^test_"
40+
41+
[tool.pylint."messages control"]
42+
disable = ["missing-module-docstring"]
43+
3644
[tool.pytest.ini_options]
3745
minversion = "7.4.0"
3846
pythonpath = "src"

src/package_name/cli.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
"""Serves as the main entrypoint for the package-name CLI tool.
2-
3-
Package description.
4-
"""
5-
61
import argparse
72

83

0 commit comments

Comments
 (0)