mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
table tests
This commit is contained in:
45
tests/test_table.py
Normal file
45
tests/test_table.py
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
import asyncio
|
||||||
|
|
||||||
|
from textual.app import App, ComposeResult
|
||||||
|
from textual.widgets import DataTable
|
||||||
|
|
||||||
|
|
||||||
|
class TableApp(App):
|
||||||
|
def compose(self) -> ComposeResult:
|
||||||
|
yield DataTable()
|
||||||
|
|
||||||
|
|
||||||
|
async def test_table_clear() -> None:
|
||||||
|
"""Check DataTable.clear"""
|
||||||
|
|
||||||
|
app = TableApp()
|
||||||
|
async with app.run_test() as pilot:
|
||||||
|
table = app.query_one(DataTable)
|
||||||
|
table.add_columns("foo", "bar")
|
||||||
|
assert table.row_count == 0
|
||||||
|
table.add_row("Hello", "World!")
|
||||||
|
assert table.data == {0: ["Hello", "World!"]}
|
||||||
|
assert table.row_count == 1
|
||||||
|
table.clear()
|
||||||
|
assert table.data == {}
|
||||||
|
assert table.row_count == 0
|
||||||
|
|
||||||
|
|
||||||
|
async def test_table_add_row() -> None:
|
||||||
|
|
||||||
|
app = TableApp()
|
||||||
|
async with app.run_test():
|
||||||
|
table = app.query_one(DataTable)
|
||||||
|
table.add_columns("foo", "bar")
|
||||||
|
|
||||||
|
assert table.columns[0].width == 3
|
||||||
|
assert table.columns[1].width == 3
|
||||||
|
table.add_row("Hello", "World!")
|
||||||
|
await asyncio.sleep(0)
|
||||||
|
assert table.columns[0].content_width == 5
|
||||||
|
assert table.columns[1].content_width == 6
|
||||||
|
|
||||||
|
table.add_row("Hello World!!!", "fo")
|
||||||
|
await asyncio.sleep(0)
|
||||||
|
assert table.columns[0].content_width == 14
|
||||||
|
assert table.columns[1].content_width == 6
|
||||||
Reference in New Issue
Block a user