From b055673eda57f402362bdbbb831739ddbdc448af Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Sat, 18 Jan 2025 17:28:46 +0000 Subject: [PATCH] test fix, fix outline --- src/textual/_styles_cache.py | 4 ++-- src/textual/strip.py | 4 +++- .../snapshot_apps/ansi_mapping.py | 21 ++++++++++--------- tests/snapshot_tests/test_snapshots.py | 20 +++++++++++------- tests/test_styles_cache.py | 8 +++++-- 5 files changed, 35 insertions(+), 22 deletions(-) diff --git a/src/textual/_styles_cache.py b/src/textual/_styles_cache.py index d84d469ad3..e64917940e 100644 --- a/src/textual/_styles_cache.py +++ b/src/textual/_styles_cache.py @@ -488,9 +488,9 @@ def post(segments: Iterable[Segment]) -> Iterable[Segment]: elif outline_left or outline_right: # Lines in side outline - left_style = Style(background=(base_background + outline_left_color)) + left_style = Style(foreground=(base_background + outline_left_color)) left = get_box(outline_left, inner, outer, left_style)[1][0] - right_style = Style(background=(base_background + outline_right_color)) + right_style = Style(foreground=(base_background + outline_right_color)) right = get_box(outline_right, inner, outer, right_style)[1][2] line = line_trim(list(line), outline_left != "", outline_right != "") if outline_left and outline_right: diff --git a/src/textual/strip.py b/src/textual/strip.py index feac765675..a010573b2a 100644 --- a/src/textual/strip.py +++ b/src/textual/strip.py @@ -112,7 +112,6 @@ def __init__( assert get_line_length(self._segments) == cell_length def __rich_repr__(self) -> rich.repr.Result: - return yield self._segments yield self.cell_length @@ -342,6 +341,9 @@ def adjust_cell_length(self, cell_length: int, style: Style | None = None) -> St A new strip with the supplied cell length. """ + if self.cell_length == cell_length: + return self + cache_key = (cell_length, style) cached_strip = self._line_length_cache.get(cache_key) if cached_strip is not None: diff --git a/tests/snapshot_tests/snapshot_apps/ansi_mapping.py b/tests/snapshot_tests/snapshot_apps/ansi_mapping.py index 4775c1e05d..3ca591718a 100644 --- a/tests/snapshot_tests/snapshot_apps/ansi_mapping.py +++ b/tests/snapshot_tests/snapshot_apps/ansi_mapping.py @@ -5,19 +5,20 @@ class AnsiMappingApp(App[None]): def compose(self) -> ComposeResult: ansi_colors = [ - "red", - "green", - "yellow", - "blue", - "magenta", - "cyan", - "white", - "black", + "ansi_red", + "ansi_green", + "ansi_yellow", + "ansi_blue", + "ansi_magenta", + "ansi_cyan", + "ansi_white", + "ansi_black", ] yield Label("Foreground & background") for color in ansi_colors: - yield Label(f"[{color}]{color}[/]") - yield Label(f"[dim {color}]dim {color}[/]") + color_name = color.partition("_")[-1] + yield Label(f"[{color}]{color_name}[/]") + yield Label(f"[dim {color}]dim {color_name}[/]") app = AnsiMappingApp() diff --git a/tests/snapshot_tests/test_snapshots.py b/tests/snapshot_tests/test_snapshots.py index 892d897a30..924072e8ba 100644 --- a/tests/snapshot_tests/test_snapshots.py +++ b/tests/snapshot_tests/test_snapshots.py @@ -183,7 +183,8 @@ def on_mount(self) -> None: def test_input_cursor(snap_compare): """The first input should say こんにちは. The second input should say こんにちは, with a cursor on the final character (double width). - Note that this might render incorrectly in the SVG output - the letters may overlap.""" + Note that this might render incorrectly in the SVG output - the letters may overlap. + """ class InputApp(App[None]): def compose(self) -> ComposeResult: @@ -2078,7 +2079,7 @@ class ANSIApp(App): """ def compose(self) -> ComposeResult: - yield Label("[red]Red[/] [magenta]Magenta[/]") + yield Label("[ansi_red]Red[/] [ansi_magenta]Magenta[/]") app = ANSIApp(ansi_color=True) assert snap_compare(app) @@ -2886,7 +2887,8 @@ async def run_before(pilot: Pilot) -> None: def test_markup_command_list(snap_compare): """Regression test for https://github.com/Textualize/textual/issues/5276 - You should see a command list, with console markup applied to the action name and help text.""" + You should see a command list, with console markup applied to the action name and help text. + """ class MyApp(App): def on_mount(self) -> None: @@ -2945,7 +2947,8 @@ def on_resize(self) -> None: def test_add_remove_tabs(snap_compare): """Regression test for https://github.com/Textualize/textual/issues/5215 - You should see a TabbedContent with three panes, entitled 'tab-2', 'New tab' and 'New tab'""" + You should see a TabbedContent with three panes, entitled 'tab-2', 'New tab' and 'New tab' + """ class ExampleApp(App): BINDINGS = [ @@ -2992,7 +2995,8 @@ async def run_before(pilot: Pilot) -> None: def test_disable_command_palette(snap_compare): """Test command palette may be disabled by check_action. - You should see a footer with an enabled binding, and the command palette binding greyed out.""" + You should see a footer with an enabled binding, and the command palette binding greyed out. + """ class FooterApp(App): BINDINGS = [("b", "bell", "Bell")] @@ -3047,7 +3051,8 @@ def compose(self) -> ComposeResult: def test_dock_align(snap_compare): """Regression test for https://github.com/Textualize/textual/issues/5345 - You should see a blue panel aligned to the top right of the screen, with a centered button.""" + You should see a blue panel aligned to the top right of the screen, with a centered button. + """ class MainContainer(Static): def compose(self): @@ -3335,7 +3340,8 @@ def compose(self) -> ComposeResult: def test_arbitrary_selection_double_cell(snap_compare): """Check that selection understands double width cells. - You should see a smiley face followed by 'Hello World!', where Hello is highlighted.""" + You should see a smiley face followed by 'Hello World!', where Hello is highlighted. + """ class LApp(App): def compose(self) -> ComposeResult: diff --git a/tests/test_styles_cache.py b/tests/test_styles_cache.py index 18e4f11697..615ed70aa6 100644 --- a/tests/test_styles_cache.py +++ b/tests/test_styles_cache.py @@ -40,17 +40,21 @@ def test_no_styles(): Color.parse("blue"), Color.parse("green"), content.__getitem__, - "", - "", + None, + None, content_size=Size(3, 3), ) style = Style.from_color(bgcolor=Color.parse("green").rich_color) + expected = [ Strip([Segment("foo", style)], 3), Strip([Segment("bar", style)], 3), Strip([Segment("baz", style)], 3), ] + print(lines[0]) + print(expected[0]) + assert lines == expected