def add_two_pairs(self): testpair1 = MuonPair(pair_name="long1", forward_group_name="fwd", backward_group_name="bwd") testpair2 = MuonPair(pair_name="long2", forward_group_name="fwd", backward_group_name="top") self.pairing_table_widget.add_pair(testpair1) self.pairing_table_widget.add_pair(testpair2)
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 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 perform_musr_file_finder(self): ConfigService['default.instrument'] = 'MUSR' file_path = FileFinder.findRuns('MUSR00022725.nxs')[0] ws, run, filename, psi_data = load_utils.load_workspace_from_filename( file_path) self.assert_(not psi_data) self.data_context._loaded_data.remove_data(run=run) self.data_context._loaded_data.add_data(run=[run], workspace=ws, filename=filename, instrument='MUSR') self.data_context.current_runs = [[22725]] self.context.data_context._instrument = "MUSR" self.context.update_current_data() test_pair = MuonPair('test_pair', 'top', 'bottom', alpha=0.75) self.group_context.add_pair(pair=test_pair) self.presenter.update_view_from_model()
def test_loading_selects_all_pairs_if_any_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 = [ MuonPair(pair_name="pair1", forward_group_name="grp1", backward_group_name="grp2") ] self._run_handle_load_grouping_with_mocked_load(groups, pairs, default='') 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)