def test_table_editor_escape_retain_edit(self): object_list = ObjectListWithSelection(values=[ListItem(other_value=0)]) tester = UITester() with tester.create_ui(object_list, dict(view=select_row_view)) as ui: cell = tester.find_by_name(ui, "values").locate(Cell(0, 1)) cell.perform(MouseClick()) cell.perform(KeySequence("123")) cell.perform(KeyClick("Esc")) # exit edit mode, did not revert self.assertEqual(object_list.values[0].other_value, 123)
def test_table_editor_modify_cell_with_tester(self): object_list = ObjectListWithSelection( values=[ListItem(value=str(i**2)) for i in range(10)]) tester = UITester() with tester.create_ui(object_list, dict(view=select_row_view)) as ui: wrapper = tester.find_by_name(ui, "values").locate(Cell(5, 0)) wrapper.perform(MouseClick()) # activate edit mode wrapper.perform(KeySequence("abc")) self.assertEqual(object_list.selected.value, "abc") # second column refers to an Int type original = object_list.selected.other_value wrapper = tester.find_by_name(ui, "values").locate(Cell(5, 1)) wrapper.perform(MouseClick()) wrapper.perform(KeySequence("abc")) # invalid self.assertEqual(object_list.selected.other_value, original) for _ in range(3): wrapper.perform(KeyClick("Backspace")) wrapper.perform(KeySequence("12")) # now ok self.assertEqual(object_list.selected.other_value, 12)
def test_table_editor_check_display_with_tester(self): object_list = ObjectListWithSelection(values=[ListItem(other_value=0)]) tester = UITester() with tester.create_ui(object_list, dict(view=select_row_view)) as ui: wrapper = tester.find_by_name(ui, "values").locate(Cell(0, 1)) actual = wrapper.inspect(DisplayedText()) self.assertEqual(actual, "0") object_list.values[0].other_value = 123 actual = wrapper.inspect(DisplayedText()) self.assertEqual(actual, "123")
def test_table_editor_select_row_index(self): object_list = ObjectListWithSelection( values=[ListItem(value=str(i**2)) for i in range(10)]) object_list.selected_index = 5 tester = UITester() with tester.create_ui(object_list, dict(view=select_row_index_view)) \ as ui: values_table = tester.find_by_name(ui, "values") values_table.locate(Cell(5, 0)).perform(MouseClick()) selected = values_table.inspect(SelectedIndices()) self.assertEqual(selected, [5])
def test_table_editor_select_cell_index(self): object_list = ObjectListWithSelection( values=[ListItem(value=str(i**2)) for i in range(10)]) view = select_cell_index_view tester = UITester() with tester.create_ui(object_list, dict(view=view)) as ui: # click the cell at (5,1) values_table = tester.find_by_name(ui, "values") cell_5_1 = values_table.locate(Cell(5, 1)) cell_5_1.perform(MouseClick()) selected = values_table.inspect(SelectedIndices()) self.assertEqual(selected, [(5, 1)])
def test_table_editor_select_cell(self): object_list = ObjectListWithSelection( values=[ListItem(value=str(i**2)) for i in range(10)]) tester = UITester() with tester.create_ui(object_list, dict(view=select_cell_view)) as ui: # click the cell at (5,0) values_table = tester.find_by_name(ui, "values") cell_5_0 = values_table.locate(Cell(5, 0)) cell_5_0.perform(MouseClick()) selected = values_table.inspect(Selected()) self.assertEqual(selected, [(object_list.values[5], "value")]) self.assertIs(selected[0], object_list.selected_cell)
def test_table_editor_select_row(self): object_list = ObjectListWithSelection( values=[ListItem(value=str(i**2)) for i in range(10)]) tester = UITester() with tester.create_ui(object_list, dict(view=select_row_view)) as ui: # click the first cell in the 6th row to select the row values_table = tester.find_by_name(ui, "values") row6_cell = values_table.locate(Cell(5, 0)) row6_cell.perform(MouseClick()) selected = values_table.inspect(Selected()) self.assertEqual(selected, [object_list.values[5]]) self.assertIs(selected[0], object_list.values[5]) self.assertIs(object_list.selected, selected[0])
def test_edit_on_first_click_false(self): object_list = ObjectListWithSelection( values=[ListItem(value=str(i**2)) for i in range(10)]) tester = UITester() with tester.create_ui(object_list, dict(view=edit_on_first_click_false_view)) as ui: wrapper = tester.find_by_name(ui, "values").locate(Cell(5, 0)) # single click will not activate edit mode wrapper.perform(MouseClick()) with self.assertRaises(Disabled): wrapper.perform(KeySequence("abc")) # double click will activate edit mode wrapper.perform(MouseDClick()) wrapper.perform(KeySequence("abc")) self.assertEqual(object_list.values[5].value, "abc")
def test_table_editor_select_column(self): object_list = ObjectListWithSelection( values=[ListItem(value=str(i**2)) for i in range(10)]) tester = UITester() with tester.create_ui(object_list, dict(view=select_column_view)) \ as ui: values_table = tester.find_by_name(ui, "values") # click a cell in the first column (the "value" column) first_cell = values_table.locate(Cell(0, 0)) first_cell.perform(MouseClick()) selected = values_table.inspect(Selected()) self.assertEqual(selected, ["value"]) self.assertIs(selected[0], "value") self.assertIs(selected[0], object_list.selected_column)