code
stringlengths
26
870k
docstring
stringlengths
1
65.6k
func_name
stringlengths
1
194
language
stringclasses
1 value
repo
stringlengths
8
68
path
stringlengths
5
194
url
stringlengths
46
254
license
stringclasses
4 values
def test_sort_children(snap_compare): """Test sort_children method.""" assert snap_compare(SNAPSHOT_APPS_DIR / "sort_children.py", terminal_size=(80, 25))
Test sort_children method.
test_sort_children
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_app_blur(snap_compare): """Test Styling after receiving an AppBlur message.""" async def run_before(pilot) -> None: await pilot.pause() # Allow the AppBlur message to get processed. assert snap_compare(SNAPSHOT_APPS_DIR / "app_blur.py", run_before=run_before)
Test Styling after receiving an AppBlur message.
test_app_blur
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_placeholder_disabled(snap_compare): """Test placeholder with diabled set to True.""" assert snap_compare(SNAPSHOT_APPS_DIR / "placeholder_disabled.py")
Test placeholder with diabled set to True.
test_placeholder_disabled
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_listview_index(snap_compare): """Tests that ListView scrolls correctly after updating its index.""" assert snap_compare(SNAPSHOT_APPS_DIR / "listview_index.py")
Tests that ListView scrolls correctly after updating its index.
test_listview_index
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_button_widths(snap_compare): """Test that button widths expand auto containers as expected.""" # https://github.com/Textualize/textual/issues/4024 assert snap_compare(SNAPSHOT_APPS_DIR / "button_widths.py")
Test that button widths expand auto containers as expected.
test_button_widths
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_example_calculator(snap_compare): """Test the calculator example.""" assert snap_compare(EXAMPLES_DIR / "calculator.py")
Test the calculator example.
test_example_calculator
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_example_color_command(snap_compare): """Test the color_command example.""" assert snap_compare( EXAMPLES_DIR / "color_command.py", press=[App.COMMAND_PALETTE_BINDING, "r", "e", "d", "enter"], )
Test the color_command example.
test_example_color_command
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_example_dictionary(snap_compare): """Test the dictionary example (basic layout test).""" async def run_before(pilot): pilot.app.query(Input).first().cursor_blink = False assert snap_compare(EXAMPLES_DIR / "dictionary.py", run_before=run_before)
Test the dictionary example (basic layout test).
test_example_dictionary
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_example_five_by_five(snap_compare): """Test the five_by_five example.""" assert snap_compare(EXAMPLES_DIR / "five_by_five.py")
Test the five_by_five example.
test_example_five_by_five
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_example_json_tree(snap_compare): """Test the json_tree example.""" assert snap_compare( EXAMPLES_DIR / "json_tree.py", press=["a", "down", "enter", "down", "down", "enter"], )
Test the json_tree example.
test_example_json_tree
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_example_markdown(snap_compare): """Test the markdown example.""" assert snap_compare(EXAMPLES_DIR / "markdown.py")
Test the markdown example.
test_example_markdown
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_example_merlin(snap_compare): """Test the merlin example.""" on_switches = {2, 3, 5, 8} async def run_before(pilot): pilot.app.query_one("Timer").running = False # This will freeze the clock. for switch in pilot.app.query("LabelSwitch"): switch.query_one("Switch").value = switch.switch_no in on_switches await pilot.pause() assert snap_compare(EXAMPLES_DIR / "merlin.py", run_before=run_before)
Test the merlin example.
test_example_merlin
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_example_pride(snap_compare): """Test the pride example.""" assert snap_compare(EXAMPLES_DIR / "pride.py")
Test the pride example.
test_example_pride
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_button_with_console_markup(snap_compare): """Regression test for https://github.com/Textualize/textual/issues/4328""" assert snap_compare(SNAPSHOT_APPS_DIR / "button_markup.py")
Regression test for https://github.com/Textualize/textual/issues/4328
test_button_with_console_markup
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_width_100(snap_compare): """Regression test for https://github.com/Textualize/textual/issues/4360""" assert snap_compare(SNAPSHOT_APPS_DIR / "width_100.py")
Regression test for https://github.com/Textualize/textual/issues/4360
test_width_100
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_hatch(snap_compare): """Test hatch styles.""" assert snap_compare(SNAPSHOT_APPS_DIR / "hatch.py")
Test hatch styles.
test_hatch
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_rules(snap_compare): """Test rules.""" assert snap_compare(SNAPSHOT_APPS_DIR / "rules.py")
Test rules.
test_rules
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_grid_auto(snap_compare): """Test grid with keyline and auto-dimension.""" # https://github.com/Textualize/textual/issues/4678 assert snap_compare(SNAPSHOT_APPS_DIR / "grid_auto.py")
Test grid with keyline and auto-dimension.
test_grid_auto
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_footer_compact(snap_compare): """Test Footer in the compact style""" assert snap_compare(SNAPSHOT_APPS_DIR / "footer_toggle_compact.py")
Test Footer in the compact style
test_footer_compact
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_footer_compact_with_hover(snap_compare): """Test Footer in the compact style when the mouse is hovering over a keybinding""" async def run_before(pilot) -> None: await pilot.hover("Footer", offset=(0, 0)) assert snap_compare( SNAPSHOT_APPS_DIR / "footer_toggle_compact.py", run_before=run_before )
Test Footer in the compact style when the mouse is hovering over a keybinding
test_footer_compact_with_hover
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_footer_standard_after_reactive_change(snap_compare): """Test Footer in the standard style after `compact` reactive change""" assert snap_compare( SNAPSHOT_APPS_DIR / "footer_toggle_compact.py", press=["ctrl+t"] )
Test Footer in the standard style after `compact` reactive change
test_footer_standard_after_reactive_change
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_footer_standard_with_hover(snap_compare): """Test Footer in the standard style when the mouse is hovering over a keybinding""" async def run_before(pilot) -> None: await pilot.press("ctrl+t") await pilot.hover("Footer", offset=(0, 0)) assert snap_compare( SNAPSHOT_APPS_DIR / "footer_toggle_compact.py", run_before=run_before )
Test Footer in the standard style when the mouse is hovering over a keybinding
test_footer_standard_with_hover
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_footer_classic_styling(snap_compare): """Regression test for https://github.com/Textualize/textual/issues/4557""" assert snap_compare(SNAPSHOT_APPS_DIR / "footer_classic_styling.py")
Regression test for https://github.com/Textualize/textual/issues/4557
test_footer_classic_styling
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_bindings_screen_overrides_show(snap_compare): """Regression test for https://github.com/Textualize/textual/issues/4382""" assert snap_compare(SNAPSHOT_APPS_DIR / "bindings_screen_overrides_show.py")
Regression test for https://github.com/Textualize/textual/issues/4382
test_bindings_screen_overrides_show
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_scroll_visible_with_margin(snap_compare): """Regression test for https://github.com/Textualize/textual/issues/2181""" assert snap_compare(SNAPSHOT_APPS_DIR / "scroll_visible_margin.py", press=["x"])
Regression test for https://github.com/Textualize/textual/issues/2181
test_scroll_visible_with_margin
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_programmatic_disable_button(snap_compare): """Regression test for https://github.com/Textualize/textual/issues/3130""" async def run_before(pilot: Pilot) -> None: await pilot.hover("#disable-btn") await pilot.press("space") assert snap_compare( SNAPSHOT_APPS_DIR / "programmatic_disable_button.py", run_before=run_before )
Regression test for https://github.com/Textualize/textual/issues/3130
test_programmatic_disable_button
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_toggle_style_order(snap_compare): """Regression test for https://github.com/Textualize/textual/issues/3421""" assert snap_compare(SNAPSHOT_APPS_DIR / "toggle_style_order.py")
Regression test for https://github.com/Textualize/textual/issues/3421
test_toggle_style_order
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_component_text_opacity(snap_compare): """Regression test for https://github.com/Textualize/textual/issues/3413""" assert snap_compare(SNAPSHOT_APPS_DIR / "component_text_opacity.py")
Regression test for https://github.com/Textualize/textual/issues/3413
test_component_text_opacity
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_progress_gradient(snap_compare): """Test gradient parameter on ProgressBar""" assert snap_compare(SNAPSHOT_APPS_DIR / "progress_gradient.py")
Test gradient parameter on ProgressBar
test_progress_gradient
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_recompose_in_mount(snap_compare): """Regression test for https://github.com/Textualize/textual/issues/4799""" assert snap_compare(SNAPSHOT_APPS_DIR / "recompose_on_mount.py")
Regression test for https://github.com/Textualize/textual/issues/4799
test_recompose_in_mount
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_remove_tab_no_animation(snap_compare): """Regression test for https://github.com/Textualize/textual/issues/4814""" assert snap_compare(SNAPSHOT_APPS_DIR / "remove_tab.py", press=["space"])
Regression test for https://github.com/Textualize/textual/issues/4814
test_remove_tab_no_animation
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_auto_height_scrollbar(snap_compare): """Regression test for https://github.com/Textualize/textual/issues/4778""" assert snap_compare(SNAPSHOT_APPS_DIR / "data_table_auto_height.py")
Regression test for https://github.com/Textualize/textual/issues/4778
test_auto_height_scrollbar
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_bind_override(snap_compare): """Regression test for https://github.com/Textualize/textual/issues/4755""" assert snap_compare(SNAPSHOT_APPS_DIR / "bind_override.py")
Regression test for https://github.com/Textualize/textual/issues/4755
test_bind_override
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_command_palette_dismiss_escape(snap_compare): """Regression test for https://github.com/Textualize/textual/issues/4856""" async def run_before(pilot: Pilot): await pilot.press(App.COMMAND_PALETTE_BINDING) await pilot.pause() await pilot.press("escape") assert snap_compare( SNAPSHOT_APPS_DIR / "command_palette_dismiss.py", run_before=run_before )
Regression test for https://github.com/Textualize/textual/issues/4856
test_command_palette_dismiss_escape
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_command_palette_dismiss_escape_no_results(snap_compare): """Regression test for https://github.com/Textualize/textual/issues/4856""" async def run_before(pilot: Pilot): await pilot.press(App.COMMAND_PALETTE_BINDING) await pilot.pause() await pilot.press(*"foo") await pilot.app.workers.wait_for_complete() await pilot.press("escape") assert snap_compare( SNAPSHOT_APPS_DIR / "command_palette_dismiss.py", run_before=run_before )
Regression test for https://github.com/Textualize/textual/issues/4856
test_command_palette_dismiss_escape_no_results
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_command_palette_key_change(snap_compare): """Regression test for https://github.com/Textualize/textual/issues/4887""" assert snap_compare(SNAPSHOT_APPS_DIR / "command_palette_key.py")
Regression test for https://github.com/Textualize/textual/issues/4887
test_command_palette_key_change
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_split(snap_compare): """Test split rule.""" assert snap_compare(SNAPSHOT_APPS_DIR / "split.py", terminal_size=(100, 30))
Test split rule.
test_split
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_system_commands(snap_compare): """The system commands should appear in the command palette.""" class SimpleApp(App): def compose(self) -> ComposeResult: input = Input() input.cursor_blink = False yield input app = SimpleApp() app.animation_level = "none" assert snap_compare( app, terminal_size=(100, 30), press=["ctrl+p"], )
The system commands should appear in the command palette.
test_system_commands
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_help_panel(snap_compare): """Test help panel.""" class HelpPanelApp(App): def compose(self) -> ComposeResult: yield Input() async def run_before(pilot: Pilot): pilot.app.query(Input).first().cursor_blink = False await pilot.press(App.COMMAND_PALETTE_BINDING) await pilot.pause() await pilot.press(*"keys") await pilot.press("enter") await pilot.app.workers.wait_for_complete() assert snap_compare(HelpPanelApp(), terminal_size=(100, 30), run_before=run_before)
Test help panel.
test_help_panel
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_scroll_page_down(snap_compare): """Regression test for https://github.com/Textualize/textual/issues/4914""" # Should show 25 at the top assert snap_compare( SNAPSHOT_APPS_DIR / "scroll_page.py", press=["pagedown"], terminal_size=(80, 25) )
Regression test for https://github.com/Textualize/textual/issues/4914
test_scroll_page_down
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_maximize(snap_compare): """Check that maximize isolates a single widget.""" class MaximizeApp(App): BINDINGS = [("m", "screen.maximize", "maximize focused widget")] def compose(self) -> ComposeResult: yield Button("Hello") yield Button("World") yield Footer() assert snap_compare(MaximizeApp(), press=["m"])
Check that maximize isolates a single widget.
test_maximize
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_maximize_container(snap_compare): """Check maximizing a widget in a maximizeable container, maximizes the container.""" class FormContainer(Vertical): ALLOW_MAXIMIZE = True DEFAULT_CSS = """ FormContainer { width: 50%; border: blue; } """ class MaximizeApp(App): BINDINGS = [("m", "screen.maximize", "maximize focused widget")] def compose(self) -> ComposeResult: with FormContainer(): yield Button("Hello") yield Button("World") yield Footer() assert snap_compare(MaximizeApp(), press=["m"])
Check maximizing a widget in a maximizeable container, maximizes the container.
test_maximize_container
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_check_consume_keys(snap_compare): """Check that when an Input is focused it hides printable keys from the footer.""" class MyApp(App): BINDINGS = [ Binding(key="q", action="quit", description="Quit the app"), Binding( key="question_mark", action="help", description="Show help screen", key_display="?", ), Binding(key="delete", action="delete", description="Delete the thing"), Binding(key="j", action="down", description="Scroll down", show=False), ] def compose(self) -> ComposeResult: yield Input(placeholder="First Name") yield Input(placeholder="Last Name") yield Switch() yield Footer() assert snap_compare(MyApp())
Check that when an Input is focused it hides printable keys from the footer.
test_check_consume_keys
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_escape_to_minimize(snap_compare): """Check escape minimizes. Regression test for https://github.com/Textualize/textual/issues/4939""" TEXT = """\ def hello(name): print("hello" + name) def goodbye(name): print("goodbye" + name) """ class TextAreaExample(App): BINDINGS = [("ctrl+m", "screen.maximize")] CSS = """ Screen { align: center middle; } #code-container { width: 20; height: 10; } """ def compose(self) -> ComposeResult: with Vertical(id="code-container"): text_area = TextArea.code_editor(TEXT) text_area.cursor_blink = False yield text_area # ctrl+m to maximize, escape should minimize assert snap_compare(TextAreaExample(), press=["ctrl+m", "escape"])
Check escape minimizes. Regression test for https://github.com/Textualize/textual/issues/4939
test_escape_to_minimize
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_escape_to_minimize_disabled(snap_compare): """Set escape to minimize disabled by app""" TEXT = """\ def hello(name): print("hello" + name) def goodbye(name): print("goodbye" + name) """ class TextAreaExample(App): # Disables escape to minimize ESCAPE_TO_MINIMIZE = False BINDINGS = [("ctrl+m", "screen.maximize")] CSS = """ Screen { align: center middle; } #code-container { width: 20; height: 10; } """ def compose(self) -> ComposeResult: with Vertical(id="code-container"): text_area = TextArea.code_editor(TEXT) text_area.cursor_blink = False yield text_area # ctrl+m to maximize, escape should *not* minimize assert snap_compare(TextAreaExample(), press=["ctrl+m", "escape"])
Set escape to minimize disabled by app
test_escape_to_minimize_disabled
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_escape_to_minimize_screen_override(snap_compare): """Test escape to minimize can be overridden by the screen""" TEXT = """\ def hello(name): print("hello" + name) def goodbye(name): print("goodbye" + name) """ class TestScreen(Screen): # Disabled on the screen ESCAPE_TO_MINIMIZE = True def compose(self) -> ComposeResult: with Vertical(id="code-container"): text_area = TextArea.code_editor(TEXT) text_area.cursor_blink = False yield text_area class TextAreaExample(App): # Enabled on app ESCAPE_TO_MINIMIZE = False BINDINGS = [("ctrl+m", "screen.maximize")] CSS = """ Screen { align: center middle; } #code-container { width: 20; height: 10; } """ def compose(self) -> ComposeResult: yield Label("You are looking at the default screen") def on_mount(self) -> None: self.push_screen(TestScreen()) # ctrl+m to maximize, escape *should* minimize assert snap_compare(TextAreaExample(), press=["ctrl+m", "escape"])
Test escape to minimize can be overridden by the screen
test_escape_to_minimize_screen_override
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_app_focus_style(snap_compare): """Test that app blur style can be selected.""" class FocusApp(App): CSS = """ Label { padding: 1 2; margin: 1 2; background: $panel; border: $primary; } App:focus { .blurred { visibility: hidden; } } App:blur { .focussed { visibility: hidden; } } """ def compose(self) -> ComposeResult: yield Label("BLURRED", classes="blurred") yield Label("FOCUSED", classes="focussed") async def run_before(pilot: Pilot) -> None: pilot.app.post_message(events.AppBlur()) await pilot.pause() assert snap_compare(FocusApp(), run_before=run_before)
Test that app blur style can be selected.
test_app_focus_style
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_ansi(snap_compare): """Test ANSI colors.""" # It is actually impossible to tell from the SVG that ANSI colors were actually used # This snapshot test exists as a canary to check if ansi_colors have broken class ANSIApp(App): CSS = """ Label { background: ansi_blue; border: solid ansi_white; } """ def compose(self) -> ComposeResult: yield Label("[ansi_red]Red[/] [ansi_magenta]Magenta[/]") app = ANSIApp(ansi_color=True) assert snap_compare(app)
Test ANSI colors.
test_ansi
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_ansi_command_palette(snap_compare): """Test command palette on top of ANSI colors.""" class CommandPaletteApp(App[None]): SUSPENDED_SCREEN_CLASS = "-screen-suspended" CSS = """ Label { width: 1fr; } """ def compose(self) -> ComposeResult: yield Label("[ansi_red]Red[/] [ansi_magenta]Magenta[/] " * 200) def on_mount(self) -> None: self.action_command_palette() app = CommandPaletteApp(ansi_color=True) assert snap_compare(app)
Test command palette on top of ANSI colors.
test_ansi_command_palette
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_disabled(snap_compare): """Regression test for https://github.com/Textualize/textual/issues/5028""" class DisabledApp(App[None]): CSS = """ Log { height: 4; } RichLog { height: 4; } DataTable { height: 4; } OptionList { height: 4; } SelectionList { height: 4; } """ def compose(self) -> ComposeResult: yield Label("Labels don't have a disabled state", disabled=True) yield Log(disabled=True) yield RichLog(disabled=True) yield DataTable(disabled=True) yield OptionList("you", "can't", "select", "me", disabled=True) yield SelectionList(("Simple SelectionList", "", False), disabled=True) def on_mount(self) -> None: self.query_one(Log).write("I am disabled") self.query_one(RichLog).write("I am disabled") self.query_one(DataTable).add_columns("Foo", "Bar") self.query_one(DataTable).add_row("Also", "disabled") app = DisabledApp() assert snap_compare(app)
Regression test for https://github.com/Textualize/textual/issues/5028
test_disabled
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_keymap_bindings_display_footer_and_help_panel(snap_compare): """Bindings overridden by the Keymap are shown as expected in the Footer and help panel. Testing that the keys work as expected is done elsewhere. Footer should show bindings `k` to Increment, and `down` to Decrement. Key panel should show bindings `k, plus` to increment, and `down, minus, j` to decrement. """ class Counter(App[None]): BINDINGS = [ Binding( key="i,up", action="increment", description="Increment", id="app.increment", ), Binding( key="d,down", action="decrement", description="Decrement", id="app.decrement", ), ] def compose(self) -> ComposeResult: yield Label("Counter") yield Footer() def on_mount(self) -> None: self.action_show_help_panel() self.set_keymap( { "app.increment": "k,plus", "app.decrement": "down,minus,j", } ) assert snap_compare(Counter())
Bindings overridden by the Keymap are shown as expected in the Footer and help panel. Testing that the keys work as expected is done elsewhere. Footer should show bindings `k` to Increment, and `down` to Decrement. Key panel should show bindings `k, plus` to increment, and `down, minus, j` to decrement.
test_keymap_bindings_display_footer_and_help_panel
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_keymap_bindings_key_display(snap_compare): """If a default binding in `BINDINGS` has a key_display, it should be reset when that binding is overridden by a Keymap. The key_display should be taken from `App.get_key_display`, so in this case it should be "THIS IS CORRECT" in the Footer and help panel, not "INCORRECT". """ class MyApp(App[None]): BINDINGS = [ Binding( key="i,up", action="increment", description="Increment", id="app.increment", key_display="INCORRECT", ), ] def compose(self) -> ComposeResult: yield Label("Check the footer and help panel") yield Footer() def on_mount(self) -> None: self.action_show_help_panel() self.set_keymap({"app.increment": "k,plus,j,l"}) def get_key_display(self, binding: Binding) -> str: if binding.id == "app.increment": return "correct" return super().get_key_display(binding) assert snap_compare(MyApp())
If a default binding in `BINDINGS` has a key_display, it should be reset when that binding is overridden by a Keymap. The key_display should be taken from `App.get_key_display`, so in this case it should be "THIS IS CORRECT" in the Footer and help panel, not "INCORRECT".
test_keymap_bindings_key_display
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_missing_new_widgets(snap_compare): """Regression test for https://github.com/Textualize/textual/issues/5024""" class MRE(App): BINDINGS = [("z", "toggle_console", "Console")] CSS = """ RichLog { border-top: dashed blue; height: 6; } .hidden { display: none; } """ def compose(self): yield VerticalScroll() yield ProgressBar( classes="hidden" ) # removing or displaying this widget prevents the bug yield Footer() # clicking "Console" in the footer prevents the bug yield RichLog(classes="hidden") def on_ready(self) -> None: self.query_one(RichLog).write("\n".join(f"line #{i}" for i in range(5))) def action_toggle_console(self) -> None: self.query_one(RichLog).toggle_class("hidden") app = MRE() assert snap_compare(app, press=["space", "space", "z"])
Regression test for https://github.com/Textualize/textual/issues/5024
test_missing_new_widgets
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_pop_until_active(snap_compare): """End result should be screen showing 'BASE'""" class BaseScreen(Screen): def compose(self) -> ComposeResult: yield Label("BASE") class FooScreen(Screen): def compose(self) -> ComposeResult: yield Label("Foo") class BarScreen(Screen): BINDINGS = [("b", "app.make_base_active")] def compose(self) -> ComposeResult: yield Label("Bar") class PopApp(App): SCREENS = {"base": BaseScreen} async def on_mount(self) -> None: # Push base await self.push_screen("base") # Push two screens await self.push_screen(FooScreen()) await self.push_screen(BarScreen()) def action_make_base_active(self) -> None: self.get_screen("base").pop_until_active() app = PopApp() # App will push three screens # Pressing "b" will call pop_until_active, and pop two screens # End result should be screen showing "BASE" assert snap_compare(app, press=["b"])
End result should be screen showing 'BASE
test_pop_until_active
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_updates_with_auto_refresh(snap_compare): """Regression test for https://github.com/Textualize/textual/issues/5056 After hiding and unhiding the RichLog, you should be able to see 1.5 fully rendered placeholder widgets. Prior to this fix, the bottom portion of the screen did not refresh after the RichLog was hidden/unhidden while in the presence of the auto-refreshing ProgressBar widget. """ class MRE(App): BINDINGS = [ ("z", "toggle_widget('RichLog')", "Console"), ] CSS = """ Placeholder { height: 15; } RichLog { height: 6; } .hidden { display: none; } """ def compose(self): with VerticalScroll(): for i in range(10): yield Placeholder() yield ProgressBar(classes="hidden") yield RichLog(classes="hidden") def on_ready(self) -> None: self.query_one(RichLog).write("\n".join(f"line #{i}" for i in range(5))) def action_toggle_widget(self, widget_type: str) -> None: self.query_one(widget_type).toggle_class("hidden") app = MRE() assert snap_compare(app, press=["z", "z"])
Regression test for https://github.com/Textualize/textual/issues/5056 After hiding and unhiding the RichLog, you should be able to see 1.5 fully rendered placeholder widgets. Prior to this fix, the bottom portion of the screen did not refresh after the RichLog was hidden/unhidden while in the presence of the auto-refreshing ProgressBar widget.
test_updates_with_auto_refresh
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_push_screen_on_mount(snap_compare): """Test pushing (modal) screen immediately on mount, which was not refreshing the base screen. Should show a panel partially obscuring Hello World text """ class QuitScreen(ModalScreen[None]): """Screen with a dialog to quit.""" DEFAULT_CSS = """ QuitScreen { align: center middle; } #dialog { grid-size: 2; grid-gutter: 1 2; grid-rows: 1fr 3; padding: 0 1; width: 60; height: 11; border: thick $primary 80%; background: $surface; } #question { column-span: 2; height: 1fr; width: 1fr; content-align: center middle; } Button { width: 100%; } """ def compose(self) -> ComposeResult: yield Grid( Label("Are you sure you want to quit?", id="question"), id="dialog" ) class MyApp(App[None]): def compose(self) -> ComposeResult: s = "Hello World Foo Bar Baz" yield Middle(Center(Static(s))) def on_mount(self) -> None: self.push_screen(QuitScreen()) app = MyApp() assert snap_compare(app)
Test pushing (modal) screen immediately on mount, which was not refreshing the base screen. Should show a panel partially obscuring Hello World text
test_push_screen_on_mount
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
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)
Renders a gradient, when the background is transparent.
test_transparent_background.render
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
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() assert snap_compare(app)
Check that a transparent background defers to render(). This should display a colorful gradient, filling the screen.
test_transparent_background
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_maximize_allow(snap_compare): """Check that App.ALLOW_IN_MAXIMIZED_VIEW is the default. If working this should show a header, some text, a focused button, and more text. """ class MaximizeApp(App): ALLOW_IN_MAXIMIZED_VIEW = "Header" BINDINGS = [("m", "screen.maximize", "maximize focused widget")] def compose(self) -> ComposeResult: yield Label( "Above", classes="-textual-system" ) # Allowed in maximize view because it has class -textual-system yield Header() # Allowed because it matches ALLOW_IN_MAXIMIZED_VIEW yield Button("Hello") # Allowed because it is the maximized widget yield Label( "Below", classes="-textual-system" ) # Allowed because it has class -textual-system yield Button("World") # Not allowed yield Footer() # Not allowed assert snap_compare(MaximizeApp(), press=["m"])
Check that App.ALLOW_IN_MAXIMIZED_VIEW is the default. If working this should show a header, some text, a focused button, and more text.
test_maximize_allow
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_background_tint(snap_compare): """Test background tint with alpha.""" # The screen background is dark blue # The vertical is 20% white # With no background tint, the verticals will be a light blue # With a 100% tint, the vertical should be 20% red plus the blue (i.e. purple) # tl;dr you should see 4 bars, blue at the top, purple at the bottom, and two shades in between class BackgroundTintApp(App): CSS = """ Screen { background: rgb(0,0,100) } Vertical { background: rgba(255,255,255,0.2); } #tint1 { background-tint: rgb(255,0,0) 0%; } #tint2 { background-tint: rgb(255,0,0) 33%; } #tint3 { background-tint: rgb(255,0,0) 66%; } #tint4 { background-tint: rgb(255,0,0) 100% } """ def compose(self) -> ComposeResult: with Vertical(id="tint1"): yield Label("0%") with Vertical(id="tint2"): yield Label("33%") with Vertical(id="tint3"): yield Label("66%") with Vertical(id="tint4"): yield Label("100%") assert snap_compare(BackgroundTintApp())
Test background tint with alpha.
test_background_tint
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_fr_and_margin(snap_compare): """Regression test for https://github.com/Textualize/textual/issues/5116""" # Check margins can be independently applied to widgets with fr unites class FRApp(App): CSS = """ #first-container { background: green; height: auto; } #second-container { margin: 2; background: red; height: auto; } #third-container { margin: 4; background: blue; height: auto; } """ def compose(self) -> ComposeResult: with Container(id="first-container"): yield Label("No margin - should extend to left and right") with Container(id="second-container"): yield Label("A margin of 2, should be 2 cells around the text") with Container(id="third-container"): yield Label("A margin of 4, should be 4 cells around the text") assert snap_compare(FRApp())
Regression test for https://github.com/Textualize/textual/issues/5116
test_fr_and_margin
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_pseudo_classes(snap_compare): """Test pseudo classes added in https://github.com/Textualize/textual/pull/5139 You should see 6 bars, with alternating green and red backgrounds. The first bar should have a red border. The last bar should have a green border. """ class PSApp(App): CSS = """ Label { width: 1fr; height: 1fr; } Label:first-of-type { border:heavy red; } Label:last-of-type { border:heavy green; } Label:odd {background: $success 20%; } Label:even {background: $error 20%; } """ def compose(self) -> ComposeResult: for item_number in range(5): yield Label(f"Item {item_number+1}") def on_mount(self) -> None: # Mounting a new widget should updated previous widgets, as the last of type has changed self.mount(Label("HELLO")) assert snap_compare(PSApp())
Test pseudo classes added in https://github.com/Textualize/textual/pull/5139 You should see 6 bars, with alternating green and red backgrounds. The first bar should have a red border. The last bar should have a green border.
test_pseudo_classes
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_split_segments_infinite_loop(snap_compare): """Regression test for https://github.com/Textualize/textual/issues/5151 Should be a bare-bones text editor containing "x" """ assert snap_compare(SNAPSHOT_APPS_DIR / "split_segments.py")
Regression test for https://github.com/Textualize/textual/issues/5151 Should be a bare-bones text editor containing "x"
test_split_segments_infinite_loop
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def get_theme_variable_defaults(self) -> dict[str, str]: """Define a custom theme variable.""" return {"theme-label-style": "bold italic", "unused": "red"}
Define a custom theme variable.
test_themes.get_theme_variable_defaults
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_themes(snap_compare, theme_name): """Test setting different themes and custom theme variables. The colors from the theme should be clear, and the text-style of the label should be bold italic, since that's set in the custom theme variable. """ class ThemeApp(App[None]): CSS = """ Screen { align: center middle; } Label { background: $panel; color: $text; padding: 1 2; border: wide $primary; text-style: $theme-label-style; } """ def get_theme_variable_defaults(self) -> dict[str, str]: """Define a custom theme variable.""" return {"theme-label-style": "bold italic", "unused": "red"} def compose(self) -> ComposeResult: yield Label(f"{theme_name.title()} Theme") def on_mount(self) -> None: self.theme = theme_name assert snap_compare(ThemeApp())
Test setting different themes and custom theme variables. The colors from the theme should be clear, and the text-style of the label should be bold italic, since that's set in the custom theme variable.
test_themes
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def get_theme_variable_defaults(self) -> dict[str, str]: """Override theme variables.""" return { "custom-text": "cyan", "custom-style": "bold italic", "custom-border": "red", "custom-background": "#0000ff 50%", }
Override theme variables.
test_custom_theme_with_variables.get_theme_variable_defaults
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_custom_theme_with_variables(snap_compare): """Test creating and using a custom theme with variables that get overridden. After the overrides from the theme, the background should be blue, the text should be white, the border should be yellow, the style should be bold italic, and the label should be cyan. """ class ThemeApp(App[None]): CSS = """ Screen { align: center middle; } Label { background: $custom-background; color: $custom-text; border: wide $custom-border; padding: 1 2; text-style: $custom-style; text-align: center; width: auto; } """ def compose(self) -> ComposeResult: yield Label("Custom Theme") def get_theme_variable_defaults(self) -> dict[str, str]: """Override theme variables.""" return { "custom-text": "cyan", "custom-style": "bold italic", "custom-border": "red", "custom-background": "#0000ff 50%", } def on_mount(self) -> None: custom_theme = Theme( name="my-custom", primary="magenta", background="black", variables={ "custom-background": "#ff0000 20%", "custom-text": "white", "custom-border": "yellow", "custom-style": "bold", }, ) self.register_theme(custom_theme) self.theme = "my-custom" assert snap_compare(ThemeApp())
Test creating and using a custom theme with variables that get overridden. After the overrides from the theme, the background should be blue, the text should be white, the border should be yellow, the style should be bold italic, and the label should be cyan.
test_custom_theme_with_variables
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def callback(): """Dummy no-op callback."""
Dummy no-op callback.
test_app_search_commands_opens_and_displays_search_list.test_app_search_commands_opens_and_displays_search_list.on_mount.callback
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
async def on_mount(self) -> None: def callback(): """Dummy no-op callback.""" commands = [("foo", callback), ("bar", callback), ("baz", callback)] await self.search_commands(commands)
Dummy no-op callback.
test_app_search_commands_opens_and_displays_search_list.on_mount
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_app_search_commands_opens_and_displays_search_list(snap_compare): """Test the App.search_commands method for displaying a list of commands.""" class SearchApp(App[None]): def compose(self) -> ComposeResult: yield Label("Search Commands") async def on_mount(self) -> None: def callback(): """Dummy no-op callback.""" commands = [("foo", callback), ("bar", callback), ("baz", callback)] await self.search_commands(commands) async def run_before(pilot: Pilot) -> None: await pilot.press("b") assert snap_compare(SearchApp(), run_before=run_before)
Test the App.search_commands method for displaying a list of commands.
test_app_search_commands_opens_and_displays_search_list
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_help_panel_key_display_not_duplicated(snap_compare): """Regression test for https://github.com/Textualize/textual/issues/5037""" class HelpPanelApp(App): BINDINGS = [ Binding("b,e,l", "bell", "Ring the bell", key_display="foo"), ] def compose(self) -> ComposeResult: yield Footer() async def run_before(pilot: Pilot): pilot.app.action_show_help_panel() app = HelpPanelApp() assert snap_compare(app, run_before=run_before)
Regression test for https://github.com/Textualize/textual/issues/5037
test_help_panel_key_display_not_duplicated
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_tabs_remove_tab_updates_highlighting(snap_compare): """Regression test for https://github.com/Textualize/textual/issues/5218""" class TabsApp(App): BINDINGS = [("r", "remove_foo", "Remove foo")] def compose(self) -> ComposeResult: yield Tabs( Tab("foo", id="foo"), Tab("bar", id="bar"), active="bar", ) yield Footer() def action_remove_foo(self) -> None: tabs = self.query_one(Tabs) tabs.remove_tab("foo") app = TabsApp() assert snap_compare(app, press="r")
Regression test for https://github.com/Textualize/textual/issues/5218
test_tabs_remove_tab_updates_highlighting
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_theme_variables_available_in_code(snap_compare): """Test that theme variables are available in code.""" class ThemeVariablesApp(App): def compose(self) -> ComposeResult: yield Label("Hello") def on_mount(self) -> None: variables = self.theme_variables label = self.query_one(Label) label.update(f"$text-primary = {variables['text-primary']}") label.styles.background = variables["primary-muted"] label.styles.color = variables["text-primary"] assert snap_compare(ThemeVariablesApp())
Test that theme variables are available in code.
test_theme_variables_available_in_code
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_dock_offset(snap_compare): """Regression test for https://github.com/Textualize/textual/issues/5261 You should see 10 labels, 0 thru 9, in a diagonal line starting at the top left. """ class OffsetBugApp(App): CSS = """ .label { dock: top; color: $text-success; background: $success-muted; } """ def compose(self) -> ComposeResult: # I'd expect this to draw a diagonal line of labels, but it places them all at the top left. for i in range(10): label = Label(str(i), classes="label") label.styles.offset = (i, i) yield label assert snap_compare(OffsetBugApp())
Regression test for https://github.com/Textualize/textual/issues/5261 You should see 10 labels, 0 thru 9, in a diagonal line starting at the top left.
test_dock_offset
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_select_overlay_constrain(snap_compare): """Check that the constrain logic on Select is working. You should see the select overlay in full, anchored to the bottom of the screen.""" class OApp(App): CSS = """ Label { height: 16; background: blue; border: tall white; } """ def compose(self) -> ComposeResult: yield Label("Padding (ignore)") yield Select.from_values(["Foo", "bar", "baz"] * 10) async def run_before(pilot: Pilot) -> None: await pilot.pause() await pilot.click(Select) assert snap_compare(OApp(), run_before=run_before)
Check that the constrain logic on Select is working. You should see the select overlay in full, anchored to the bottom of the screen.
test_select_overlay_constrain
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_position_absolute(snap_compare): """Check position: absolute works as expected. You should see three staggered labels at the top-left, and three staggered relative labels in the center. The relative labels will have an additional line between them. """ class AbsoluteApp(App): CSS = """ Screen { align: center middle; .absolute { position: absolute; } .relative { position: relative; } .offset1 { offset: 1 1; } .offset2 { offset: 2 2; } .offset3 { offset: 3 3; } } """ def compose(self) -> ComposeResult: yield Label("Absolute 1", classes="absolute offset1") yield Label("Absolute 2", classes="absolute offset2") yield Label("Absolute 3", classes="absolute offset3") yield Label("Relative 1", classes="relative offset1") yield Label("Relative 2", classes="relative offset2") yield Label("Relative 3", classes="relative offset3") assert snap_compare(AbsoluteApp())
Check position: absolute works as expected. You should see three staggered labels at the top-left, and three staggered relative labels in the center. The relative labels will have an additional line between them.
test_position_absolute
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_grid_offset(snap_compare): """Regression test for https://github.com/Textualize/textual/issues/5279 You should see 6 boxes arranged in a 3x2 grid. The 6th should be offset 10 lines down. """ class GridOffsetApp(App): CSS = """ Screen { layout: grid; grid-size: 3 2; } .box { height: 100%; border: solid green; } #six { offset: 0 10; background: blue; } """ def compose(self) -> ComposeResult: yield Static("One", classes="box") yield Static("Two", classes="box") yield Static("Three", classes="box") yield Static("Four", classes="box") yield Static("Five", classes="box") yield Static("Six", classes="box", id="six") assert snap_compare(GridOffsetApp())
Regression test for https://github.com/Textualize/textual/issues/5279 You should see 6 boxes arranged in a 3x2 grid. The 6th should be offset 10 lines down.
test_grid_offset
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_select_width_auto(snap_compare): """Regression test for https://github.com/Textualize/textual/issues/5280" The overlay has a width of auto, so the first (widest) option should not wrap.""" class TallSelectApp(App[None]): CSS = """ Screen { align: center middle; & > Select { width: 50; & > SelectOverlay { max-height: 100vh; width: auto; } } } """ def compose(self) -> ComposeResult: yield Select( [("Extra long option here", 100)] + [(f"Option {idx + 1}", idx) for idx in range(100)], value=100, ) async def run_before(pilot: Pilot) -> None: await pilot.pause() await pilot.click("Select") assert snap_compare(TallSelectApp(), run_before=run_before)
Regression test for https://github.com/Textualize/textual/issues/5280" The overlay has a width of auto, so the first (widest) option should not wrap.
test_select_width_auto
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
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. """ class MyApp(App): def on_mount(self) -> None: self.search_commands( [ SimpleCommand( "Hello [u ansi_green]World", lambda: None, "Help [u ansi_red]text", ) ] ) assert snap_compare(MyApp())
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.
test_markup_command_list
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_app_resize_order(snap_compare): """Regression test for https://github.com/Textualize/textual/issues/5284 You should see a placeholder with text "BAR", focused and scrolled down so it fills the screen. """ class FocusPlaceholder(Placeholder, can_focus=True): pass class NarrowScreen(Screen): AUTO_FOCUS = "#bar" def compose(self) -> ComposeResult: yield FocusPlaceholder("FOO", id="foo") yield FocusPlaceholder("BAR", id="bar") class SCApp(App): CSS = """ Placeholder:focus { border: heavy white; } #foo { height: 24; } #bar { height: 1fr; } .narrow #bar { height: 100%; } """ def on_mount(self) -> None: self.push_screen(NarrowScreen()) def on_resize(self) -> None: self.add_class("narrow") async def run_before(pilot: Pilot): await pilot.pause() await pilot.wait_for_animation() await pilot.pause() assert snap_compare(SCApp(), run_before=run_before)
Regression test for https://github.com/Textualize/textual/issues/5284 You should see a placeholder with text "BAR", focused and scrolled down so it fills the screen.
test_app_resize_order
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
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' """ class ExampleApp(App): BINDINGS = [ ("r", "remove_pane", "Remove first pane"), ("a", "add_pane", "Add pane"), ] def compose(self) -> ComposeResult: with TabbedContent(initial="tab-2"): with TabPane("tab-1"): yield Label("tab-1") with TabPane("tab-2"): yield Label("tab-2") yield Footer() def action_remove_pane(self) -> None: tabbed_content = self.query_one(TabbedContent) tabbed_content.remove_pane("tab-1") def action_add_pane(self) -> None: tabbed_content = self.query_one(TabbedContent) new_pane = TabPane("New tab", Label("new")) tabbed_content.add_pane(new_pane) assert snap_compare(ExampleApp(), press=["a", "r", "a"])
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'
test_add_remove_tabs
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_click_expand(snap_compare): """Should show an expanded select with 15 highlighted.""" class SelectApp(App): def compose(self) -> ComposeResult: yield Select.from_values( range(20), value=15, ) async def run_before(pilot: Pilot) -> None: await pilot.pause() await pilot.click(Select) assert snap_compare(SelectApp(), run_before=run_before)
Should show an expanded select with 15 highlighted.
test_click_expand
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
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. """ class FooterApp(App): BINDINGS = [("b", "bell", "Bell")] def compose(self) -> ComposeResult: yield Footer() def check_action( self, action: str, parameters: tuple[object, ...] ) -> bool | None: if action == "command_palette": return None return True assert snap_compare(FooterApp())
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.
test_disable_command_palette
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_selection_list_wrap(snap_compare): """Regression test for https://github.com/Textualize/textual/issues/5326""" class SelectionListApp(App): def compose(self) -> ComposeResult: yield SelectionList(("Hello World " * 100, 0)) assert snap_compare(SelectionListApp())
Regression test for https://github.com/Textualize/textual/issues/5326
test_selection_list_wrap
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_border_tab(snap_compare): """Test tab border style. You should see a border with a left align tab at the top and a right aligned tab at the bottom.""" class TabApp(App): CSS = """ Screen { align: center middle; } Label { border: tab $border; padding: 2 4; border-title-align: left; } """ def compose(self) -> ComposeResult: label = Label("Hello, World") label.border_title = "Tab Border" label.border_subtitle = ":-)" yield label assert snap_compare(TabApp())
Test tab border style. You should see a border with a left align tab at the top and a right aligned tab at the bottom.
test_border_tab
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
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. """ class MainContainer(Static): def compose(self): yield Sidebar() # ~~~~ Sidebar widget ~~~~ class Sidebar(Static): def compose(self): yield StartButtons() # ~~~~ the two buttons inside the sidebar ~~~~ class StartButtons(Static): def compose(self): yield Button("Start", variant="primary", id="start") yield Button("Stop", variant="error", id="stop") # ~~~~ main ~~~~ class Test1(App): CSS = """ Screen { layout: horizontal; } MainContainer { width: 100%; height: 100%; background: red; layout: horizontal; } Sidebar { width: 40; background: blue; border: double green; layout: vertical; /* seems to be a weird interaction between these two */ /* V V V V */ dock: right; align-horizontal: center; } StartButtons { max-width: 18.5; height: 5; background: $boost; padding: 1; layout: horizontal; } #start { dock: left; } #stop { dock: left; } """ def compose(self): yield MainContainer() assert snap_compare(Test1())
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.
test_dock_align
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_auto_parent_with_alignment(snap_compare): class Sidebar(Vertical): DEFAULT_CSS = """ Sidebar { dock: right; # Not strictly required to replicate the issue width: auto; height: auto; background: blue; align-vertical: bottom; #contents { width: auto; height: auto; background: red; border: white; } } """ def compose(self) -> ComposeResult: with Vertical(id="contents"): yield Button("Start") yield Button("Stop") class FloatSidebarApp(App): CSS = """ Screen { layers: base sidebar; } """ def compose(self) -> ComposeResult: yield Sidebar() assert snap_compare(FloatSidebarApp())
def compose(self) -> ComposeResult: with Vertical(id="contents"): yield Button("Start") yield Button("Stop") class FloatSidebarApp(App): CSS =
test_auto_parent_with_alignment
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_select_refocus(snap_compare): """Regression test for https://github.com/Textualize/textual/issues/5416 The original bug was that the call to focus had no apparent effect as the Select was re-focusing itself after the Changed message was processed. You should see a list view with three items, where the second one is in focus. """ opts = ["foo", "bar", "zoo"] class MyListItem(ListItem): def __init__(self, opts: list[str]) -> None: self.opts = opts self.lab = Label("Hello!") self.sel = Select(options=[(opt, opt) for opt in self.opts]) super().__init__() def compose(self): with HorizontalGroup(): yield self.lab yield self.sel def on_select_changed(self, event: Select.Changed): self.app.query_one(MyListView).focus() class MyListView(ListView): def compose(self): yield MyListItem(opts) yield MyListItem(opts) yield MyListItem(opts) def on_list_view_selected(self, event: ListView.Selected): event.item.sel.focus() event.item.sel.expanded = True class TUI(App): def compose(self): with Container(): yield MyListView() assert snap_compare(TUI(), press=["down", "enter", "down", "down", "enter"])
Regression test for https://github.com/Textualize/textual/issues/5416 The original bug was that the call to focus had no apparent effect as the Select was re-focusing itself after the Changed message was processed. You should see a list view with three items, where the second one is in focus.
test_select_refocus
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_widgets_in_grid(snap_compare): """You should see a 3x3 grid of labels where the text is wrapped, and there is no superfluous space.""" TEXT = """I must not fear. Fear is the mind-killer. Fear is the little-death that brings total obliteration. I will face my fear. I will permit it to pass over me and through me. And when it has gone past, I will turn the inner eye to see its path. Where the fear has gone there will be nothing. Only I will remain.""" class MyApp(App): CSS = """ VerticalGroup { layout: grid; grid-size: 3 3; grid-columns: 1fr; grid-rows: auto; height: auto; background: blue; } Label { border: heavy red; text-align: left; } """ def compose(self) -> ComposeResult: with VerticalGroup(): for n in range(9): label = Label(TEXT, id=f"label{n}") label.border_title = str(n) yield label assert snap_compare(MyApp(), terminal_size=(100, 50))
You should see a 3x3 grid of labels where the text is wrapped, and there is no superfluous space.
test_widgets_in_grid
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_arbitrary_selection(snap_compare): """You should see 3x3 labels with different text alignments. Text selection should start from somewhere in the first label, and end somewhere in the right label. """ async def run_before(pilot: Pilot) -> None: await pilot.pause() await pilot.mouse_down(pilot.app.query_one("#first"), offset=(10, 10)) await pilot.mouse_up(pilot.app.query_one("#last"), offset=(10, 10)) await pilot.pause() assert snap_compare( SNAPSHOT_APPS_DIR / "text_selection.py", terminal_size=(175, 50), run_before=run_before, )
You should see 3x3 labels with different text alignments. Text selection should start from somewhere in the first label, and end somewhere in the right label.
test_arbitrary_selection
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_collapsible_datatable(snap_compare): """Regression test for https://github.com/Textualize/textual/issues/5407 You should see two collapsibles, where the first is expanded. In the expanded coillapsible, you should see a DataTable filling the space, with all borders and both scrollbars visible. """ class MyApp(App): CSS = """ DataTable { } """ def compose(self) -> ComposeResult: yield Collapsible(DataTable(id="t1"), id="c1", collapsed=False) yield Collapsible(Label("hello"), id="c2") def on_mount(self) -> None: self.query_one("#c1", Collapsible).styles.max_height = "50%" self.query_one("#c2", Collapsible).styles.max_height = "50%" t1 = self.query_one("#t1", DataTable) t1.styles.border = "heavy", "black" t1.add_column("A") for number in range(1, 100): t1.add_row(str(number) + " " * 200) assert snap_compare(MyApp())
Regression test for https://github.com/Textualize/textual/issues/5407 You should see two collapsibles, where the first is expanded. In the expanded coillapsible, you should see a DataTable filling the space, with all borders and both scrollbars visible.
test_collapsible_datatable
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_scrollbar_background_with_opacity(snap_compare): """Regression test for https://github.com/Textualize/textual/issues/5458 The scrollbar background should match the background of the widget.""" class ScrollbarOpacityApp(App): CSS = """ Screen { align: center middle; } VerticalScroll { width: 50%; height: 50%; background: blue 10%; scrollbar-background: blue 10%; scrollbar-color: cyan; scrollbar-size-vertical: 10; } """ def compose(self) -> ComposeResult: with VerticalScroll(): yield Static("\n".join(f"This is some text {n}" for n in range(100))) assert snap_compare(ScrollbarOpacityApp())
Regression test for https://github.com/Textualize/textual/issues/5458 The scrollbar background should match the background of the widget.
test_scrollbar_background_with_opacity
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_static_markup(snap_compare): """Check that markup may be disabled. You should see 3 labels. This first label contains an invalid style, and should have tags removed. The second label should have the word "markup" emboldened. The third label has markup disabled, and should show tags without styles. """ class LabelApp(App): def compose(self) -> ComposeResult: yield Label("There should be no [foo]tags or style[/foo]") yield Label("This allows [bold]markup[/bold]") yield Label("This does not allow [bold]markup[/bold]", markup=False) assert snap_compare(LabelApp())
Check that markup may be disabled. You should see 3 labels. This first label contains an invalid style, and should have tags removed. The second label should have the word "markup" emboldened. The third label has markup disabled, and should show tags without styles.
test_static_markup
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
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. """ class LApp(App): def compose(self) -> ComposeResult: yield Label("😃Hello World!") async def run_before(pilot: Pilot) -> None: await pilot.pause() await pilot.mouse_down(Label, offset=(2, 0)) await pilot.mouse_up(Label, offset=(7, 0)) await pilot.pause() assert snap_compare(LApp(), run_before=run_before)
Check that selection understands double width cells. You should see a smiley face followed by 'Hello World!', where Hello is highlighted.
test_arbitrary_selection_double_cell
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_markup(snap_compare): """Check markup rendering, text in test should match the markup.""" assert snap_compare(SNAPSHOT_APPS_DIR / "markup.py")
Check markup rendering, text in test should match the markup.
test_markup
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_no_wrap(snap_compare): """Test no wrap. You should see exactly two lines. The first is cropped, the second is cropped with an ellipsis symbol.""" TEXT = """I must not fear. Fear is the mind-killer. Fear is the little-death that brings total obliteration. I will face my fear.""" class NoWrapApp(App): CSS = """ Label { max-width: 100vw; text-wrap: nowrap; } #label2 { text-overflow: ellipsis; } """ def compose(self) -> ComposeResult: yield Label(TEXT, id="label1") yield Label(TEXT, id="label2") assert snap_compare(NoWrapApp())
Test no wrap. You should see exactly two lines. The first is cropped, the second is cropped with an ellipsis symbol.
test_no_wrap
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_overflow(snap_compare): """Test overflow. You should see three labels across 4 lines. The first with overflow clip, the second with overflow ellipsis, and the last with overflow fold.""" TEXT = "FOO " + "FOOBARBAZ" * 100 class OverflowApp(App): CSS = """ Label { max-width: 100vw; } #label1 { # Overflow will be cropped text-overflow: clip; background: blue 20%; } #label2 { # Like clip, but last character will be an ellipsis text-overflow: ellipsis; background: green 20%; } #label3 { # Overflow will fold on to subsequence lines text-overflow: fold; background: red 20%; } """ def compose(self) -> ComposeResult: yield Label(TEXT, id="label1") yield Label(TEXT, id="label2") yield Label(TEXT, id="label3") assert snap_compare(OverflowApp())
Test overflow. You should see three labels across 4 lines. The first with overflow clip, the second with overflow ellipsis, and the last with overflow fold.
test_overflow
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_empty_option_list(snap_compare): """Regression test for https://github.com/Textualize/textual/issues/5489 You should see an OptionList with no options, resulting in a small square at the top left. """ class OptionListAutoCrash(App[None]): CSS = """ OptionList { width: auto; } """ def compose(self) -> ComposeResult: yield OptionList() assert snap_compare(OptionListAutoCrash())
Regression test for https://github.com/Textualize/textual/issues/5489 You should see an OptionList with no options, resulting in a small square at the top left.
test_empty_option_list
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_focus_within_transparent(snap_compare): """Regression test for https://github.com/Textualize/textual/issues/5488 You should see the right 50% in yellow, with a yellow OptionList and a black TextArea """ class Panel(Vertical, can_focus=True): pass class FocusWithinTransparentApp(App[None]): CSS = """ Screen { layout: horizontal; } Input { width: 1fr; height: 1fr; } Panel { padding: 5 10; background: red; &:focus, &:focus-within { background: yellow; } OptionList, OptionList:focus { height: 1fr; background: transparent; } } """ def compose(self) -> ComposeResult: yield Input(placeholder="This is here to escape to") with Panel(): yield OptionList(*["This is an option" for _ in range(30)]) yield Input(placeholder="Escape out via here for the bug") assert snap_compare(FocusWithinTransparentApp(), press=["tab"])
Regression test for https://github.com/Textualize/textual/issues/5488 You should see the right 50% in yellow, with a yellow OptionList and a black TextArea
test_focus_within_transparent
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_option_list_wrapping(snap_compare): """You should see a 40 cell wide Option list with a single line, ending in an ellipsis.""" class OLApp(App): CSS = """ OptionList { width: 40; text-wrap: nowrap; text-overflow: ellipsis; } """ def compose(self) -> ComposeResult: yield OptionList( "This is a very long option that is too wide to fit within the space provided and will overflow." ) assert snap_compare(OLApp())
You should see a 40 cell wide Option list with a single line, ending in an ellipsis.
test_option_list_wrapping
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT