mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Testing case where you try to update cells which dont exist
This commit is contained in:
@@ -523,8 +523,17 @@ class DataTable(ScrollView, Generic[CellType], can_focus=True):
|
|||||||
value: The new value to put inside the cell.
|
value: The new value to put inside the cell.
|
||||||
update_width: Whether to resize the column width to accommodate
|
update_width: Whether to resize the column width to accommodate
|
||||||
for the new cell content.
|
for the new cell content.
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
CellDoesNotExist: When the supplied `row_key` and `column_key`
|
||||||
|
cannot be found in the table.
|
||||||
"""
|
"""
|
||||||
|
try:
|
||||||
self.data[row_key][column_key] = value
|
self.data[row_key][column_key] = value
|
||||||
|
except KeyError:
|
||||||
|
raise CellDoesNotExist(
|
||||||
|
f"No cell exists for row_key={row_key!r}, column_key={column_key!r}."
|
||||||
|
) from None
|
||||||
self._update_count += 1
|
self._update_count += 1
|
||||||
|
|
||||||
# Recalculate widths if necessary
|
# Recalculate widths if necessary
|
||||||
@@ -545,6 +554,7 @@ class DataTable(ScrollView, Generic[CellType], can_focus=True):
|
|||||||
update_width: Whether to resize the column width to accommodate
|
update_width: Whether to resize the column width to accommodate
|
||||||
for the new cell content.
|
for the new cell content.
|
||||||
"""
|
"""
|
||||||
|
# TODO: Validate coordinate and raise exception
|
||||||
row_key, column_key = self.coordinate_to_cell_key(coordinate)
|
row_key, column_key = self.coordinate_to_cell_key(coordinate)
|
||||||
self.update_cell(row_key, column_key, value, update_width=update_width)
|
self.update_cell(row_key, column_key, value, update_width=update_width)
|
||||||
|
|
||||||
|
|||||||
@@ -303,6 +303,16 @@ async def test_update_cell_cell_exists():
|
|||||||
assert table.get_cell_value("1", "A") == "NEW_VALUE"
|
assert table.get_cell_value("1", "A") == "NEW_VALUE"
|
||||||
|
|
||||||
|
|
||||||
|
async def test_update_cell_cell_doesnt_exist():
|
||||||
|
app = DataTableApp()
|
||||||
|
async with app.run_test():
|
||||||
|
table = app.query_one(DataTable)
|
||||||
|
table.add_column("A", key="A")
|
||||||
|
table.add_row("1", key="1")
|
||||||
|
with pytest.raises(CellDoesNotExist):
|
||||||
|
table.update_cell("INVALID", "CELL", "Value")
|
||||||
|
|
||||||
|
|
||||||
# TODO: Test update coordinate
|
# TODO: Test update coordinate
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user