Files
MeshTerm/tests/test_modifier_watch.py
Jean-Pierre MartineauandClaude Opus 5.5 11b5274b31 Docstrings and comments of the tests are in ASD-STE100
Each test docstring states the behaviour that the test proves, in the
simple present. No assertion message, test id, or other string literal
changed. Four statements now agree with the code: the Trace highlight
stays on the last row, a menu count, and two others.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-06 21:36:50 -04:00

48 lines
1.6 KiB
Python

# SPDX-License-Identifier: Apache-2.0
"""The watcher of the Shift state of the F-key lane: 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 that the watcher set last, with no change 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 flicker at the release.
A press of F6-F10 keeps the shifted state of the lane for a grace window. This is true
also if the raw watcher reports that Shift is already up. Because of a quirk of the MCU,
the watcher can report this 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, and the raw flag never became true
clock[0] += modifier_watch._SHIFT_BANK_GRACE_S - 0.05
assert modifier_watch.shift_down() is True # still in the grace window
clock[0] += 0.1
assert modifier_watch.shift_down() is False # the grace window ended, and Shift is up
finally:
_reset()