Skip to content

Commit 3e768d4

Browse files
authored
test coverage badge Feature/test pytest coverage (#97)
* ✨ chore: Update README and GitHub Actions for pytest coverage reporting - Added pytest coverage reporting to the GitHub Actions workflow, including output to a text file and JUnit XML. - Updated README.md to include a placeholder for pytest coverage comments, which will be dynamically populated by the workflow. - Integrated a step to commit changes to README.md after coverage updates, ensuring documentation stays current. * ✨ chore: Fix indentation in GitHub Actions workflow for README update step - Corrected the indentation for the "Update README" step in the lint-and-test workflow to ensure proper execution. - This change enhances the clarity and functionality of the workflow, maintaining accurate coverage reporting in the README.md. * docs: update coverage badge * ✨ chore: Update GitHub Actions workflow and .gitignore for pytest coverage - Adjusted the path for pytest coverage output in the GitHub Actions workflow to ensure correct file location. - Added pytest coverage output files to .gitignore to prevent unnecessary tracking in the repository. * ✨ chore: Update README and GitHub Actions for pytest coverage paths - Removed unnecessary line from README.md. - Adjusted paths for pytest coverage output and JUnit XML in the GitHub Actions workflow to reflect the correct directory structure. * docs: update coverage badge * ✨ chore: Update GitHub Actions to use pytest-coverage-comment action - Replaced the manual README update step with the pytest-coverage-comment action for automated coverage reporting. - Streamlined the workflow by removing unnecessary commit steps, enhancing efficiency in coverage updates. * ✨ chore: Update GitHub Actions workflow for pytest coverage reporting - Adjusted paths for pytest coverage output and JUnit XML to reflect the correct directory structure. - Added a step to update the README.md with the latest coverage information and commit the changes automatically. * ✨ chore: Add coverage step ID in GitHub Actions workflow - Introduced an ID for the pytest coverage comment step to facilitate future reference and enhancements in the workflow. - This change improves the clarity and maintainability of the GitHub Actions configuration. * docs: update coverage badge * ✨ chore: Update README and backend README for pytest coverage reporting - Added placeholders for pytest coverage comments in both README.md and backend/README.md. - Adjusted the GitHub Actions workflow to update the backend README with the latest coverage information, ensuring accurate documentation. * ✨ chore: Enhance pytest coverage reporting in GitHub Actions workflow - Updated the pytest command to generate an XML coverage report, improving the coverage data output. - Modified the coverage comment step to reference the new XML coverage report, ensuring accurate integration with the coverage comment action. * Revert "✨ chore: Enhance pytest coverage reporting in GitHub Actions workflow" This reverts commit 054c08b. * ✨ chore: Refactor GitHub Actions workflow for pytest execution - Simplified the pytest command in the workflow by removing the `cd` command and using the `working-directory` attribute. - Enhanced readability of the pytest command by formatting it across multiple lines, improving maintainability. * ✨ chore: Update file pattern for coverage badge in GitHub Actions workflow - Changed the file pattern from README.md to backend/README.md to ensure the correct README is updated with the latest coverage information. * docs: update coverage badge * ✨ chore: Add coverage path prefix in GitHub Actions workflow - Introduced a coverage path prefix for the pytest coverage report to ensure accurate path resolution in the generated reports. * docs: update coverage badge * ✨ chore: Fix coverage path prefix in GitHub Actions workflow - Updated the coverage path prefix to include a trailing slash for accurate path resolution in the pytest coverage report. * docs: update coverage badge * feat: refactor linters & run configs * feat: linter code * feat: change debugpy config * feat: delete useless files * refactor: refactor mts tests name * feat: update mypy dep, config * feat: bump version of project * fix: fix conflicts * feat: refactor lms tests, conftest and handlers * refactor: handlers.py * feat: add new route for lms * feat: add few tests for bulk
1 parent 9d42ae3 commit 3e768d4

33 files changed

Lines changed: 1932 additions & 234 deletions

.github/workflows/lint-and-test.yaml

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,29 @@ jobs:
4444
uv run mypy --config-file=pyproject.toml yet_another_calendar
4545
4646
- name: Run tests
47+
working-directory: backend
4748
run: |
48-
cd backend
49-
YET_ANOTHER_CALENDAR_TUTOR_SECRET_KEY='test' uv run pytest --cov-fail-under=80 --cov=yet_another_calendar/web yet_another_calendar/tests/*
49+
YET_ANOTHER_CALENDAR_TUTOR_SECRET_KEY='test' \
50+
uv run pytest --junitxml=../pytest.xml \
51+
--cov-report=term-missing:skip-covered \
52+
--cov-fail-under=80 \
53+
--cov=yet_another_calendar/web \
54+
yet_another_calendar/tests/* | tee ../pytest-coverage.txt
55+
56+
- name: Pytest coverage comment
57+
id: coverage
58+
uses: MishaKav/pytest-coverage-comment@main
59+
with:
60+
pytest-coverage-path: ./pytest-coverage.txt
61+
junitxml-path: ./pytest.xml
62+
coverage-path-prefix: backend/
63+
64+
# - name: Update README
65+
# run: |
66+
# sed -i '/<!-- Pytest Coverage Comment:Begin -->/,/<!-- Pytest Coverage Comment:End -->/c\<!-- Pytest Coverage Comment:Begin -->\n${{ steps.coverage.outputs.coverageHtml }}\n<!-- Pytest Coverage Comment:End -->' ./backend/README.md
67+
68+
# - name: Commit changes
69+
# uses: stefanzweifel/git-auto-commit-action@v5
70+
# with:
71+
# commit_message: 'docs: update coverage badge'
72+
# file_pattern: backend/README.md

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
pytest-coverage.txt
2+
pytest.xml
3+
14
.idea
25
.version
36

.vscode/launch.json

100644100755
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@
1010
"request": "launch",
1111
"module": "pytest",
1212
"console": "integratedTerminal",
13+
"cwd": "${workspaceFolder}/backend",
1314
"args": [
14-
"backend/yet_another_calendar/tests/"
15-
],
15+
"yet_another_calendar/tests/test_lms.py"
16+
]
1617
},
1718
{
1819
"name": "Python debug backend (docker)",
1920
"request": "attach",
20-
"type": "python",
21+
"type": "debugpy",
2122
"pathMappings": [
2223
{
2324
"localRoot": "${workspaceFolder}/backend",

.vscode/settings.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"python.testing.pytestArgs": [
3+
"./backend/yet_another_calendar/tests/"
4+
],
5+
"python.testing.unittestEnabled": false,
6+
"python.testing.pytestEnabled": true,
7+
8+
"ruff.configuration": "./backend/pyproject.toml",
9+
"ruff.nativeServer": "on",
10+
11+
"mypy.dmypyExecutable": "${workspaceFolder}/backend/.venv/bin/dmypy",
12+
"mypy.mypyExecutable": "${workspaceFolder}/backend/.venv/bin/mypy",
13+
"mypy.configFile": "backend/pyproject.toml",
14+
}

backend/.flake8

Lines changed: 0 additions & 6 deletions
This file was deleted.

backend/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
[![Checked with mypy](https://www.mypy-lang.org/static/mypy_badge.svg)](https://mypy-lang.org/)
66
[![uv](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json)](https://github.com/astral-sh/uv)
77

8+
89
[![Redis](https://img.shields.io/badge/redis-%23DD0031.svg?style=for-the-badge&logo=redis&logoColor=white&style=flat)](https://redis.io/)
910
[![Docker](https://img.shields.io/badge/docker-%230db7ed.svg?style=for-the-badge&logo=docker&logoColor=white&style=flat)](https://www.docker.com/)
1011
[![FastAPI](https://img.shields.io/badge/FastAPI-005571?style=for-the-badge&logo=fastapi&style=flat)](https://fastapi.tiangolo.com/)

backend/generate_password_hash.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,34 +20,34 @@ def generate_password_hash(password: str | None = None) -> str:
2020
if password is None:
2121
password = getpass.getpass("Enter tutor password: ")
2222
confirm_password = getpass.getpass("Confirm password: ")
23-
23+
2424
if password != confirm_password:
2525
logger.info("Passwords don't match. Please try again.")
2626
return generate_password_hash()
27-
27+
2828
if len(password) < 8:
2929
logger.info("Password must be at least 8 characters long. Please try again.")
3030
if password is None:
3131
return generate_password_hash()
3232
else:
3333
sys.exit(1)
34-
34+
3535
# Generate salt and hash
3636
salt = bcrypt.gensalt()
3737
password_hash = bcrypt.hashpw(password.encode('utf-8'), salt)
38-
38+
3939
return password_hash.decode('utf-8')
4040

4141

4242
if __name__ == "__main__":
4343
password_arg = sys.argv[1] if len(sys.argv) > 1 else None
4444
hash_value = generate_password_hash(password_arg)
45-
45+
4646
# Verify the hash works
4747
if password_arg:
4848
verification_result = bcrypt.checkpw(password_arg.encode('utf-8'), hash_value.encode('utf-8'))
4949
logger.info(f"Hash verification: {verification_result}")
50-
50+
5151
logger.info("\n" + "="*50)
5252
logger.info("Generated password hash:")
5353
logger.info(hash_value)
@@ -57,4 +57,4 @@ def generate_password_hash(password: str | None = None) -> str:
5757
logger.info("\nFor Docker Compose (escape $ characters):")
5858
docker_hash = hash_value.replace("$", "$$")
5959
logger.info(f"YET_ANOTHER_CALENDAR_TUTOR_PASSWORD_HASH={docker_hash}")
60-
logger.info("="*50)
60+
logger.info("="*50)

backend/pyproject.toml

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "yet_another_calendar"
3-
version = "2.0.0"
3+
version = "2.1.0"
44
description = ""
55
authors = [
66
{ name = "Ivan Popov", email = "ma1n.py@yandex.ru" },
@@ -14,6 +14,7 @@ dependencies = [
1414
"environs>=14.1.1",
1515
"fastapi>=0.115.11",
1616
"fastapi-cache2>=0.2.2",
17+
"flake8-import-conventions>=0.1.0",
1718
"httpx[http2]==0.27.2",
1819
"icalendar>=6.1.1",
1920
"loguru>=0.7.3",
@@ -36,7 +37,8 @@ dependencies = [
3637
dev = [
3738
"black>=25.1.0",
3839
"fakeredis>=2.27.0",
39-
"mypy>=1.15.0",
40+
"flake8-async>=25.7.1",
41+
"mypy>=1.18.2",
4042
"pytest>=8.3.5",
4143
"pytest-asyncio>=0.25.3",
4244
"pytest-cov>=6.0.0",
@@ -72,14 +74,15 @@ env = [
7274
"YET_ANOTHER_CALENDAR_DB_BASE=yet_another_calendar_test",
7375
]
7476

75-
[ruff]
77+
[tool.ruff]
7678
target-version = "py311"
7779

7880
lint.select = [
7981
"A", # prevent using keywords that clobber python builtins
8082
"N", # pep8-naming
8183
"B", # bugbear: security warnings
82-
"E", # pycodestyle
84+
"E", # pycodestyle errors
85+
"W", # pycodestyle warnings
8386
"F", # pyflakes
8487
"ISC", # implicit string concatenation
8588
"UP", # alert you when better syntax is available in your python version
@@ -91,7 +94,15 @@ lint.select = [
9194
"COM", # flake8-logging
9295
"ASYNC", # flake8-async
9396
"ANN", # flake8-annotations
97+
"C4", # flake8-comprehensions
98+
"EXE", # flake8-executable
99+
"FIX", # flake8-fixme
100+
"ICN", # flake8-import-conventions
101+
"PIE", # flake8-pie
102+
94103
"PL", # Pylint
104+
"PLE", # pylint errors
105+
95106
]
96107
lint.ignore = [
97108
"ANN401",
@@ -102,14 +113,14 @@ lint.ignore = [
102113
line-length = 119
103114
exclude = [
104115
".venv/",
105-
"yet_another_calendar/tests/*",
116+
"*/tests/*",
106117
]
107118

108-
[ruff.lint.pydocstyle]
119+
[tool.ruff.lint.pydocstyle]
109120
convention = "pep257"
110121
ignore-decorators = ["typing.overload"]
111122

112-
[ruff.lint.pylint]
123+
[tool.ruff.lint.pylint]
113124
allow-magic-value-types = ["int", "str", "float", "bytes"]
114125

115126
[fastapi-template.options]

0 commit comments

Comments
 (0)