MCPcopy
hub / github.com/Textualize/textual / test_dirty_cache

Function test_dirty_cache

tests/test_styles_cache.py:193–271  ·  view source on GitHub ↗

Check that we only render content once or if it has been marked as dirty.

()

Source from the content-addressed store, hash-verified

191
192
193def test_dirty_cache() -> None:
194 """Check that we only render content once or if it has been marked as dirty."""
195
196 content = [
197 Strip([Segment("foo")]),
198 Strip([Segment("bar")]),
199 Strip([Segment("baz")]),
200 ]
201 rendered_lines: list[int] = []
202
203 def get_content_line(y: int) -> Strip:
204 rendered_lines.append(y)
205 return content[y]
206
207 styles = Styles()
208 styles.padding = 1
209 styles.border = ("heavy", "white")
210 cache = StylesCache()
211 lines = cache.render(
212 styles,
213 Size(7, 7),
214 Color.parse("blue"),
215 Color.parse("green"),
216 get_content_line,
217 [],
218 None,
219 None,
220 content_size=Size(3, 3),
221 )
222 assert rendered_lines == [0, 1, 2]
223 del rendered_lines[:]
224
225 text_content = _extract_content(lines)
226
227 expected_text = [
228 "┏━━━━━┓",
229 "┃ ┃",
230 "┃ foo ┃",
231 "┃ bar ┃",
232 "┃ baz ┃",
233 "┃ ┃",
234 "┗━━━━━┛",
235 ]
236 assert text_content == expected_text
237
238 # Re-render styles, check that content was not requested
239 lines = cache.render(
240 styles,
241 Size(7, 7),
242 Color.parse("blue"),
243 Color.parse("green"),
244 get_content_line,
245 [],
246 None,
247 None,
248 content_size=Size(3, 3),
249 )
250 assert rendered_lines == []

Callers

nothing calls this directly

Calls 9

renderMethod · 0.95
set_dirtyMethod · 0.95
StripClass · 0.90
StylesClass · 0.90
StylesCacheClass · 0.90
SizeClass · 0.90
RegionClass · 0.90
_extract_contentFunction · 0.85
parseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…