diff --git a/scripts/Muon/GUI/Common/grouping_tab_widget/grouping_tab_widget_model.py b/scripts/Muon/GUI/Common/grouping_tab_widget/grouping_tab_widget_model.py index 781738b859c9ef845206d200ab09b91bcaaf5005..8fcaad6e9d127ee28ca01f71a7952a3ecd97e133 100644 --- a/scripts/Muon/GUI/Common/grouping_tab_widget/grouping_tab_widget_model.py +++ b/scripts/Muon/GUI/Common/grouping_tab_widget/grouping_tab_widget_model.py @@ -75,6 +75,12 @@ class GroupingTabModel(object): def remove_groups_by_name(self, name_list): for name in name_list: del self._data.groups[name] + self.remove_pairs_with_removed_name(name) + + def remove_pairs_with_removed_name(self, group_name): + for name, pair in self._data.pairs.items(): + if pair.forward_group == group_name or pair.backward_group == group_name: + del self._data.pairs[name] def remove_pairs_by_name(self, name_list): for name in name_list: diff --git a/scripts/Muon/GUI/Common/pairing_table_widget/pairing_table_widget_presenter.py b/scripts/Muon/GUI/Common/pairing_table_widget/pairing_table_widget_presenter.py index 8c4677ed063974394382f1aaf78546ee28c52803..af3abdd7a431d51e9f2e3b2f54813ec70586d024 100644 --- a/scripts/Muon/GUI/Common/pairing_table_widget/pairing_table_widget_presenter.py +++ b/scripts/Muon/GUI/Common/pairing_table_widget/pairing_table_widget_presenter.py @@ -51,10 +51,16 @@ class PairingTablePresenter(object): self.guessAlphaNotifier.notify_subscribers([pair_name, group1, group2]) def handle_data_change(self, row, col): - changed_item = self._view.get_table_item_text(row, col) + changed_item = self._view.get_table_contents()[row][col] update_model = True if col == 0 and not self.validate_pair_name(changed_item): update_model = False + if col == 1: + if changed_item == self._view.get_table_item_text(row, 2): + update_model = False + if col == 2: + if changed_item == self._view.get_table_item_text(row, 1): + update_model = False if col == 3: if not self.validate_alpha(changed_item): update_model = False diff --git a/scripts/test/Muon/grouping_tab/grouping_tab_presenter_test.py b/scripts/test/Muon/grouping_tab/grouping_tab_presenter_test.py index 66562d1b5c326fa9d4b1f7a0ebef7e26011c0ac6..3ad0cd9f4e9b5e7691cb4ed95fb99a114d84171d 100644 --- a/scripts/test/Muon/grouping_tab/grouping_tab_presenter_test.py +++ b/scripts/test/Muon/grouping_tab/grouping_tab_presenter_test.py @@ -23,7 +23,6 @@ else: class GroupingTabPresenterTest(unittest.TestCase): - def setUp(self): self._qapp = mock_widget.mockQapp() # Store an empty widget to parent all the views, and ensure they are deleted correctly @@ -66,7 +65,6 @@ class GroupingTabPresenterTest(unittest.TestCase): # ------------------------------------------------------------------------------------------------------------------ # TESTS # ------------------------------------------------------------------------------------------------------------------ - def test_context_menu_add_pair_adds_pair_if_two_groups_selected(self): self.grouping_table_view._get_selected_row_indices = mock.Mock(return_value=[0, 1]) self.grouping_table_view.contextMenuEvent(0) @@ -92,14 +90,18 @@ class GroupingTabPresenterTest(unittest.TestCase): self.assertEqual(self.grouping_table_view.num_rows(), 0) self.assertEqual(self.pairing_table_view.num_rows(), 0) - def test_that_load_grouping_triggers_the_correct_function(self): - self.view.show_file_browser_and_return_selection = mock.Mock(return_value="grouping.xml") + @mock.patch("Muon.GUI.Common.grouping_tab_widget.grouping_tab_widget_presenter.xml_utils.load_grouping_from_XML") + def test_that_load_grouping_triggers_the_correct_function(self, mock_load): + self.view.show_file_browser_and_return_selection = mock.MagicMock(return_value="grouping.xml") + groups = [MuonGroup(group_name="grp1", detector_ids=[1, 2, 3, 4, 5]), + MuonGroup(group_name="grp2", detector_ids=[6, 7, 8, 9, 10])] + pairs = [MuonPair(pair_name="pair1", forward_group_name="grp1", backward_group_name="grp2")] + mock_load.return_value = (groups, pairs) - with mock.patch("Muon.GUI.Common.grouping_tab_widget.grouping_tab_widget_presenter.xml_utils.load_grouping_from_XML") as mock_load: - self.view.load_grouping_button.clicked.emit(True) + self.view.load_grouping_button.clicked.emit(True) - self.assertEqual(mock_load.call_count, 1) - self.assertEqual(mock_load.call_args[0][0], "grouping.xml") + self.assertEqual(mock_load.call_count, 1) + self.assertEqual(mock_load.call_args[0][0], "grouping.xml") def test_that_load_grouping_inserts_loaded_groups_and_pairs_correctly(self): self.view.show_file_browser_and_return_selection = mock.Mock(return_value="grouping.xml") @@ -107,7 +109,8 @@ class GroupingTabPresenterTest(unittest.TestCase): MuonGroup(group_name="grp2", detector_ids=[6, 7, 8, 9, 10])] pairs = [MuonPair(pair_name="pair1", forward_group_name="grp1", backward_group_name="grp2")] - with mock.patch("Muon.GUI.Common.grouping_tab_widget.grouping_tab_widget_presenter.xml_utils.load_grouping_from_XML") as mock_load: + with mock.patch( + "Muon.GUI.Common.grouping_tab_widget.grouping_tab_widget_presenter.xml_utils.load_grouping_from_XML") as mock_load: # mock the loading to return set groups/pairs mock_load.return_value = (groups, pairs) self.view.load_grouping_button.clicked.emit(True) @@ -123,7 +126,8 @@ class GroupingTabPresenterTest(unittest.TestCase): # Save functionality is tested elsewhere self.view.show_file_save_browser_and_return_selection = mock.Mock(return_value="grouping.xml") - with mock.patch("Muon.GUI.Common.grouping_tab_widget.grouping_tab_widget_presenter.xml_utils.save_grouping_to_XML") as mock_save: + with mock.patch( + "Muon.GUI.Common.grouping_tab_widget.grouping_tab_widget_presenter.xml_utils.save_grouping_to_XML") as mock_save: self.view.save_grouping_button.clicked.emit(True) self.assertEqual(mock_save.call_count, 1) @@ -136,6 +140,14 @@ class GroupingTabPresenterTest(unittest.TestCase): self.presenter.thread_manager.process.assert_called_once_with(self.presenter.listener, self.presenter.calculate_all_data, 0, [1]) + def test_removing_group_removes_linked_pairs(self): + self.add_three_groups() + self.add_two_pairs() + + self.presenter.grouping_table_widget.remove_last_row_in_view_and_model() + + self.assertEqual(self.model.pair_names, ['long1']) + if __name__ == '__main__': unittest.main(buffer=False, verbosity=2) diff --git a/scripts/test/Muon/grouping_tab/pairing_table_group_selector_test.py b/scripts/test/Muon/grouping_tab/pairing_table_group_selector_test.py index 99df885e022408465ad17947a004bec31b68a606..9817f6bb2bbe76e31eadd02ef4b14a850ac527bf 100644 --- a/scripts/test/Muon/grouping_tab/pairing_table_group_selector_test.py +++ b/scripts/test/Muon/grouping_tab/pairing_table_group_selector_test.py @@ -188,6 +188,25 @@ class GroupSelectorTest(unittest.TestCase): self.assertEqual(self.get_group_1_selector_from_pair(0).currentText(), 'my_group_1') self.assertEqual(self.get_group_2_selector_from_pair(0).currentText(), 'my_group_1') + def test_group_cannot_be_changed_to_match_other_group(self): + self.add_three_groups_to_model() + self.presenter.handle_add_pair_button_clicked() + + self.assertEqual(self.get_group_1_selector_from_pair(0).count(), 3) + self.assertEqual(self.get_group_2_selector_from_pair(0).count(), 3) + self.assertEqual(self.get_group_1_selector_from_pair(0).currentText(), 'my_group_0') + self.assertEqual(self.get_group_2_selector_from_pair(0).currentText(), 'my_group_1') + + group_selector = self.get_group_1_selector_from_pair(0) + group_selector.setCurrentIndex(1) + + self.assertEqual(self.get_group_1_selector_from_pair(0).count(), 3) + self.assertEqual(self.get_group_2_selector_from_pair(0).count(), 3) + self.assertEqual(self.get_group_1_selector_from_pair(0).currentText(), 'my_group_0') + self.assertEqual(self.get_group_2_selector_from_pair(0).currentText(), 'my_group_1') + + + if __name__ == '__main__': unittest.main(buffer=False, verbosity=2)