mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Remove comments, simplify test
This commit is contained in:
@@ -2,7 +2,7 @@ import csv
|
|||||||
import io
|
import io
|
||||||
|
|
||||||
from textual.app import App, ComposeResult
|
from textual.app import App, ComposeResult
|
||||||
from textual.widgets import DataTable
|
from textual.widgets import DataTable, Header
|
||||||
|
|
||||||
CSV = """lane,swimmer,country,time
|
CSV = """lane,swimmer,country,time
|
||||||
4,Joseph Schooling,Singapore,50.39
|
4,Joseph Schooling,Singapore,50.39
|
||||||
@@ -17,6 +17,7 @@ CSV = """lane,swimmer,country,time
|
|||||||
|
|
||||||
class TableApp(App):
|
class TableApp(App):
|
||||||
def compose(self) -> ComposeResult:
|
def compose(self) -> ComposeResult:
|
||||||
|
yield Header()
|
||||||
yield DataTable()
|
yield DataTable()
|
||||||
|
|
||||||
def on_mount(self) -> None:
|
def on_mount(self) -> None:
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ def snap_compare(
|
|||||||
"""
|
"""
|
||||||
node = request.node
|
node = request.node
|
||||||
app = import_app(app_path)
|
app = import_app(app_path)
|
||||||
|
compare.app = app
|
||||||
actual_screenshot = take_svg_screenshot(
|
actual_screenshot = take_svg_screenshot(
|
||||||
app=app,
|
app=app,
|
||||||
press=press,
|
press=press,
|
||||||
|
|||||||
@@ -2,8 +2,9 @@ from pathlib import Path
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
# --- Layout related stuff ---
|
# --- Layout related stuff ---
|
||||||
|
from textual.widgets import Input
|
||||||
|
|
||||||
|
|
||||||
def test_grid_layout_basic(snap_compare):
|
def test_grid_layout_basic(snap_compare):
|
||||||
assert snap_compare("docs/examples/guide/layout/grid_layout1.py")
|
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
|
# When adding a new widget, ideally we should also create a snapshot test
|
||||||
# from these examples which test rendering and simple interactions with it.
|
# 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):
|
def test_checkboxes(snap_compare):
|
||||||
"""Tests checkboxes but also acts a regression test for using
|
"""Tests checkboxes but also acts a regression test for using
|
||||||
width: auto in a Horizontal layout context."""
|
width: auto in a Horizontal layout context."""
|
||||||
@@ -60,9 +54,18 @@ def test_checkboxes(snap_compare):
|
|||||||
|
|
||||||
|
|
||||||
def test_input_and_focus(snap_compare):
|
def test_input_and_focus(snap_compare):
|
||||||
first_field = ["tab"] + list("Darren") # Focus first input, write "Darren"
|
press = [
|
||||||
second_field = ["tab"] + list("Burns") # Tab focus to second input, write "Burns"
|
"tab",
|
||||||
assert snap_compare("docs/examples/widgets/input.py", press=first_field + second_field)
|
*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):
|
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"])
|
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):
|
def test_datatable_render(snap_compare):
|
||||||
press = ["tab", "down", "down", "right", "up", "left"]
|
press = ["tab", "down", "down", "right", "up", "left"]
|
||||||
assert snap_compare("docs/examples/widgets/data_table.py", press=press)
|
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):
|
def test_header_render(snap_compare):
|
||||||
assert snap_compare("docs/examples/widgets/header.py")
|
assert snap_compare("docs/examples/widgets/header.py")
|
||||||
|
|
||||||
|
|
||||||
# --- CSS properties ---
|
# --- CSS properties ---
|
||||||
# We have a canonical example for each CSS property that is shown in their docs.
|
# 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.
|
# If any of these change, something has likely broken, so snapshot each of them.
|
||||||
|
|||||||
Reference in New Issue
Block a user