The 46 missing docstrings, written rather than generated. Most of the test ones already carried the explanation — as a comment sitting on the first line of the body. That prose is the docstring; it was only in the wrong place, so the config editor's PIN and lane tests keep their own words and lose the duplicate comment. The rest are new: the two `repo` fixtures, the counting `FakeDevice` in `test_device_state` (each method now says what it answers *and* that it counts the call), the PicoCalc chrome and 16-slot theme tests, and three one-offs. In the package: `PathLine` and `FastRenderer`'s constructors point at the class docstring that already documents their arguments rather than repeating it, `SelectItem.__post_init__` and `courier_screen`'s opener say what they cache and why, and `emoji_width.create_content` explains the memo it wraps the line lookup in. `flash.py` and `uart1-mux.py` get theirs too, and `tests/__init__.py` finally says what the package is. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
44 lines
1.4 KiB
Python
44 lines
1.4 KiB
Python
"""The F-key lane's Shift-state watcher: the raw flag and the shift-bank latch."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from meshterm.services import modifier_watch
|
|
|
|
|
|
def _reset() -> None:
|
|
modifier_watch._shift_down = False
|
|
modifier_watch._last_shift_bank_at = None
|
|
|
|
|
|
def test_shift_down_reflects_the_raw_flag() -> None:
|
|
"""``shift_down()`` reports the flag the watcher last set, with nothing in between."""
|
|
_reset()
|
|
try:
|
|
assert modifier_watch.shift_down() is False
|
|
modifier_watch._shift_down = True
|
|
assert modifier_watch.shift_down() is True
|
|
finally:
|
|
_reset()
|
|
|
|
|
|
def test_shift_bank_key_latches_over_the_release_flicker(monkeypatch) -> None:
|
|
"""An F6-F10 press keeps the lane's shifted read for a grace window, even if the raw
|
|
watcher (wrongly, per the MCU quirk) reports Shift already back up.
|
|
"""
|
|
_reset()
|
|
try:
|
|
clock = [100.0]
|
|
monkeypatch.setattr(modifier_watch.time, "monotonic", lambda: clock[0])
|
|
|
|
assert modifier_watch.shift_down() is False
|
|
modifier_watch.note_shift_bank_key()
|
|
assert modifier_watch.shift_down() is True # latched, raw flag never went true
|
|
|
|
clock[0] += modifier_watch._SHIFT_BANK_GRACE_S - 0.05
|
|
assert modifier_watch.shift_down() is True # still inside the grace window
|
|
|
|
clock[0] += 0.1
|
|
assert modifier_watch.shift_down() is False # grace lapsed, Shift really let go
|
|
finally:
|
|
_reset()
|