Add infrastructure for pytest and mypy
Make mypy run with proper type stubs for micropython RP2. Add basic structure for pytest testing. Signed-off-by: Matthias Blankertz <matthias@blankertz.org>
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -3,6 +3,9 @@ hardware/tonberry-pico/tonberry-pico-backups/
|
|||||||
*.kicad_sch-bak
|
*.kicad_sch-bak
|
||||||
*.kicad_sch.lck
|
*.kicad_sch.lck
|
||||||
software/build
|
software/build
|
||||||
|
software/typings
|
||||||
compile_commands.json
|
compile_commands.json
|
||||||
.dir-locals.el
|
.dir-locals.el
|
||||||
.cache
|
.cache
|
||||||
|
\#*#
|
||||||
|
__pycache__
|
||||||
|
|||||||
11
DEVELOP.md
Normal file
11
DEVELOP.md
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
# Developer notes
|
||||||
|
|
||||||
|
## How to setup python environment for mypy and pytest
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd software
|
||||||
|
python -m venv test-venv
|
||||||
|
. test-venv/bin/activate
|
||||||
|
pip install -r tests/requirements.txt
|
||||||
|
pip install -U micropython-rp2-pico_w-stubs --target typings
|
||||||
|
```
|
||||||
9
software/mypy.ini
Normal file
9
software/mypy.ini
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
[mypy]
|
||||||
|
platform = linux
|
||||||
|
mypy_path = $MYPY_CONFIG_FILE_DIR/src:$MYPY_CONFIG_FILE_DIR/typings
|
||||||
|
custom_typeshed_dir = $MYPY_CONFIG_FILE_DIR/typings
|
||||||
|
follow_imports = silent
|
||||||
|
exclude = "typings[\\/].*"
|
||||||
|
follow_imports_for_stubs = true
|
||||||
|
no_site_packages = true
|
||||||
|
check_untyped_defs = true
|
||||||
3
software/pytest.ini
Normal file
3
software/pytest.ini
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
[pytest]
|
||||||
|
pythonpath = tests/mocks src
|
||||||
|
testpaths = tests
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
# SPDX-License-Identifier: MIT
|
# SPDX-License-Identifier: MIT
|
||||||
# Copyright (c) 2024-2025 Matthias Blankertz <matthias@blankertz.org>
|
# Copyright (c) 2024-2025 Matthias Blankertz <matthias@blankertz.org>
|
||||||
|
|
||||||
import aiorepl
|
import aiorepl # type: ignore
|
||||||
import asyncio
|
import asyncio
|
||||||
import machine
|
import machine
|
||||||
import micropython
|
import micropython
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ if TYPE_CHECKING:
|
|||||||
|
|
||||||
|
|
||||||
class Buttons:
|
class Buttons:
|
||||||
def __init__(self, cb: ButtonCallback, pin_volup=17, pin_voldown=19, pin_next=18):
|
def __init__(self, cb: "ButtonCallback", pin_volup=17, pin_voldown=19, pin_next=18):
|
||||||
self.VOLUP = micropython.const(1)
|
self.VOLUP = micropython.const(1)
|
||||||
self.VOLDOWN = micropython.const(2)
|
self.VOLDOWN = micropython.const(2)
|
||||||
self.NEXT = micropython.const(3)
|
self.NEXT = micropython.const(3)
|
||||||
|
|||||||
2
software/tests/mocks/machine.py
Normal file
2
software/tests/mocks/machine.py
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
# Copyright (c) 2025 Matthias Blankertz <matthias@blankertz.org>
|
||||||
2
software/tests/mocks/micropython.py
Normal file
2
software/tests/mocks/micropython.py
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
# Copyright (c) 2025 Matthias Blankertz <matthias@blankertz.org>
|
||||||
5
software/tests/mocks/rp2_sd.py
Normal file
5
software/tests/mocks/rp2_sd.py
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
# Copyright (c) 2025 Matthias Blankertz <matthias@blankertz.org>
|
||||||
|
|
||||||
|
class SDCard():
|
||||||
|
pass
|
||||||
1
software/tests/requirements.txt
Normal file
1
software/tests/requirements.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
pytest
|
||||||
3
software/tests/test_dummy.py
Normal file
3
software/tests/test_dummy.py
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
def test_dummy():
|
||||||
|
# This is just a dummy test to make pytest not fail because no tests are defined
|
||||||
|
pass
|
||||||
0
software/tests/utils_test/__init__.py
Normal file
0
software/tests/utils_test/__init__.py
Normal file
Reference in New Issue
Block a user