def test_that_load_grouping_inserts_loaded_groups_and_pairs_correctly( self): 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") ] self._run_handle_load_grouping_with_mocked_load(groups, pairs, default='pair1') self.assertCountEqual(self.model.group_names, ["grp1", "grp2"]) self.assertCountEqual(self.model.pair_names, ["pair1"]) self.assertEqual(self.grouping_table_view.num_rows(), 2) self.assertEqual(self.pairing_table_view.num_rows(), 1) self.assertEqual( self.pairing_table_view.pairing_table.cellWidget(0, 2).currentText(), "grp1") self.assertEqual( self.pairing_table_view.pairing_table.cellWidget(0, 3).currentText(), "grp2")
def add_three_groups(self): testgroup1 = MuonGroup(group_name="fwd", detector_ids=[1, 2, 3, 4, 5]) testgroup2 = MuonGroup(group_name="bwd", detector_ids=[6, 7, 8, 9, 10]) testgroup3 = MuonGroup(group_name="top", detector_ids=[11, 12, 13, 14, 15]) self.grouping_table_widget.add_group(testgroup1) self.grouping_table_widget.add_group(testgroup2) self.grouping_table_widget.add_group(testgroup3)
def test_loading_selects_groups_if_no_pairs_exist_and_no_default_set(self): groups = [ MuonGroup(group_name="grp1", detector_ids=[1, 2, 3, 4, 5]), MuonGroup(group_name="grp2", detector_ids=[6, 7, 8, 9, 10]) ] pairs = [] self._run_handle_load_grouping_with_mocked_load(groups, pairs, default='') self.assertEqual(self.model.selected_pairs, []) self.assertEqual(self.model.selected_groups, ["grp1", "grp2"])
def test_loading_selects_correctly_when_default_is_invalid(self): 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") ] self._run_handle_load_grouping_with_mocked_load(groups, pairs, default='grp3') self.assertEqual(self.model.selected_pairs, ["pair1"]) self.assertEqual(self.model.selected_groups, [])
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, [], 'description', 'pair1') 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")
def test_loading_does_not_insert_invalid_groups(self): groups = [ MuonGroup(group_name="grp1", detector_ids=[1, 2, 3, 4, 5]), MuonGroup(group_name="grp2", detector_ids=[6, 7, 8, 9, 1000]) ] pairs = [ MuonPair(pair_name="pair1", forward_group_name="grp1", backward_group_name="grp2") ] self._run_handle_load_grouping_with_mocked_load(groups, pairs, default='pair1') self.view.display_warning_box.assert_called_once_with( 'Invalid detectors in group grp2') self.assertCountEqual(self.model.group_names, ["grp1"]) self.assertCountEqual(self.model.pair_names, []) self.assertEqual(self.grouping_table_view.num_rows(), 1) self.assertEqual(self.pairing_table_view.num_rows(), 0)