From 10c3deb9d238a794a4d724d76d5a23d1cc382712 Mon Sep 17 00:00:00 2001 From: Darren Burns Date: Wed, 8 Feb 2023 12:49:59 +0000 Subject: [PATCH] Testing reverse sort --- tests/test_data_table.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/test_data_table.py b/tests/test_data_table.py index 0abeb278e..3b8ff25d0 100644 --- a/tests/test_data_table.py +++ b/tests/test_data_table.py @@ -580,6 +580,35 @@ async def test_sort_coordinate_and_key_access(): assert table.get_value_at(Coordinate(2, 0)) == 3 +async def test_sort_reverse_coordinate_and_key_access(): + """Ensure that, after sorting, that coordinates and cell keys + can still be used to retrieve the correct cell.""" + app = DataTableApp() + async with app.run_test(): + table = app.query_one(DataTable) + column = table.add_column("number") + row_three = table.add_row(3) + row_one = table.add_row(1) + row_two = table.add_row(2) + + # Items inserted in correct initial positions (before sort) + assert table.get_value_at(Coordinate(0, 0)) == 3 + assert table.get_value_at(Coordinate(1, 0)) == 1 + assert table.get_value_at(Coordinate(2, 0)) == 2 + + table.sort(column, reverse=True) + + # The keys still refer to the same cells... + assert table.get_cell_value(row_one, column) == 1 + assert table.get_cell_value(row_two, column) == 2 + assert table.get_cell_value(row_three, column) == 3 + + # ...even though the values under the coordinates have changed... + assert table.get_value_at(Coordinate(0, 0)) == 3 + assert table.get_value_at(Coordinate(1, 0)) == 2 + assert table.get_value_at(Coordinate(2, 0)) == 1 + + def test_key_equals_equivalent_string(): text = "Hello" key = RowKey(text)