From 4a519d4dad5ffcd10bd9d46256cf1c57e585b87d Mon Sep 17 00:00:00 2001 From: Simon Sawert Date: Sat, 26 Sep 2026 11:12:19 +0200 Subject: [PATCH] fix: add stub for CircuitPython `storage` module - Add `storage` stub with `getmount`, `remount` and USB drive toggles - Report the root mount as writable, `remount` updates the flag - Add tests for the stub --- matrixbox_simulator/device/cpstubs/storage.py | 36 +++++++++++++++++++ tests/test_storage_stub.py | 13 +++++++ 2 files changed, 49 insertions(+) create mode 100644 matrixbox_simulator/device/cpstubs/storage.py create mode 100644 tests/test_storage_stub.py diff --git a/matrixbox_simulator/device/cpstubs/storage.py b/matrixbox_simulator/device/cpstubs/storage.py new file mode 100644 index 0000000..28aedcd --- /dev/null +++ b/matrixbox_simulator/device/cpstubs/storage.py @@ -0,0 +1,36 @@ +"""Stand-in for CircuitPython's `storage`. The simulated filesystem has no +USB host competing for it, so it starts writable from code's point of view +and USB drive toggling is a no-op. + +https://docs.circuitpython.org/en/latest/shared-bindings/storage/ +""" + + +class VfsFat: + def __init__(self, readonly: bool = False) -> None: + self.readonly = readonly + self.label = "CIRCUITPY" + + +_root_mount = VfsFat() + + +def getmount(mount_path: str) -> VfsFat: + return _root_mount + + +def remount( + mount_path: str, + readonly: bool = False, + *, + disable_concurrent_write_protection: bool = False, +) -> None: + getmount(mount_path).readonly = readonly + + +def disable_usb_drive() -> None: + pass + + +def enable_usb_drive() -> None: + pass diff --git a/tests/test_storage_stub.py b/tests/test_storage_stub.py new file mode 100644 index 0000000..eba0f6f --- /dev/null +++ b/tests/test_storage_stub.py @@ -0,0 +1,13 @@ +from matrixbox_simulator.device.cpstubs import storage + + +def test_root_mount_starts_writable() -> None: + assert storage.getmount("/").readonly is False + + +def test_remount_updates_readonly_flag() -> None: + storage.remount("/", True) + assert storage.getmount("/").readonly is True + + storage.remount("/", False) + assert storage.getmount("/").readonly is False