diff --git a/meshterm/tools/preferences.py b/meshterm/tools/preferences.py index 1dfccf3..4afc5e5 100644 --- a/meshterm/tools/preferences.py +++ b/meshterm/tools/preferences.py @@ -125,7 +125,7 @@ class PreferencesTool(Tool): if changes: prefs.save() - if scripted and applied is not None and any(op[0] in ("set", "reset") for op in ops): + if scripted and any(op[0] in ("set", "reset") for op in ops): blocks.append(_written(applied, prefs)) plural = "" if changes == 1 else "s" diff --git a/meshterm/ui/fields.py b/meshterm/ui/fields.py index 1f89ae2..c1b0835 100644 --- a/meshterm/ui/fields.py +++ b/meshterm/ui/fields.py @@ -451,10 +451,17 @@ def _flag_cell(value: bool | None) -> str: def _time(value: Any, *, absent: str) -> str: - """Render a time in whichever language this run speaks (see :func:`when`).""" - if isinstance(value, datetime) or value is None: - return script.stamp(value) if _absolute() else script.age(value, absent=absent) - return normalise(value) # pragma: no cover - a row holding something else is a bug + """Render a time in whichever language this run speaks (see :func:`when`). + + ``absent`` survives the switch to timestamps, because it is not a rendering choice: + ``never`` says the event has not happened, and ``--absolute`` was asked for a different + *form* of time, not for one fewer fact. + """ + if not isinstance(value, datetime) and value is not None: + return normalise(value) # pragma: no cover - a row holding something else is a bug + if value is None: + return absent + return script.stamp(value) if _absolute() else script.age(value, absent=absent) def _absolute() -> bool: diff --git a/tests/test_cli_contract.py b/tests/test_cli_contract.py index fbc6166..199bd2d 100644 --- a/tests/test_cli_contract.py +++ b/tests/test_cli_contract.py @@ -269,10 +269,12 @@ def test_contacts_names_every_node_bare_and_ages_every_time(run) -> None: # noq age = line.split()[2] assert age in ("now", "never") or age[-1] in "mhdw" + # `--absolute` asks for a different *form* of time, not for one fewer fact, so + # `never` survives it: a node that has never been heard has no instant to print. absolute = result_lines(run("--absolute", "contacts"))[1:] for line in absolute: stamp = line.split()[2] - assert stamp == "-" or stamp[:4].isdigit() + assert stamp in ("-", "never") or stamp[:4].isdigit() def test_contacts_never_elides_a_key(run) -> None: # noqa: ANN001