Files
MeshTerm/tests/test_modifier_watch.py
T
Jean-Pierre MartineauandClaude Fable 5.1 c9f5a71ce7 Every Python file names its licence with an SPDX identifier
Apache-2.0 does not require per-file headers, but a file lifted out of the tree carried no marking at all. One comment line, first (or right after a shebang), on every .py under meshterm/, tests/, packaging/ and scripts/, plus the extensionless SPI bridge; tests/test_spdx.py keeps a new file from landing without one.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-13 13:09:18 -04:00

48 lines
1.5 KiB
Python

# SPDX-License-Identifier: Apache-2.0
"""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:
"""A shift-bank key latches over the release flicker.
An F6-F10 press keeps the lane's shifted read for a grace window, even if the raw
watcher reports Shift already back up — which, per the MCU quirk, it may do
wrongly.
"""
_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()