def test_removing_selected_rows(self): def removeWorkspaceIfPresent(loaded_ws_name): model_dict.pop(loaded_ws_name, "") return model_dict.values() self.presenter.row_numbers = data_presenter.TwoWayRowDict() self.presenter.row_numbers["name1"] = 0 self.presenter.row_numbers["name2"] = 1 self.presenter.row_numbers["name3"] = 2 model_dict = {"name1": self.ws1, "name2": self.ws2, "name3": self.ws3} self.model.get_loaded_workspaces.return_value = model_dict self.model.delete_workspace.side_effect = removeWorkspaceIfPresent self.model.delete_workspace.return_value = ["name1", "name2"] self.view.remove_selected.return_value = [0, 2] self.presenter.plot_removed_notifier = mock.MagicMock() self.presenter.plot_added_notifier = mock.MagicMock() self.presenter.all_plots_removed_notifier = mock.MagicMock() self.presenter._remove_selected_tracked_workspaces() self.presenter._handle_table_cell_changed(0, 2) self.assertEqual(1, self.view.remove_selected.call_count) test_dict = data_presenter.TwoWayRowDict() test_dict["name2"] = 0 self.assertEqual(self.presenter.row_numbers, test_dict) self.assertEqual(self.model.delete_workspace.call_count, 2) self.assertEqual( 1, self.presenter.all_plots_removed_notifier.notify_subscribers. call_count) self.assertEqual( 1, self.presenter.plot_added_notifier.notify_subscribers.call_count)
def _setup_bgsub_test(self): mocked_table_item = mock.MagicMock() mocked_table_item.checkState.return_value = True self.view.get_table_item.return_value = mocked_table_item self.presenter.row_numbers = data_presenter.TwoWayRowDict() self.presenter.row_numbers["name1"] = 0 self.presenter.row_numbers["name2"] = 1 self.model.get_loaded_workspaces.return_value = {"name1": self.ws1, "name2": self.ws2} self.model.estimate_background.return_value = self.ws2
def test_inspect_bg_button_enables_and_disables(self): self.view.get_item_checked.return_value = False self.presenter.row_numbers = data_presenter.TwoWayRowDict() self.presenter.row_numbers["name1"] = 0 self.presenter.row_numbers["name2"] = 1 self.view.get_selected_rows.return_value = self.presenter.row_numbers self.presenter._handle_selection_changed() self.view.set_inspect_bg_button_enabled.assert_called_with(True) self.view.get_selected_rows.return_value = {} self.presenter._handle_selection_changed() self.view.set_inspect_bg_button_enabled.assert_called_with(False)
def test_removing_selected_rows(self): self.presenter.row_numbers = data_presenter.TwoWayRowDict() self.presenter.row_numbers["name1"] = 0 self.presenter.row_numbers["name2"] = 1 self.presenter.row_numbers["name3"] = 2 model_dict = {"name1": self.ws1, "name2": self.ws2, "name3": self.ws3} self.model.get_loaded_workspaces.return_value = model_dict self.view.remove_selected.return_value = [0, 2] self.presenter.plot_removed_notifier = mock.MagicMock() self.presenter.plot_added_notifier = mock.MagicMock() self.presenter.all_plots_removed_notifier = mock.MagicMock() self.presenter._remove_selected_tracked_workspaces() self.assertEqual(1, self.view.remove_selected.call_count) test_dict = data_presenter.TwoWayRowDict() test_dict["name2"] = 0 self.assertEqual(self.presenter.row_numbers, test_dict) self.assertEqual(model_dict, {"name2": self.ws2}) self.assertEqual(2, self.presenter.plot_removed_notifier.notify_subscribers.call_count) self.assertEqual(1, self.presenter.plot_added_notifier.notify_subscribers.call_count) self.model.remove_log_rows.assert_called_once_with(self.view.remove_selected())
def test_handle_table_cell_changed_checkbox_unticked(self): self.view.get_item_checked.return_value = False self.presenter.row_numbers = data_presenter.TwoWayRowDict() self.presenter.row_numbers["name1"] = 0 self.presenter.row_numbers["name2"] = 1 model_dict = {"name1": self.ws1, "name2": self.ws2} self.model.get_loaded_workspaces.return_value = model_dict self.presenter.plot_added_notifier = mock.MagicMock() self.presenter.plot_removed_notifier = mock.MagicMock() self.presenter._handle_table_cell_changed(0, 2) self.assertEqual(0, self.presenter.plot_added_notifier.notify_subscribers.call_count) self.assertEqual(1, self.presenter.plot_removed_notifier.notify_subscribers.call_count) self.presenter.plot_removed_notifier.notify_subscribers.assert_any_call(self.ws1)
def test_handle_table_cell_changed_other_element(self): mocked_table_item = mock.MagicMock() mocked_table_item.checkState.return_value = 2 self.view.get_table_item.return_value = mocked_table_item self.presenter.row_numbers = data_presenter.TwoWayRowDict() self.presenter.row_numbers["name1"] = 0 self.presenter.row_numbers["name2"] = 1 model_dict = {"name1": self.ws1, "name2": self.ws2} self.model.get_loaded_workspaces.return_value = model_dict self.presenter.plot_added_notifier = mock.MagicMock() self.presenter.plot_removed_notifier = mock.MagicMock() self.presenter._handle_table_cell_changed(1, 1) self.assertEqual(0, self.presenter.plot_added_notifier.notify_subscribers.call_count) self.assertEqual(0, self.presenter.plot_removed_notifier.notify_subscribers.call_count)
def test_handle_table_cell_changed_checkbox_ticked(self): mocked_table_item = mock.MagicMock() self.view.get_item_checked.side_effect = _get_item_checked_mock self.view.get_table_item.return_value = mocked_table_item self.presenter.row_numbers = data_presenter.TwoWayRowDict() self.presenter.row_numbers["name1"] = 0 self.presenter.row_numbers["name2"] = 1 self.model.get_active_ws.return_value = self.ws1 self.model.get_active_ws_name.return_value = "name1" self.presenter.plot_added_notifier = mock.MagicMock() self.presenter.plot_removed_notifier = mock.MagicMock() self.presenter._handle_table_cell_changed(0, 2) self.assertEqual( 1, self.presenter.plot_added_notifier.notify_subscribers.call_count) self.presenter.plot_added_notifier.notify_subscribers.assert_any_call( self.ws1) self.assertEqual( 0, self.presenter.plot_removed_notifier.notify_subscribers.call_count)