From 5e72bd208afe982bf65671ec5b3909690022ea00 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Tue, 1 Oct 2024 18:25:13 +0100 Subject: [PATCH] snapshot test for transparent background --- .../test_transparent_background.svg | 865 ++++++++++++++++++ tests/snapshot_tests/test_snapshots.py | 40 + 2 files changed, 905 insertions(+) create mode 100644 tests/snapshot_tests/__snapshots__/test_snapshots/test_transparent_background.svg diff --git a/tests/snapshot_tests/__snapshots__/test_snapshots/test_transparent_background.svg b/tests/snapshot_tests/__snapshots__/test_snapshots/test_transparent_background.svg new file mode 100644 index 0000000000..f9a8ab6ed6 --- /dev/null +++ b/tests/snapshot_tests/__snapshots__/test_snapshots/test_transparent_background.svg @@ -0,0 +1,865 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + TransparentApp + + + + + + + + + + ▀▀▀▀▀▀▀▀ +▀▀▀▀▀▀ +▀▀▀▀▀ +▀▀▀▀ +▀▀▀ +▀▀ + + + + + + + + + + + + + + +▀▀▀ +▀▀▀▀ +▀▀▀▀▀ +▀▀▀▀▀▀ + + + diff --git a/tests/snapshot_tests/test_snapshots.py b/tests/snapshot_tests/test_snapshots.py index b11d1f5592..a0b290cc93 100644 --- a/tests/snapshot_tests/test_snapshots.py +++ b/tests/snapshot_tests/test_snapshots.py @@ -12,6 +12,7 @@ from textual.binding import Binding from textual.containers import Vertical, VerticalScroll from textual.pilot import Pilot +from textual.renderables.gradient import LinearGradient from textual.screen import ModalScreen, Screen from textual.widgets import ( Button, @@ -2101,6 +2102,7 @@ def action_toggle_console(self) -> None: app = MRE() assert snap_compare(app, press=["space", "space", "z"]) + def test_pop_until_active(snap_compare): """End result should be screen showing 'BASE'""" @@ -2137,6 +2139,7 @@ def action_make_base_active(self) -> None: # End result should be screen showing "BASE" assert snap_compare(app, press=["b"]) + def test_updates_with_auto_refresh(snap_compare): """Regression test for https://github.com/Textualize/textual/issues/5056 @@ -2171,6 +2174,7 @@ def action_toggle_widget(self, widget_type: str) -> None: app = MRE() assert snap_compare(app, press=["z", "z"]) + def test_push_screen_on_mount(snap_compare): """Test pushing (modal) screen immediately on mount, which was not refreshing the base screen. @@ -2226,3 +2230,39 @@ def on_mount(self) -> None: assert snap_compare(app) + +def test_transparent_background(snap_compare): + """Check that a transparent background defers to render(). + + This should display a colorful gradient, filling the screen. + """ + + COLORS = [ + "#881177", + "#aa3355", + "#cc6666", + "#ee9944", + "#eedd00", + "#99dd55", + "#44dd88", + "#22ccbb", + "#00bbcc", + "#0099cc", + "#3366bb", + "#663399", + ] + + class TransparentApp(App): + CSS = """ + Screen { + background: transparent; + } + """ + + def render(self) -> LinearGradient: + """Renders a gradient, when the background is transparent.""" + stops = [(i / (len(COLORS) - 1), c) for i, c in enumerate(COLORS)] + return LinearGradient(30.0, stops) + + app = TransparentApp() + snap_compare(app)