MCPcopy
hub / github.com/Textualize/textual / test_datatable_message_emission

Function test_datatable_message_emission

tests/test_data_table.py:67–169  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

65
66
67async def test_datatable_message_emission():
68 app = DataTableApp()
69 expected_messages = []
70 async with app.run_test() as pilot:
71 table = app.query_one(DataTable)
72
73 assert app.message_names == expected_messages
74
75 table.add_columns("Column0", "Column1")
76 table.add_rows(ROWS)
77
78 # A CellHighlighted is emitted because there were no rows (and
79 # therefore no highlighted cells), but then a row was added, and
80 # so the cell at (0, 0) became highlighted.
81 expected_messages.append("CellHighlighted")
82 await pilot.pause()
83 assert app.message_names == expected_messages
84
85 # Pressing Enter when the cursor is on a cell emits a CellSelected
86 await pilot.press("enter")
87 await pilot.pause()
88 expected_messages.append("CellSelected")
89 assert app.message_names == expected_messages
90
91 # Moving the cursor left and up when the cursor is at origin
92 # emits no events, since the cursor doesn't move at all.
93 await pilot.press("left", "up")
94 assert app.message_names == expected_messages
95
96 # ROW CURSOR
97 # Switch over to the row cursor... should emit a `RowHighlighted`
98 table.cursor_type = "row"
99 expected_messages.append("RowHighlighted")
100 await pilot.pause()
101 assert app.message_names == expected_messages
102
103 # Select the row...
104 await pilot.press("enter")
105 await pilot.pause()
106 expected_messages.append("RowSelected")
107 assert app.message_names == expected_messages
108
109 # COLUMN CURSOR
110 # Switching to the column cursor emits a `ColumnHighlighted`
111 table.cursor_type = "column"
112 expected_messages.append("ColumnHighlighted")
113 await pilot.pause()
114 assert app.message_names == expected_messages
115
116 # Select the column...
117 await pilot.press("enter")
118 expected_messages.append("ColumnSelected")
119 await pilot.pause()
120 assert app.message_names == expected_messages
121
122 # NONE CURSOR
123 # No messages get emitted at all...
124 table.cursor_type = "none"

Callers

nothing calls this directly

Calls 8

DataTableAppClass · 0.85
run_testMethod · 0.80
query_oneMethod · 0.80
add_columnsMethod · 0.80
add_rowsMethod · 0.80
appendMethod · 0.45
pauseMethod · 0.45
pressMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…