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:
2025-08-23 13:04:04 +02:00
parent fb36ac8ed2
commit 27110b7b62
12 changed files with 41 additions and 2 deletions

3
.gitignore vendored
View File

@@ -3,6 +3,9 @@ hardware/tonberry-pico/tonberry-pico-backups/
*.kicad_sch-bak
*.kicad_sch.lck
software/build
software/typings
compile_commands.json
.dir-locals.el
.cache
\#*#
__pycache__

11
DEVELOP.md Normal file
View 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
View 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
View File

@@ -0,0 +1,3 @@
[pytest]
pythonpath = tests/mocks src
testpaths = tests

View File

@@ -1,7 +1,7 @@
# SPDX-License-Identifier: MIT
# Copyright (c) 2024-2025 Matthias Blankertz <matthias@blankertz.org>
import aiorepl
import aiorepl # type: ignore
import asyncio
import machine
import micropython

View File

@@ -17,7 +17,7 @@ if TYPE_CHECKING:
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.VOLDOWN = micropython.const(2)
self.NEXT = micropython.const(3)

View File

@@ -0,0 +1,2 @@
# SPDX-License-Identifier: MIT
# Copyright (c) 2025 Matthias Blankertz <matthias@blankertz.org>

View File

@@ -0,0 +1,2 @@
# SPDX-License-Identifier: MIT
# Copyright (c) 2025 Matthias Blankertz <matthias@blankertz.org>

View File

@@ -0,0 +1,5 @@
# SPDX-License-Identifier: MIT
# Copyright (c) 2025 Matthias Blankertz <matthias@blankertz.org>
class SDCard():
pass

View File

@@ -0,0 +1 @@
pytest

View 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

View File