Exception on duplicate row and column keys

This commit is contained in:
Darren Burns
2023-02-13 14:09:33 +00:00
parent 196054f6b0
commit 12a58f838f
3 changed files with 38 additions and 7 deletions

View File

@@ -11,6 +11,7 @@ from textual.events import Click, MouseMove
from textual.message import Message
from textual.message_pump import MessagePump
from textual.widgets import DataTable
from textual.widgets._data_table import DuplicateKey
from textual.widgets.data_table import CellDoesNotExist, CellKey, ColumnKey, Row, RowKey
ROWS = [["0/0", "0/1"], ["1/0", "1/1"], ["2/0", "2/1"]]
@@ -192,6 +193,25 @@ async def test_add_rows_user_defined_keys():
assert table.rows["algernon"] == first_row
async def test_add_row_duplicate_key():
app = DataTableApp()
async with app.run_test():
table = app.query_one(DataTable)
table.add_column("A")
table.add_row("1", key="1")
with pytest.raises(DuplicateKey):
table.add_row("2", key="1") # Duplicate row key
async def test_add_column_duplicate_key():
app = DataTableApp()
async with app.run_test():
table = app.query_one(DataTable)
table.add_column("A", key="A")
with pytest.raises(DuplicateKey):
table.add_column("B", key="A") # Duplicate column key
async def test_add_column_with_width():
app = DataTableApp()
async with app.run_test():