Skip to content

Commit

Permalink
use tox for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
firstof9 committed May 11, 2024
1 parent e2b768a commit 298972d
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 16 deletions.
49 changes: 33 additions & 16 deletions .github/workflows/pytest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,49 @@ on:
- cron: "0 7 1-28/7 * *"

jobs:
build:
tests:
runs-on: ubuntu-latest
name: Run tests
strategy:
matrix:
python-version:
- "3.12"

steps:
- uses: actions/checkout@v4
- name: 📥 Checkout the repository
uses: actions/checkout@v4
- name: 🛠️ Set up Python
uses: actions/setup-python@v5
with:
fetch-depth: 2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
sudo apt-get install libudev-dev
python -m pip install --upgrade pip
pip install -r requirements_test.txt
- name: Run formatting
- name: 📦 Install requirements
run: |
python -m isort -v --profile black .
python -m black -v .
- name: Generate coverage report
run: |
python -m pytest
pip install pytest-cov
pytest ./tests/ --cov=custom_components/keymaster/ --cov-report=xml
- name: Upload coverage to Codecov
pip install tox tox-gh-actions
- name: 🏃 Test with tox
run: tox
- name: 📤 Upload coverage to Codecov
uses: "actions/upload-artifact@v4"
with:
name: coverage-data
path: "coverage.xml"

coverage:
runs-on: ubuntu-latest
needs: tests
steps:
- name: 📥 Checkout the repository
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: 📥 Download coverage data
uses: actions/download-artifact@v4
with:
name: coverage-data
- name: 📤 Upload coverage report
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }} # required
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ custom_components/*/__pycache__/
venv
*.pyc
.coverage
coverage.xml
.tox/py312/.tox-info.json
50 changes: 50 additions & 0 deletions pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
[MASTER]
ignore=tests
# Use a conservative default here; 2 should speed up most setups and not hurt
# any too bad. Override on command line as appropriate.
jobs=2
persistent=no

[BASIC]
good-names=id,i,j,k,ex,Run,_,fp
max-attributes=15
argument-naming-style=snake_case
attr-naming-style=snake_case

[MESSAGES CONTROL]
# Reasons disabled:
# locally-disabled - it spams too much
# too-many-* - are not enforced for the sake of readability
# too-few-* - same as too-many-*
# import-outside-toplevel - TODO
disable=
duplicate-code,
fixme,
import-outside-toplevel,
locally-disabled,
too-few-public-methods,
too-many-arguments,
too-many-public-methods,
too-many-instance-attributes,
too-many-branches,
too-many-statements,
broad-except,
too-many-lines,
too-many-locals,
unexpected-keyword-arg,
abstract-method,

[REFACTORING]

# Maximum number of nested blocks for function / method body
max-nested-blocks=8

[REPORTS]
score=no

[TYPECHECK]
# For attrs
ignored-classes=_CountingAttr

[FORMAT]
expected-line-ending-format=LF
3 changes: 3 additions & 0 deletions requirements_test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ black
isort
pydispatcher
zeroconf
tox
mypy
flake8
32 changes: 32 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[mypy]
python_version = 3.10
show_error_codes = true
ignore_errors = true
follow_imports = silent
ignore_missing_imports = true
warn_incomplete_stub = true
warn_redundant_casts = true
warn_unused_configs = true

[flake8]
exclude = .venv,.git,.tox,docs,venv,bin,lib,deps,build
# To work with Black
max-line-length = 88
# E501: line too long
# W503: Line break occurred before a binary operator
# E203: Whitespace before ':'
# D202 No blank lines allowed after function docstring
# W504 line break after binary operator
ignore =
E501,
W503,
E203,
D202,
W504

[isort]
multi_line_output = 3
include_trailing_comma = True
force_grid_wrap = 0
use_parentheses = True
line_length = 88
1 change: 1 addition & 0 deletions tests/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
KWIKSET_910_LOCK_ENTITY = "lock.smart_code_with_home_connect_technology"
_LOGGER = logging.getLogger(__name__)

pytestmark = pytest.mark.asyncio

@pytest.mark.parametrize(
"input_1,title,data",
Expand Down
35 changes: 35 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[tox]
skipsdist = true
envlist = py310, py311, py312, lint, mypy
skip_missing_interpreters = True

[gh-actions]
python =
3.10: py310
3.11: py311
3.12: py312, lint, mypy

[testenv]
commands =
pytest --asyncio-mode=auto --timeout=30 --cov=custom_components/keymaster --cov-report=xml {posargs}
deps =
-rrequirements_test.txt

[testenv:lint]
basepython = python3
ignore_errors = True
commands =
black --check ./
flake8 custom_components/keymaster
pylint custom_components/keymaster
pydocstyle custom_components/keymaster tests
deps =
-rrequirements_test.txt

[testenv:mypy]
basepython = python3
ignore_errors = True
commands =
mypy custom_components/keymaster
deps =
-rrequirements_test.txt

0 comments on commit 298972d

Please sign in to comment.