Skip to content

Commit 239c1b0

Browse files
authored
unit tests with mock i2c (#54)
* feat: adds mock i2c tests. * fix: make non-file targets phony so they always run. Ignore line too long warnings. (120 chars is the norm in many projects and PEP8 allows a maximum of 79.) See https://stackoverflow.com/questions/17319422/how-do-i-set-the-maximum-line-length-in-pycharm#comment58112267_17319775 for discussion. * fix: ignore line too long endings in github actions. (Ideally these should use the Makefile so they are consistent.) * latest ubuntu (v22) doesn't have python < 3.8, so using v20 actions/setup-python#391 * add mocking for periphery.I2C * chore: separate out the make targets, while preserving existing behavior. Don't use the virtualenv if it doesn't exist. * chore: use the makefile as the one point for running flake8, docstyle and tests. Removes duplication of flake8 flags. * chore: use pytest class declarations, remove the new `unittest` import.
1 parent bc4f9ab commit 239c1b0

File tree

4 files changed

+298
-343
lines changed

4 files changed

+298
-343
lines changed

.github/workflows/manual-run.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ on: workflow_dispatch
88
jobs:
99
build:
1010

11-
runs-on: ubuntu-latest
11+
runs-on: ubuntu-20.04
1212
strategy:
1313
matrix:
14-
python-version: [3.9]
14+
python-version: [3.8, 3.9]
1515

1616
steps:
1717
- name: Send building notification
@@ -34,10 +34,12 @@ jobs:
3434
- name: Lint with flake8
3535
run: |
3636
# stop the build if there are Python syntax errors or undefined names
37-
flake8 test/ notecard/ examples/ --count --ignore=E722,F401,F403,W503 --show-source --statistics
37+
make flake8
38+
# flake8 test/ notecard/ examples/ --count --ignore=E722,F401,F403,W503,E501 --show-source --statistics
3839
- name: Lint Docs with Pydocstyle
3940
run: |
40-
pydocstyle notecard/ examples/
41+
make docstyle
42+
# pydocstyle notecard/ examples/
4143
- name: Send running tests notification
4244
run: |
4345
curl --request POST \
@@ -47,7 +49,7 @@ jobs:
4749
--data '{"req":"note.add","file":"build_results.qi","body":{"result":"running_tests"}}'
4850
- name: Test with pytest
4951
run: |
50-
pytest
52+
make test
5153
- name: Check if the job has succeeded
5254
if: ${{ success() }}
5355
run: |

.github/workflows/python-package.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ on:
1212
jobs:
1313
build:
1414

15-
runs-on: ubuntu-latest
15+
runs-on: ubuntu-20.04
1616
strategy:
1717
matrix:
1818
python-version: [3.6, 3.7, 3.8, 3.9]
@@ -38,10 +38,10 @@ jobs:
3838
- name: Lint with flake8
3939
run: |
4040
# stop the build if there are Python syntax errors or undefined names
41-
flake8 test/ notecard/ examples/ --count --ignore=E722,F401,F403,W503 --show-source --statistics
41+
make flake8
4242
- name: Lint Docs with Pydocstyle
4343
run: |
44-
pydocstyle notecard/ examples/
44+
make docstyle
4545
- name: Send running tests notification
4646
run: |
4747
curl --request POST \

Makefile

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,40 @@
1+
# define VENV_NAME to use a specific virtual environment. It defaults to `env`.
12
VENV_NAME?=env
23
VENV_ACTIVATE=. $(VENV_NAME)/bin/activate
3-
PYTHON=${VENV_NAME}/bin/python3
4+
PYTHON=python
5+
VENV =
46

5-
default: test
7+
# check if the VENV file exists
8+
ifneq ("$(wildcard $(PVENV_ACTIVATE))","")
9+
VENV = venv
10+
PYTHON = ${VENV_NAME}/bin/python3
11+
endif
12+
13+
default: docstyle flake8 test
614

715
venv: $(VENV_NAME)/bin/activate
816

9-
test: venv
10-
${PYTHON} -m pydocstyle notecard/ examples/
11-
${PYTHON} -m flake8 test/ notecard/ examples/ --count --ignore=E722,F401,F403,W503 --show-source --statistics
17+
test: $(VENV)
1218
${PYTHON} -m pytest test --cov=notecard
1319

14-
coverage: venv
20+
docstyle: $(VENV)
21+
${PYTHON} -m pydocstyle notecard/ examples/
22+
23+
flake8: $(VENV)
24+
# E722 Do not use bare except, specify exception instead https://www.flake8rules.com/rules/E722.html
25+
# F401 Module imported but unused https://www.flake8rules.com/rules/F401.html
26+
# F403 'from module import *' used; unable to detect undefined names https://www.flake8rules.com/rules/F403.html
27+
# W503 Line break occurred before a binary operator https://www.flake8rules.com/rules/W503.html
28+
# E501 Line too long (>79 characters) https://www.flake8rules.com/rules/E501.html
29+
${PYTHON} -m flake8 test/ notecard/ examples/ --count --ignore=E722,F401,F403,W503,E501 --show-source --statistics
30+
31+
coverage: $(VENV)
1532
${PYTHON} -m pytest test --doctest-modules --junitxml=junit/test-results.xml --cov=notecard --cov-report=xml --cov-report=html
1633

17-
run_build:
34+
run_build: $(VENV)
1835
${PYTHON} -m setup sdist bdist_wheel
1936

20-
deploy:
37+
deploy: $(VENV)
2138
${PYTHON} -m twine upload -r "pypi" --config-file .pypirc 'dist/*'
39+
40+
.PHONY: venv test coverage run_build deploy

0 commit comments

Comments
 (0)