mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Add tests for DataTable.get_cell_value
This commit is contained in:
@@ -5,8 +5,7 @@ from textual.app import App
|
|||||||
from textual.coordinate import Coordinate
|
from textual.coordinate import Coordinate
|
||||||
from textual.message import Message
|
from textual.message import Message
|
||||||
from textual.widgets import DataTable
|
from textual.widgets import DataTable
|
||||||
from textual.widgets._data_table import (
|
from textual.widgets.data_table import (
|
||||||
StringKey,
|
|
||||||
CellDoesNotExist,
|
CellDoesNotExist,
|
||||||
RowKey,
|
RowKey,
|
||||||
Row,
|
Row,
|
||||||
@@ -248,6 +247,35 @@ async def test_column_widths() -> None:
|
|||||||
|
|
||||||
|
|
||||||
async def test_get_cell_value_returns_value_at_cell():
|
async def test_get_cell_value_returns_value_at_cell():
|
||||||
|
app = DataTableApp()
|
||||||
|
async with app.run_test():
|
||||||
|
table = app.query_one(DataTable)
|
||||||
|
table.add_column("Column1", key="C1")
|
||||||
|
table.add_row("TargetValue", key="R1")
|
||||||
|
assert table.get_cell_value("R1", "C1") == "TargetValue"
|
||||||
|
|
||||||
|
|
||||||
|
async def test_get_cell_value_invalid_row_key():
|
||||||
|
app = DataTableApp()
|
||||||
|
async with app.run_test():
|
||||||
|
table = app.query_one(DataTable)
|
||||||
|
table.add_column("Column1", key="C1")
|
||||||
|
table.add_row("TargetValue", key="R1")
|
||||||
|
with pytest.raises(CellDoesNotExist):
|
||||||
|
table.get_cell_value("INVALID_ROW", "C1")
|
||||||
|
|
||||||
|
|
||||||
|
async def test_get_cell_value_invalid_column_key():
|
||||||
|
app = DataTableApp()
|
||||||
|
async with app.run_test():
|
||||||
|
table = app.query_one(DataTable)
|
||||||
|
table.add_column("Column1", key="C1")
|
||||||
|
table.add_row("TargetValue", key="R1")
|
||||||
|
with pytest.raises(CellDoesNotExist):
|
||||||
|
table.get_cell_value("R1", "INVALID_COLUMN")
|
||||||
|
|
||||||
|
|
||||||
|
async def test_get_value_at_returns_value_at_cell():
|
||||||
app = DataTableApp()
|
app = DataTableApp()
|
||||||
async with app.run_test():
|
async with app.run_test():
|
||||||
table = app.query_one(DataTable)
|
table = app.query_one(DataTable)
|
||||||
@@ -256,7 +284,7 @@ async def test_get_cell_value_returns_value_at_cell():
|
|||||||
assert table.get_value_at(Coordinate(0, 0)) == "0/0"
|
assert table.get_value_at(Coordinate(0, 0)) == "0/0"
|
||||||
|
|
||||||
|
|
||||||
async def test_get_cell_value_exception():
|
async def test_get_value_at_exception():
|
||||||
app = DataTableApp()
|
app = DataTableApp()
|
||||||
async with app.run_test():
|
async with app.run_test():
|
||||||
table = app.query_one(DataTable)
|
table = app.query_one(DataTable)
|
||||||
@@ -266,15 +294,24 @@ async def test_get_cell_value_exception():
|
|||||||
table.get_value_at(Coordinate(9999, 0))
|
table.get_value_at(Coordinate(9999, 0))
|
||||||
|
|
||||||
|
|
||||||
|
# async def test_update_cell_cell_exists():
|
||||||
|
# app = DataTableApp()
|
||||||
|
# async with app.run_test():
|
||||||
|
# table = app.query_one(DataTable)
|
||||||
|
# table.add_column("A", key="A")
|
||||||
|
# table.add_row("1", key="1")
|
||||||
|
# assert table.get_cell_value()
|
||||||
|
|
||||||
|
|
||||||
def test_key_equals_equivalent_string():
|
def test_key_equals_equivalent_string():
|
||||||
text = "Hello"
|
text = "Hello"
|
||||||
key = StringKey(text)
|
key = RowKey(text)
|
||||||
assert key == text
|
assert key == text
|
||||||
assert hash(key) == hash(text)
|
assert hash(key) == hash(text)
|
||||||
|
|
||||||
|
|
||||||
def test_key_doesnt_match_non_equal_string():
|
def test_key_doesnt_match_non_equal_string():
|
||||||
key = StringKey("123")
|
key = ColumnKey("123")
|
||||||
text = "laksjdlaskjd"
|
text = "laksjdlaskjd"
|
||||||
assert key != text
|
assert key != text
|
||||||
assert hash(key) != hash(text)
|
assert hash(key) != hash(text)
|
||||||
@@ -293,9 +330,9 @@ def test_key_string_lookup():
|
|||||||
# in tests how we intend for the keys to work for cache lookups.
|
# in tests how we intend for the keys to work for cache lookups.
|
||||||
dictionary = {
|
dictionary = {
|
||||||
"foo": "bar",
|
"foo": "bar",
|
||||||
StringKey("hello"): "world",
|
RowKey("hello"): "world",
|
||||||
}
|
}
|
||||||
assert dictionary["foo"] == "bar"
|
assert dictionary["foo"] == "bar"
|
||||||
assert dictionary[StringKey("foo")] == "bar"
|
assert dictionary[RowKey("foo")] == "bar"
|
||||||
assert dictionary["hello"] == "world"
|
assert dictionary["hello"] == "world"
|
||||||
assert dictionary[StringKey("hello")] == "world"
|
assert dictionary[RowKey("hello")] == "world"
|
||||||
|
|||||||
Reference in New Issue
Block a user