Check that we only render content once or if it has been marked as dirty.
()
| 191 | |
| 192 | |
| 193 | def 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 == [] |
nothing calls this directly
no test coverage detected
searching dependent graphs…