From 041bb350140f77f327fb747c4471bc093076070e Mon Sep 17 00:00:00 2001 From: Darren Burns Date: Mon, 24 Oct 2022 14:51:40 +0100 Subject: [PATCH] Remove comments, simplify test --- docs/examples/widgets/data_table.py | 3 ++- tests/snapshot_tests/conftest.py | 1 + tests/snapshot_tests/test_snapshots.py | 28 ++++++++++++++------------ 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/docs/examples/widgets/data_table.py b/docs/examples/widgets/data_table.py index 87b2c0ce8..f2671dd48 100644 --- a/docs/examples/widgets/data_table.py +++ b/docs/examples/widgets/data_table.py @@ -2,7 +2,7 @@ import csv import io from textual.app import App, ComposeResult -from textual.widgets import DataTable +from textual.widgets import DataTable, Header CSV = """lane,swimmer,country,time 4,Joseph Schooling,Singapore,50.39 @@ -17,6 +17,7 @@ CSV = """lane,swimmer,country,time class TableApp(App): def compose(self) -> ComposeResult: + yield Header() yield DataTable() def on_mount(self) -> None: diff --git a/tests/snapshot_tests/conftest.py b/tests/snapshot_tests/conftest.py index 79b5584b1..0a0f0d55c 100644 --- a/tests/snapshot_tests/conftest.py +++ b/tests/snapshot_tests/conftest.py @@ -59,6 +59,7 @@ def snap_compare( """ node = request.node app = import_app(app_path) + compare.app = app actual_screenshot = take_svg_screenshot( app=app, press=press, diff --git a/tests/snapshot_tests/test_snapshots.py b/tests/snapshot_tests/test_snapshots.py index fb4913227..71b02371e 100644 --- a/tests/snapshot_tests/test_snapshots.py +++ b/tests/snapshot_tests/test_snapshots.py @@ -2,8 +2,9 @@ from pathlib import Path import pytest - # --- Layout related stuff --- +from textual.widgets import Input + def test_grid_layout_basic(snap_compare): assert snap_compare("docs/examples/guide/layout/grid_layout1.py") @@ -38,13 +39,6 @@ def test_dock_layout_sidebar(snap_compare): # When adding a new widget, ideally we should also create a snapshot test # from these examples which test rendering and simple interactions with it. -# before snapshot test: -# src/textual/widgets/_checkbox.py 47 47 0% 1-126 -# before testing presses in snapshot test: -# src/textual/widgets/_checkbox.py 47 11 77% 83-88, 110, 113, 118, 124-126 -# after testing presses in snapshot test: -# src/textual/widgets/_checkbox.py 47 2 96% 87, 110 - def test_checkboxes(snap_compare): """Tests checkboxes but also acts a regression test for using width: auto in a Horizontal layout context.""" @@ -60,9 +54,18 @@ def test_checkboxes(snap_compare): def test_input_and_focus(snap_compare): - first_field = ["tab"] + list("Darren") # Focus first input, write "Darren" - second_field = ["tab"] + list("Burns") # Tab focus to second input, write "Burns" - assert snap_compare("docs/examples/widgets/input.py", press=first_field + second_field) + press = [ + "tab", + *list("Darren"), # Focus first input, write "Darren" + "tab", + *list("Burns"), # Tab focus to second input, write "Burns" + ] + assert snap_compare("docs/examples/widgets/input.py", press=press) + + # Assert that the state of the Input is what we'd expect + input: Input = snap_compare.app.query_one(Input) + assert input.value == "Darren" + assert input.cursor_position == 6 def test_buttons_render(snap_compare): @@ -70,8 +73,6 @@ def test_buttons_render(snap_compare): assert snap_compare("docs/examples/widgets/button.py", press=["tab"]) -# src/textual/widgets/_data_table.py 312 312 0% -# src/textual/widgets/_data_table.py 312 85 73% def test_datatable_render(snap_compare): press = ["tab", "down", "down", "right", "up", "left"] assert snap_compare("docs/examples/widgets/data_table.py", press=press) @@ -84,6 +85,7 @@ def test_footer_render(snap_compare): def test_header_render(snap_compare): assert snap_compare("docs/examples/widgets/header.py") + # --- CSS properties --- # We have a canonical example for each CSS property that is shown in their docs. # If any of these change, something has likely broken, so snapshot each of them.