Skip to content

Commit a81fe83

Browse files
authored
refactor: Add unit testing and refactor code to follow Python standards. (#31)
* refactor: Add unit testing and refactor code to follow Python standards. - Reformat file with community standards black and ruff, with basic config - Format all variable namings using PEP8. - Add unit tests for two of the auxiliary methods. - Add testing on CI using github actions and pytest - Improve code clarity by using f-strings, available since python 3.6 * fix: Fix test pipeline and apply suggestions. * fix: Fix wrong conditional on test pipeline.
1 parent 9b22b21 commit a81fe83

File tree

8 files changed

+332
-188
lines changed

8 files changed

+332
-188
lines changed

.github/workflows/test.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Run tests
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: [ main ]
7+
8+
jobs:
9+
build:
10+
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
python-version: ["3.9", "3.10", "3.11"]
15+
16+
steps:
17+
- uses: actions/checkout@v3
18+
- name: Set up Python ${{ matrix.python-version }}
19+
uses: actions/setup-python@v4
20+
with:
21+
python-version: ${{ matrix.python-version }}
22+
- name: Install dependencies
23+
run: |
24+
python -m pip install --upgrade pip
25+
pip install ruff pytest
26+
cd src/ && pip install -r requirements.txt
27+
- name: Lint with ruff
28+
run: |
29+
# stop the build if there are Python syntax errors or undefined names
30+
ruff --select=E9,F63,F7,F82 --target-version=py37 .
31+
# default set of ruff rules with GitHub Annotations
32+
ruff --target-version=py37 .
33+
- name: Test with pytest
34+
run: |
35+
pytest

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ local.properties
6363
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
6464

6565
# User-specific stuff:
66+
.idea/
6667
.idea/**/workspace.xml
6768
.idea/**/tasks.xml
6869
.idea/dictionaries
@@ -223,3 +224,4 @@ $RECYCLE.BIN/
223224
*.lnk
224225

225226
# End of https://www.gitignore.io/api/osx,java,linux,eclipse,windows,netbeans,java-web,intellij
227+
__pycache__/

.pre-commit-config.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,26 @@ repos:
1414
rev: v2.12.0
1515
hooks:
1616
- id: hadolint-docker
17+
- repo: 'https://github.com/charliermarsh/ruff-pre-commit'
18+
rev: v0.2.0
19+
hooks:
20+
- id: ruff
21+
args:
22+
- '--line-length=120'
23+
- '--fix'
24+
- '--exit-non-zero-on-fix'
25+
- repo: 'https://github.com/pycqa/isort'
26+
rev: 5.13.2
27+
hooks:
28+
- id: isort
29+
name: isort (python)
30+
args:
31+
- '--profile'
32+
- black
33+
- '--filter-files'
34+
- repo: 'https://github.com/psf/black'
35+
rev: 24.1.1
36+
hooks:
37+
- id: black
38+
args:
39+
- '--line-length=120'

src/app/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)