Files
MeshTerm/tests/conftest.py
T
Jean-Pierre MartineauandClaude Sonnet 5 8f1fba135e Platform seam: meshterm/platforms.py, --platform flag, dual-platform gallery
One frozen Platform spec (REGULAR/PICOCALC), resolved once at boot
(--platform flag > MESHTERM_PLATFORM env > /proc/device-tree/model
auto-detect > REGULAR) and read via get_platform()/set_platform() -
never a stale `from platforms import PLATFORM`, which the module
docstring calls out. `meshterm platform` reports the resolution and
everything it looked at.

Wires the two correctness bindings that matter before any flavour
work lands: width_reclaim off on PicoCalc's exact-width console
(session._reclaim_last_column, env override still wins), and the
emoji-width calibration probe skipped outright when a platform never
draws emoji.

tests/test_gallery.py renders all 16 screens the interactive menu
opens against REGULAR (72x24) and PICOCALC (53x26 live floor, 53x40
lux case), asserting no line overflows its platform - 35 passing
cases, 13 xfailed as a real P6 worklist (contacts, map, walk,
livefeed, remote_cli, path_composer). Also caught and left alone: the
map screen's footer hint already overflowed the *existing* 72-col
standard before this seam existed, unrelated to picocalc - xfailed
rather than fixed as a drive-by. tests/test_platforms.py unit-tests
the module directly; conftest.py gained an autouse fixture resetting
the platform between tests.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-01 02:18:22 -04:00

60 lines
2.3 KiB
Python

"""Shared fixtures and helpers: plain-text screen reading, and pinned path rendering.
:func:`plain` is THE way a test reads a rendered screen — every screen test needs the
same move (strip the ANSI colour escapes, join the rendered lines) before it can assert
on content, and each file re-deriving it is how the copies drift.
The powerline verdict is environmental — the suite may run inside VS Code or Windows
Terminal (both chip-capable) or a bare CI shell (not) — and screen assertions must
not change with the developer's glass. ``MESHTERM_POWERLINE=0`` is the supported pin;
the cached verdict is cleared around each test so no ordering leaks it. Powerline-
specific tests pass explicit modes or monkeypatch the widget's own switch.
"""
from __future__ import annotations
import re
from typing import Iterable, Iterator, Union
import pytest
from meshterm.platforms import REGULAR, set_platform
from meshterm.ui.termfont import powerline_support
#: ANSI SGR escapes — the colour runs a rendered line carries between its characters.
_ANSI = re.compile(r"\x1b\[[0-9;]*m")
def plain(rendered: Union[str, Iterable[str]]) -> str:
"""The plain-text form of rendered screen output, for content assertions.
Takes what a render handed back — a list of ANSI lines (joined with newlines) or a
single already-joined string — and strips the colour escapes, so assertions read
the screen the way a viewer does.
"""
if not isinstance(rendered, str):
rendered = "\n".join(rendered)
return _ANSI.sub("", rendered)
@pytest.fixture(autouse=True)
def _plain_path_rendering(monkeypatch: pytest.MonkeyPatch) -> Iterator[None]:
monkeypatch.setenv("MESHTERM_POWERLINE", "0")
powerline_support.cache_clear()
yield
powerline_support.cache_clear()
@pytest.fixture(autouse=True)
def _reset_platform() -> Iterator[None]:
"""Every test starts and ends on :data:`~meshterm.platforms.REGULAR`.
A test that calls ``set_platform(PICOCALC)`` (directly, or via the gallery harness)
can't leak that choice into whatever runs next — regular is the suite's baseline, the
same way it is the default for a process that never passes ``--platform``/
``MESHTERM_PLATFORM`` (see :mod:`meshterm.platforms`).
"""
set_platform(REGULAR)
yield
set_platform(REGULAR)