Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions matrixbox_simulator/device/cpstubs/storage.py
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions tests/test_storage_stub.py
Original file line number Diff line number Diff line change
@@ -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
Loading