Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions tests/test_app_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,16 +283,21 @@ def test_end_response_without_open_is_noop() -> None:


def test_resize_rerenders_ansi() -> None:
"""Changing the width from the width_fn triggers a re-render (cache miss)."""
"""A width change re-renders. The width is re-read each call, so a different
width is a cache miss that yields a fresh render object re-keyed to the new
width — the environment-independent AppUI resize contract. (Whether the terminal
visibly re-wraps depends on the terminal/Rich and is a live-checklist item, so
we assert object identity + the cache key here, not byte-difference of output.)
"""
width = [80]
ui = AppUI(glyphs=GLYPHS, width_fn=lambda: width[0])
# Add enough text that line-wrapping changes between 80 and 40 columns.
ui.show_status("a" * 60 + " " + "b" * 60)
ansi_80 = ui._render_ansi()
width[0] = 40
ansi_40 = ui._render_ansi()
# The ANSI output must differ — different wrapping at different widths.
assert ansi_80 != ansi_40
# Cache miss on the width change → a fresh object, re-keyed to the new width.
assert ansi_40 is not ansi_80
assert ui._cache is not None and ui._cache[0] == 40


def test_cache_hit_at_same_width() -> None:
Expand All @@ -311,7 +316,7 @@ def test_cache_invalidated_on_new_content() -> None:
before = ui._render_ansi()
ui.show_status("second")
after = ui._render_ansi()
assert before != after
assert after is not before # cache invalidated → a fresh render, not the cached object
assert "second" in plain(ui)


Expand Down