test fixes

This commit is contained in:
Will McGugan
2023-02-04 15:53:00 +01:00
parent fb7c1642bc
commit de2a4fd78d

View File

@@ -10,7 +10,7 @@ from textual.geometry import Region, Size
from textual.strip import Strip from textual.strip import Strip
def _extract_content(lines: list[list[Segment]]): def _extract_content(lines: list[Strip]) -> list[str]:
"""Extract the text content from lines.""" """Extract the text content from lines."""
content = ["".join(segment.text for segment in line) for line in lines] content = ["".join(segment.text for segment in line) for line in lines]
return content return content
@@ -28,9 +28,9 @@ def test_set_dirty():
def test_no_styles(): def test_no_styles():
"""Test that empty style returns the content un-altered""" """Test that empty style returns the content un-altered"""
content = [ content = [
[Segment("foo")], Strip([Segment("foo")]),
[Segment("bar")], Strip([Segment("bar")]),
[Segment("baz")], Strip([Segment("baz")]),
] ]
styles = Styles() styles = Styles()
cache = StylesCache() cache = StylesCache()
@@ -54,9 +54,9 @@ def test_no_styles():
def test_border(): def test_border():
content = [ content = [
[Segment("foo")], Strip([Segment("foo")]),
[Segment("bar")], Strip([Segment("bar")]),
[Segment("baz")], Strip([Segment("baz")]),
] ]
styles = Styles() styles = Styles()
styles.border = ("heavy", "white") styles.border = ("heavy", "white")
@@ -85,9 +85,9 @@ def test_border():
def test_padding(): def test_padding():
content = [ content = [
[Segment("foo")], Strip([Segment("foo")]),
[Segment("bar")], Strip([Segment("bar")]),
[Segment("baz")], Strip([Segment("baz")]),
] ]
styles = Styles() styles = Styles()
styles.padding = 1 styles.padding = 1
@@ -116,9 +116,9 @@ def test_padding():
def test_padding_border(): def test_padding_border():
content = [ content = [
[Segment("foo")], Strip([Segment("foo")]),
[Segment("bar")], Strip([Segment("bar")]),
[Segment("baz")], Strip([Segment("baz")]),
] ]
styles = Styles() styles = Styles()
styles.padding = 1 styles.padding = 1
@@ -150,9 +150,9 @@ def test_padding_border():
def test_outline(): def test_outline():
content = [ content = [
[Segment("foo")], Strip([Segment("foo")]),
[Segment("bar")], Strip([Segment("bar")]),
[Segment("baz")], Strip([Segment("baz")]),
] ]
styles = Styles() styles = Styles()
styles.outline = ("heavy", "white") styles.outline = ("heavy", "white")
@@ -177,9 +177,9 @@ def test_outline():
def test_crop(): def test_crop():
content = [ content = [
[Segment("foo")], Strip([Segment("foo")]),
[Segment("bar")], Strip([Segment("bar")]),
[Segment("baz")], Strip([Segment("baz")]),
] ]
styles = Styles() styles = Styles()
styles.padding = 1 styles.padding = 1
@@ -203,17 +203,17 @@ def test_crop():
assert text_content == expected_text assert text_content == expected_text
def test_dirty_cache(): def test_dirty_cache() -> None:
"""Check that we only render content once or if it has been marked as dirty.""" """Check that we only render content once or if it has been marked as dirty."""
content = [ content = [
[Segment("foo")], Strip([Segment("foo")]),
[Segment("bar")], Strip([Segment("bar")]),
[Segment("baz")], Strip([Segment("baz")]),
] ]
rendered_lines: list[int] = [] rendered_lines: list[int] = []
def get_content_line(y: int) -> list[Segment]: def get_content_line(y: int) -> Strip:
rendered_lines.append(y) rendered_lines.append(y)
return content[y] return content[y]
@@ -232,6 +232,7 @@ def test_dirty_cache():
del rendered_lines[:] del rendered_lines[:]
text_content = _extract_content(lines) text_content = _extract_content(lines)
print(text_content)
expected_text = [ expected_text = [
"┏━━━━━┓", "┏━━━━━┓",
"┃ ┃", "┃ ┃",