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