class HomeTabRunInfoPresenterTest(unittest.TestCase): def setUp(self): self._qapp = mock_widget.mockQapp() self.obj = QtGui.QWidget() self.context = MuonDataContext() self.view = HomeRunInfoWidgetView(self.obj) self.model = HomeRunInfoWidgetModel(self.context) self.presenter = HomeRunInfoWidgetPresenter(self.view, self.model) self.view.warning_popup = mock.MagicMock() def tearDown(self): self.obj = None def test_runinfo_correct(self): file_path = FileFinder.findRuns('MUSR00022725.nxs')[0] ws, run, filename = load_utils.load_workspace_from_filename(file_path) self.context._loaded_data.remove_data(run=run) self.context._loaded_data.add_data(run=run, workspace=ws, filename=filename) self.context.update_current_data() test_pair = MuonPair('test_pair', 'top', 'bottom', alpha=0.75) self.context.add_pair(pair=test_pair) self.presenter.update_view_from_model() expected_string_list = ['Instrument:MUSR', 'Run:22725', 'Title:FeTeSeT=1F=100', 'Comment:FCfirstsample', 'Start:2009-03-24T04:18:58', 'End:2009-03-24T04:56:26', 'Counts(MEv):20.076704', 'GoodFrames:88540', 'CountsperGoodFrame:226.753', 'CountsperGoodFrameperdet:3.543', 'AverageTemperature(K):2.53386', 'SampleTemperature(K):1.0', 'SampleMagneticField(G):100.0'] self.assertEqual(str(self.view.run_info_box.toPlainText()).replace(' ', '').splitlines(), expected_string_list)
class MuonDataContextTest(unittest.TestCase): def setUp(self): self.loaded_data = MuonLoadData() self.context = MuonDataContext(self.loaded_data) self.context.instrument = 'EMU' filepath = FileFinder.findRuns('EMU00019489.nxs')[0] load_result, run, filename = load_workspace_from_filename(filepath) self.loaded_data.add_data(workspace=load_result, run=[run], filename=filename, instrument='EMU') self.context.current_runs = [[run]] self.context.update_current_data() def tearDown(self): AnalysisDataService.clear() def test_that_setting_a_fixed_rebin_step_calculates_all_groups_and_pairs_twice( self): self.context.gui_variables['RebinType'] = 'Fixed' self.context.gui_variables['RebinFixed'] = '2' self.context.show_all_groups() expected_workspaces = [ 'EMU19489', 'EMU19489 Groups', 'EMU19489; Group; bwd; Asymmetry; #1', 'EMU19489; Group; bwd; Asymmetry; Rebin; #1', 'EMU19489; Group; bwd; Counts; #1', 'EMU19489; Group; bwd; Counts; Rebin; #1', 'EMU19489; Group; fwd; Asymmetry; #1', 'EMU19489; Group; fwd; Asymmetry; Rebin; #1', 'EMU19489; Group; fwd; Counts; #1', 'EMU19489; Group; fwd; Counts; Rebin; #1', 'Muon Data' ] self.assertEqual(AnalysisDataService.getObjectNames(), expected_workspaces) def test_that_setting_no_rebinning_calculates_groups_and_pairs_once(self): self.context.gui_variables['RebinType'] = 'None' self.context.show_all_groups() expected_workspaces = [ 'EMU19489', 'EMU19489 Groups', 'EMU19489; Group; bwd; Asymmetry; #1', 'EMU19489; Group; bwd; Counts; #1', 'EMU19489; Group; fwd; Asymmetry; #1', 'EMU19489; Group; fwd; Counts; #1', 'Muon Data' ] self.assertEqual(AnalysisDataService.getObjectNames(), expected_workspaces) def test_that_setting_a_variable_rebin_step_calculates_all_groups_and_pairs_twice( self): self.context.gui_variables['RebinType'] = 'Variable' self.context.gui_variables['RebinVariable'] = '1,0.1,2' self.context.show_all_groups() expected_workspaces = [ 'EMU19489', 'EMU19489 Groups', 'EMU19489; Group; bwd; Asymmetry; #1', 'EMU19489; Group; bwd; Asymmetry; Rebin; #1', 'EMU19489; Group; bwd; Counts; #1', 'EMU19489; Group; bwd; Counts; Rebin; #1', 'EMU19489; Group; fwd; Asymmetry; #1', 'EMU19489; Group; fwd; Asymmetry; Rebin; #1', 'EMU19489; Group; fwd; Counts; #1', 'EMU19489; Group; fwd; Counts; Rebin; #1', 'Muon Data' ] self.assertEqual(AnalysisDataService.getObjectNames(), expected_workspaces)