mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Snapshot tests for column and row cursors in DataTable
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -0,0 +1,35 @@
|
|||||||
|
import csv
|
||||||
|
import io
|
||||||
|
|
||||||
|
from textual.app import App, ComposeResult
|
||||||
|
from textual.widgets import DataTable
|
||||||
|
|
||||||
|
CSV = """lane,swimmer,country,time
|
||||||
|
4,Joseph Schooling,Singapore,50.39
|
||||||
|
2,Michael Phelps,United States,51.14
|
||||||
|
5,Chad le Clos,South Africa,51.14
|
||||||
|
6,László Cseh,Hungary,51.14
|
||||||
|
3,Li Zhuhao,China,51.26
|
||||||
|
8,Mehdy Metella,France,51.58
|
||||||
|
7,Tom Shields,United States,51.73
|
||||||
|
1,Aleksandr Sadovnikov,Russia,51.84"""
|
||||||
|
|
||||||
|
|
||||||
|
class TableApp(App):
|
||||||
|
def compose(self) -> ComposeResult:
|
||||||
|
table = DataTable()
|
||||||
|
table.focus()
|
||||||
|
table.cursor_type = "column"
|
||||||
|
table.fixed_columns = 1
|
||||||
|
yield table
|
||||||
|
|
||||||
|
def on_mount(self) -> None:
|
||||||
|
table = self.query_one(DataTable)
|
||||||
|
rows = csv.reader(io.StringIO(CSV))
|
||||||
|
table.add_columns(*next(rows))
|
||||||
|
table.add_rows(rows)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
app = TableApp()
|
||||||
|
app.run()
|
||||||
34
tests/snapshot_tests/snapshot_apps/data_table_row_cursor.py
Normal file
34
tests/snapshot_tests/snapshot_apps/data_table_row_cursor.py
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
import csv
|
||||||
|
import io
|
||||||
|
|
||||||
|
from textual.app import App, ComposeResult
|
||||||
|
from textual.widgets import DataTable
|
||||||
|
|
||||||
|
CSV = """lane,swimmer,country,time
|
||||||
|
4,Joseph Schooling,Singapore,50.39
|
||||||
|
2,Michael Phelps,United States,51.14
|
||||||
|
5,Chad le Clos,South Africa,51.14
|
||||||
|
6,László Cseh,Hungary,51.14
|
||||||
|
3,Li Zhuhao,China,51.26
|
||||||
|
8,Mehdy Metella,France,51.58
|
||||||
|
7,Tom Shields,United States,51.73
|
||||||
|
1,Aleksandr Sadovnikov,Russia,51.84"""
|
||||||
|
|
||||||
|
|
||||||
|
class TableApp(App):
|
||||||
|
def compose(self) -> ComposeResult:
|
||||||
|
table = DataTable()
|
||||||
|
table.focus()
|
||||||
|
table.cursor_type = "row"
|
||||||
|
yield table
|
||||||
|
|
||||||
|
def on_mount(self) -> None:
|
||||||
|
table = self.query_one(DataTable)
|
||||||
|
rows = csv.reader(io.StringIO(CSV))
|
||||||
|
table.add_columns(*next(rows))
|
||||||
|
table.add_rows(rows)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
app = TableApp()
|
||||||
|
app.run()
|
||||||
@@ -93,6 +93,16 @@ def test_datatable_render(snap_compare):
|
|||||||
assert snap_compare(WIDGET_EXAMPLES_DIR / "data_table.py", press=press)
|
assert snap_compare(WIDGET_EXAMPLES_DIR / "data_table.py", press=press)
|
||||||
|
|
||||||
|
|
||||||
|
def test_datatable_row_cursor_render(snap_compare):
|
||||||
|
press = ["up", "left", "right", "down", "down", "_"]
|
||||||
|
assert snap_compare(SNAPSHOT_APPS_DIR / "data_table_row_cursor.py", press=press)
|
||||||
|
|
||||||
|
|
||||||
|
def test_datatable_column_cursor_render(snap_compare):
|
||||||
|
press = ["left", "up", "down", "right", "right", "_"]
|
||||||
|
assert snap_compare(SNAPSHOT_APPS_DIR / "data_table_column_cursor.py", press=press)
|
||||||
|
|
||||||
|
|
||||||
def test_footer_render(snap_compare):
|
def test_footer_render(snap_compare):
|
||||||
assert snap_compare(WIDGET_EXAMPLES_DIR / "footer.py")
|
assert snap_compare(WIDGET_EXAMPLES_DIR / "footer.py")
|
||||||
|
|
||||||
@@ -147,11 +157,11 @@ def test_multiple_css(snap_compare):
|
|||||||
|
|
||||||
|
|
||||||
def test_order_independence(snap_compare):
|
def test_order_independence(snap_compare):
|
||||||
assert snap_compare("snapshot_apps/order_independence.py")
|
assert snap_compare("snapshot_apps/layer_order_independence.py")
|
||||||
|
|
||||||
|
|
||||||
def test_order_independence_toggle(snap_compare):
|
def test_order_independence_toggle(snap_compare):
|
||||||
assert snap_compare("snapshot_apps/order_independence.py", press="t,_")
|
assert snap_compare("snapshot_apps/layer_order_independence.py", press="t,_")
|
||||||
|
|
||||||
|
|
||||||
def test_columns_height(snap_compare):
|
def test_columns_height(snap_compare):
|
||||||
|
|||||||
Reference in New Issue
Block a user