Skip to content

Commit ef295f0

Browse files
authored
Merge pull request #27 from pritam001/development
Add testing and coverage reporting
2 parents 1aeabc2 + 71bae21 commit ef295f0

35 files changed

+164
-45
lines changed

.bandit.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
[bandit]
2-
targets: src,test,*.py
3-
exclude: dummy.py
4-
skips:
5-
tests:
1+
targets: src,*.py
2+
exclude: dummy.py
3+
skips:
4+
tests:

.github/workflows/pythonpackage.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,8 @@ jobs:
2626
run: |
2727
pip install flake8
2828
make lint
29+
- name: Test and CC
30+
run: |
31+
make test-n-cover
32+
bash <(curl -s https://codecov.io/bash) -t ${{ secrets.CODECOV_TOKEN }}
2933

.gitignore

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,7 @@ DS_Store
138138

139139
# logs
140140
logs/
141-
142-
# mypy
143-
.mypy_cache/
141+
**/logs/
144142

145143
# terminalizer
146144
config.yml

Makefile

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ PYTHON = python3
2121

2222
# .PHONY defines parts of the makefile that are not dependant on any specific file
2323
# This is most often used to store functions
24-
.PHONY = help setup format lint test debug clean
24+
.PHONY = all help setup format lint format-n-lint test-n-cover pre-commit
2525

2626
# Defining an array variable
2727
FILES = input output
@@ -37,7 +37,9 @@ help:
3737
@echo "$(BOLD_CYAN)make setup$(RESET_STYLES) : Setup pyflask-service"
3838
@echo "$(BOLD_CYAN)make format$(RESET_STYLES) : Format and fix python code in pyflask-service"
3939
@echo "$(BOLD_CYAN)make lint$(RESET_STYLES) : Lint pyflask-service"
40-
@echo "$(BOLD_CYAN)make test$(RESET_STYLES) : Test pyflask-service"
40+
@echo "$(BOLD_CYAN)make format-n-lint$(RESET_STYLES) : Format and lint python code in pyflask-service"
41+
@echo "$(BOLD_CYAN)make test-n-cover$(RESET_STYLES) : Test and code coverage pyflask-service"
42+
@echo "$(BOLD_CYAN)make pre-commit$(RESET_STYLES) : Run pre-commit checks for pyflask-service"
4143
@echo "$(BOLD_CYAN)make debug$(RESET_STYLES) : Debug pyflask-service"
4244
@echo "$(BOLD_CYAN)make clean$(RESET_STYLES) : Clean pyflask-service"
4345
@echo "$(BOLD_CYAN)make dev-run$(RESET_STYLES) : Run pyflask-service in environment=development"
@@ -73,6 +75,9 @@ format: #: Format and fix python code with black, isort, autoflake
7375
@echo "\n$(BOLD_CYAN)Flaking$(RESET_STYLES) ❄️"
7476
flake8 --version
7577
autoflake --remove-all-unused-imports --remove-unused-variables --remove-duplicate-keys --ignore-init-module-imports -i -r $(APP_DIR) $(TEST_DIR) $(HOME_DIR_PY_FILES)
78+
@echo "\n$(BOLD_CYAN)Running pre-commit hooks$(RESET_STYLES) 🏁️️️"
79+
pre-commit run --all-files
80+
@echo "\n$(BOLD_CYAN)All checks passed$(RESET_STYLES) 🏳️️️️"
7681
@echo "\n"
7782

7883

@@ -88,9 +93,25 @@ lint: #: Run static analysis with flake8, radon, mypy and bandit
8893
mypy $(APP_DIR) $(HOME_DIR_PY_FILES)
8994
@echo "\n$(BOLD_CYAN)Securing with bandit$(RESET_STYLES) 🕵️️"
9095
bandit --version
91-
bandit -l -i -r . --format=custom
92-
@echo "\n$(BOLD_CYAN)Running pre-commit hooks$(RESET_STYLES) 🏁️️️"
93-
pre-commit run --all-files
94-
@echo "\n$(BOLD_CYAN)All checks passed$(RESET_STYLES) 🏳️️️️"
96+
bandit -l -i -r . --format=custom -c .bandit.yml -x ./$(TEST_DIR)
97+
@echo "\n"
98+
99+
100+
format-n-lint: #: Format and lint
101+
make format
102+
make lint
95103
@echo "\n"
96104

105+
106+
test-n-cover: #: Test with pytest, Code coverage with pytest-cov plugin
107+
@echo "\n$(BOLD_CYAN)Testing with pytest$(RESET_STYLES) 📊️"
108+
pytest --version
109+
pytest
110+
@echo "\n"
111+
112+
113+
pre-commit: #: Run pre-commit checks : format, lint, test, cover
114+
make format-n-lint
115+
make test-n-cover
116+
@echo "\n$(BOLD_CYAN)Pre commit jobs completed$(RESET_STYLES) 👍"
117+
@echo "\n"

README.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@ An "optionally opinionated and structured" flask boilerplate microservice for ju
66
![Python](https://img.shields.io/badge/-Python-3776AB?style=flat-square&logo=Python&logoColor=white)
77
![Flask](https://img.shields.io/badge/-Flask-000000?style=flat-square&logo=flask&logoColor=white)
88
![License](https://img.shields.io/github/license/pritam001/pyflask-microservice-base?style=flat-square&label=License)
9+
10+
11+
Project status
12+
------------------------------------------------------------------------------
913
![WIP](https://img.shields.io/badge/%20%F0%9F%9A%A7%20-Dev%20in%20progress-important)
14+
[![Maintainability](https://api.codeclimate.com/v1/badges/cc34f11b1a2b9bb8e216/maintainability)](https://codeclimate.com/github/pritam001/pyflask-microservice-base/maintainability)
15+
[![codecov](https://codecov.io/gh/pritam001/pyflask-microservice-base/branch/master/graph/badge.svg)](https://codecov.io/gh/pritam001/pyflask-microservice-base)
1016

1117

1218
Tools
@@ -20,6 +26,8 @@ Tools
2026
[![Security: bandit](https://img.shields.io/badge/security-bandit-yellow.svg?style=flat)](https://github.com/PyCQA/bandit)
2127
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?style=flat&logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit)
2228
[![API Specs](https://img.shields.io/badge/specs-flasgger-6D9A00?style=flat&logo=swagger&logoColor=white)](https://github.com/flasgger/flasgger)
29+
[![Tests: pytest](https://img.shields.io/badge/%20tests-pytest-%23009BDB?style=flat)](https://docs.pytest.org/en/latest/contents.html)
30+
[![Coverage: pytest-cov](https://img.shields.io/badge/%20coverage-pytest--cov-%23009BDB?style=flat)](https://docs.pytest.org/en/latest/contents.html)
2331

2432

2533
Usage Guide
@@ -44,9 +52,13 @@ Type `make help` for available commands
4452

4553
<p align="center"><img src="documentation/assets/make-help.gif" /></p>
4654

55+
Type `make pre-commit` before committing your changes to run formatters, linters, tests and code coverage collectors
56+
57+
<p align="center"><img src="documentation/assets/make-pre-commit.gif" /></p>
58+
4759

4860
### Linting Guide
49-
`make format` : Format and fix python code with black, isort, autoflake
61+
`make format` : Format and fix python code with black, isort, autoflake and pre-commit hooks
5062

5163
<p align="center"><img src="documentation/assets/make-format.gif" /></p>
5264

@@ -86,8 +98,9 @@ TODO
8698
-----------------------------------------------------------------------------
8799
- [x] Swagger support
88100
- [ ] Update linting documentation
89-
- [ ] Introduction of testing tools
101+
- [x] Introduction of testing tools
90102
- [ ] Testing tools documentation
103+
- [x] Code coverage
91104
- [ ] Version handling by tbump
92-
- [ ] Add CoC, Contribution guidelines, PR and issue
105+
- [ ] Add CoC, Contribution guidelines, PR and issue templates
93106

555 KB
Loading

documentation/assets/make-help.gif

29.4 KB
Loading

documentation/assets/make-lint.gif

-515 KB
Loading
4.51 MB
Loading
File renamed without changes.

0 commit comments

Comments
 (0)