def setUp(self):
        self._qapp = mock_widget.mockQapp()

        # Store an empty widget to parent all the views, and ensure they are deleted correctly
        self.obj = QtGui.QWidget()

        self.popup_patcher = mock.patch('Muon.GUI.Common.thread_model.warning')
        self.addCleanup(self.popup_patcher.stop)
        self.popup_mock = self.popup_patcher.start()

        self.load_patcher = mock.patch(
            'Muon.GUI.Common.load_file_widget.model.load_utils.load_workspace_from_filename'
        )
        self.addCleanup(self.load_patcher.stop)
        self.load_mock = self.load_patcher.start()

        self.load_run_patcher = mock.patch(
            'Muon.GUI.Common.load_run_widget.load_run_model.load_utils.load_workspace_from_filename'
        )
        self.addCleanup(self.load_run_patcher.stop)
        self.load_run_mock = self.load_run_patcher.start()

        self.data = MuonLoadData()
        self.context = MuonDataContext(self.data)
        self.context.instrument = 'EMU'
        self.load_file_view = BrowseFileWidgetView(self.obj)
        self.load_run_view = LoadRunWidgetView(self.obj)
        self.load_file_model = BrowseFileWidgetModel(self.data, self.context)
        self.load_run_model = LoadRunWidgetModel(self.data, self.context)

        self.model = LoadWidgetModel(self.data, self.context)
        self.view = LoadWidgetView(parent=self.obj,
                                   load_run_view=self.load_run_view,
                                   load_file_view=self.load_file_view)

        self.presenter = LoadWidgetPresenter(view=self.view, model=self.model)
        self.presenter.set_load_file_widget(
            BrowseFileWidgetPresenter(self.load_file_view,
                                      self.load_file_model))
        self.presenter.set_load_run_widget(
            LoadRunWidgetPresenter(self.load_run_view, self.load_run_model))
        self.presenter.load_run_widget.set_current_instrument('EMU')

        self.presenter.load_file_widget._view.warning_popup = mock.MagicMock()
        self.presenter.load_run_widget._view.warning_popup = mock.MagicMock()

        self.load_file_view.show_file_browser_and_return_selection = mock.Mock(
            return_value=["C:\\dir1\\EMU0001234.nxs"])
        self.workspace_mock = self.create_fake_workspace(1)
        self.load_mock.return_value = (self.workspace_mock, 1234,
                                       "C:\\dir1\\EMU0001234.nxs")
        self.load_run_mock.return_value = (self.workspace_mock, 1234,
                                           "C:\\dir1\\EMU0001234.nxs")

        self.presenter.load_file_widget.on_browse_button_clicked()
        self.wait_for_thread(self.presenter.load_file_widget._load_thread)

        self.mock_loading_to_throw()
        file_utils.get_current_run_filename = mock.Mock(
            return_value="EMU0001234.nxs")
示例#2
0
def setup_context(freq=False):
    loaded_data = MuonLoadData()
    loaded_data.get_main_field_direction = mock.MagicMock(
        return_value='transverse')
    data_context = MuonDataContext(load_data=loaded_data)
    gui_context = MuonGuiContext()
    group_context = MuonGroupPairContext(
        data_context.check_group_contains_valid_detectors)
    phase_table_context = PhaseTableContext()
    fitting_context = FittingContext()
    freq_context = FrequencyContext()
    if freq:
        return FrequencyDomainAnalysisContext(
            muon_data_context=data_context,
            muon_group_context=group_context,
            muon_gui_context=gui_context,
            muon_phase_context=phase_table_context,
            fitting_context=fitting_context,
            frequency_context=freq_context)
    else:
        return DataAnalysisContext(muon_data_context=data_context,
                                   muon_group_context=group_context,
                                   muon_gui_context=gui_context,
                                   muon_phase_context=phase_table_context,
                                   fitting_context=fitting_context)
    def setUp(self):
        self._qapp = mock_widget.mockQapp()
        self.view = BrowseFileWidgetView()

        self.view.on_browse_clicked = mock.Mock()
        self.view.set_file_edit = mock.Mock()
        self.view.reset_edit_to_cached_value = mock.Mock()
        self.view.show_file_browser_and_return_selection = mock.Mock(
            return_value=["C:/dir1/file1.nxs", "C:/dir2/file2.nxs"])

        self.data = MuonLoadData()
        self.context = MuonDataContext
        self.context.instrument = 'EMU'
        self.model = BrowseFileWidgetModel(self.data, self.context)
        self.model.exception_message_for_failed_files = mock.Mock()

        self.view.disable_load_buttons = mock.Mock()
        self.view.enable_load_buttons = mock.Mock()
        self.view.warning_popup = mock.Mock()

        self.presenter = BrowseFileWidgetPresenter(self.view, self.model)

        patcher = mock.patch(
            'Muon.GUI.Common.load_file_widget.model.load_utils')
        self.addCleanup(patcher.stop)
        self.load_utils_patcher = patcher.start()
示例#4
0
    def setUp(self):
        self._qapp = mock_widget.mockQapp()
        # Store an empty widget to parent all the views, and ensure they are deleted correctly
        self.obj = QtGui.QWidget()

        self.data = MuonLoadData()
        self.view = LoadRunWidgetView(parent=self.obj)
        self.model = LoadRunWidgetModel(self.data)
        self.presenter = LoadRunWidgetPresenter(self.view, self.model)

        self.model.load_workspace_from_filename = mock.Mock(
            return_value=([1, 2, 3], "currentRun.nxs", 1234))
        self.view.warning_popup = mock.Mock()
        self.view.disable_load_buttons = mock.Mock()
        self.view.enable_load_buttons = mock.Mock()

        self.presenter.set_current_instrument("EMU")

        fileUtils.get_current_run_filename = mock.Mock(
            return_value="EMU0001234.nxs")

        patcher = mock.patch(
            'Muon.GUI.Common.load_run_widget.model.load_utils')
        self.addCleanup(patcher.stop)
        self.load_utils_patcher = patcher.start()
        self.load_utils_patcher.exception_message_for_failed_files.return_value = ''
示例#5
0
def setup_context(freq=False):
    loaded_data = MuonLoadData()
    loaded_data.get_main_field_direction = mock.MagicMock(
        return_value='transverse')
    data_context = MuonDataContext(load_data=loaded_data)
    gui_context = MuonGuiContext()
    group_context = MuonGroupPairContext(
        data_context.check_group_contains_valid_detectors)
    corrections_context = CorrectionsContext(loaded_data)
    phase_table_context = PhaseTableContext()
    freq_context = FrequencyContext()
    plot_panes_context = PlotPanesContext()

    if freq:
        return FrequencyDomainAnalysisContext(
            muon_data_context=data_context,
            muon_group_context=group_context,
            muon_gui_context=gui_context,
            muon_phase_context=phase_table_context,
            corrections_context=corrections_context,
            fitting_context=BasicFittingContext(
                allow_double_pulse_fitting=True),
            frequency_context=freq_context,
            plot_panes_context=plot_panes_context)
    else:
        return DataAnalysisContext(muon_data_context=data_context,
                                   muon_group_context=group_context,
                                   muon_gui_context=gui_context,
                                   corrections_context=corrections_context,
                                   muon_phase_context=phase_table_context,
                                   fitting_context=TFAsymmetryFittingContext(
                                       allow_double_pulse_fitting=True),
                                   results_context=ResultsContext(),
                                   model_fitting_context=ModelFittingContext(),
                                   plot_panes_context=plot_panes_context)
示例#6
0
    def __init__(self, loaded_data_store=MuonLoadData(), context=None):
        # Used with load thread
        self._filenames = []

        self._loaded_data_store = loaded_data_store
        self._data_context = context.data_context
        self._current_run = None
示例#7
0
def setup_context_for_tests(parent_object):
    parent_object.loaded_data = MuonLoadData()
    parent_object.loaded_data.get_main_field_direction = mock.MagicMock(
        return_value='transverse')
    parent_object.data_context = MuonDataContext(
        load_data=parent_object.loaded_data)
    parent_object.gui_context = MuonGuiContext()
    parent_object.group_context = MuonGroupPairContext(
        parent_object.data_context.check_group_contains_valid_detectors)
    parent_object.corrections_context = CorrectionsContext(
        parent_object.loaded_data)
    parent_object.phase_table_context = PhaseTableContext()
    parent_object.fitting_context = TFAsymmetryFittingContext(
        allow_double_pulse_fitting=True)
    parent_object.results_context = ResultsContext()
    parent_object.plot_panes_context = PlotPanesContext()
    parent_object.model_fitting_context = ModelFittingContext()
    parent_object.context = DataAnalysisContext(
        muon_data_context=parent_object.data_context,
        muon_group_context=parent_object.group_context,
        muon_gui_context=parent_object.gui_context,
        muon_phase_context=parent_object.phase_table_context,
        corrections_context=parent_object.corrections_context,
        fitting_context=parent_object.fitting_context,
        results_context=parent_object.results_context,
        model_fitting_context=parent_object.model_fitting_context,
        plot_panes_context=parent_object.plot_panes_context)
示例#8
0
    def setUp(self):
        self._qapp = mock_widget.mockQapp()
        # Store an empty widget to parent all the views, and ensure they are deleted correctly
        self.obj = QtGui.QWidget()
        ConfigService['default.instrument'] = 'MUSR'

        self.data = MuonLoadData()
        self.context = MuonDataContext(self.data)
        self.context.instrument = 'MUSR'
        self.load_file_view = BrowseFileWidgetView(self.obj)
        self.load_run_view = LoadRunWidgetView(self.obj)
        self.load_file_model = BrowseFileWidgetModel(self.data, self.context)
        self.load_run_model = LoadRunWidgetModel(self.data, self.context)

        self.view = LoadWidgetView(parent=self.obj,
                                   load_file_view=self.load_file_view,
                                   load_run_view=self.load_run_view)
        self.presenter = LoadWidgetPresenter(
            self.view, LoadWidgetModel(self.data, self.context))
        self.presenter.set_load_file_widget(
            BrowseFileWidgetPresenter(self.load_file_view,
                                      self.load_file_model))
        self.presenter.set_load_run_widget(
            LoadRunWidgetPresenter(self.load_run_view, self.load_run_model))

        self.presenter.load_file_widget._view.warning_popup = mock.MagicMock()
        self.presenter.load_run_widget._view.warning_popup = mock.MagicMock()

        self.view.multiple_loading_check.setCheckState(1)
        self.presenter.handle_multiple_files_option_changed()

        self.runs = [15196, 15197]
        self.workspaces = [self.create_fake_workspace(1) for _ in self.runs]
        self.filenames = FileFinder.findRuns(
            'MUSR00015196.nxs, MUSR00015197.nxs')
示例#9
0
    def setUp(self):
        AnalysisDataService.clear()
        self.filepath = FileFinder.findRuns('EMU00019489.nxs')[0]
        self.load_result, self.run_number, self.filename = load_workspace_from_filename(
            self.filepath)
        self.loaded_data = MuonLoadData()
        self.data_context = MuonDataContext(self.loaded_data)
        self.gui_context = MuonGuiContext()
        self.group_pair_context = MuonGroupPairContext()
        self.gui_context.update({'RebinType': 'None'})

        self.context = MuonContext(muon_data_context=self.data_context,
                                   muon_gui_context=self.gui_context,
                                   muon_group_context=self.group_pair_context)

        self.data_context.instrument = 'EMU'

        self.loaded_data.add_data(workspace=self.load_result,
                                  run=[self.run_number],
                                  filename=self.filename,
                                  instrument='EMU')
        self.data_context.current_runs = [[self.run_number]]
        self.data_context.update_current_data()
        self.group_pair_context.reset_group_and_pairs_to_default(
            self.load_result['OutputWorkspace'][0]._workspace, 'EMU', '')
示例#10
0
    def setUp(self):
        self.data = MuonLoadData()
        self.model = BrowseFileWidgetModel(self.data)

        patcher = mock.patch(
            'Muon.GUI.Common.load_file_widget.model.load_utils')
        self.addCleanup(patcher.stop)
        self.load_utils_patcher = patcher.start()
示例#11
0
    def test_data_can_be_added_correctly_via_keyword_args(self):
        data = MuonLoadData()
        data.add_data(run=1234, workspace=[1], filename="C:\\dir1\\file1.nxs")

        self.assertEqual(data.num_items(), 1)
        self.assertEqual(data.contains_n(run=1234), 1)
        self.assertEqual(data.contains_n(workspace=[1]), 1)
        self.assertEqual(data.contains_n(filename="C:\\dir1\\file1.nxs"), 1)
    def setUp(self):
        self.loaded_data = MuonLoadData()
        self.context = MuonDataContext(self.loaded_data)
        self.context.instrument = 'EMU'

        self.loaded_data.add_data(workspace=self.load_result, run=[self.run_number], filename=self.filename, instrument='EMU')
        self.context.current_runs = [[self.run_number]]
        self.context.update_current_data()
示例#13
0
 def setUp(self):
     self.muon_load_data = MuonLoadData()
     self.workspace = mock.MagicMock()
     self.workspace_last = mock.MagicMock()
     self.muon_load_data.add_data(run=1, workspace=mock.MagicMock(), filename='path to file')
     self.muon_load_data.add_data(run=2, workspace=self.workspace, filename='path to file')
     self.muon_load_data.add_data(run=3, workspace=mock.MagicMock(), filename='matching path')
     self.muon_load_data.add_data()
     self.muon_load_data.add_data(run=4, workspace=self.workspace_last, filename='path to file')
示例#14
0
    def test_counting_entries_with_keyword_argument_gives_correct_count(self):
        data = MuonLoadData()

        data.add_data(run=1234, workspace=[1], filename="C:\\dir1\\file1.nxs")
        data.add_data(run=1235, workspace=[2], filename="C:\\dir1\\file2.nxs")
        data.add_data(run=1234, workspace=[3], filename="C:\\dir1\\file3.nxs")

        self.assertEqual(data.contains_n(run=1234), 2)
        self.assertEqual(data.contains_n(filename="C:\\dir1\\file1.nxs"), 1)
        self.assertEqual(data.contains_n(run=9999), 0)
示例#15
0
    def test_that_contains_is_false_when_data_contains_entries_which_match_to_only_one_of_multiple_keywords(self):
        data = MuonLoadData()

        data.add_data(run=1234, workspace=[1], filename="C:\\dir1\\file1.nxs")
        data.add_data(run=1235, workspace=[2], filename="C:\\dir1\\file2.nxs")
        data.add_data(run=1234, workspace=[3], filename="C:\\dir1\\file3.nxs")

        # values from keywords correspond to different entries
        self.assertFalse(data.contains(run=1234, filename="C:\\dir1\\file2.nxs"))
        self.assertTrue(data.contains(run=1234, workspace=[3]))
示例#16
0
def setup_context_for_ea_tests(parent_object):
    parent_object.loaded_data = MuonLoadData()
    parent_object.data_context = DataContext(
        load_data=parent_object.loaded_data)
    parent_object.gui_context = MuonGuiContext()
    parent_object.plot_panes_context = PlotPanesContext()
    parent_object.group_context = EAGroupContext(
        parent_object.data_context.check_group_contains_valid_detectors)
    parent_object.context = ElementalAnalysisContext(
        parent_object.data_context, parent_object.group_context,
        parent_object.gui_context, parent_object.plot_panes_context)
示例#17
0
    def test_counting_entries_applies_AND_behaviour_to_keyword_arguments(self):
        data = MuonLoadData()

        data.add_data(run=1234, workspace=[1], filename="C:\\dir1\\file1.nxs")
        data.add_data(run=1235, workspace=[2], filename="C:\\dir1\\file2.nxs")
        data.add_data(run=1234, workspace=[3], filename="C:\\dir1\\file3.nxs")
        data.add_data(run=1236, workspace=[4], filename="C:\\dir1\\file4.nxs")

        self.assertEqual(data.contains_n(run=1234, workspace=[1]), 1)
        self.assertEqual(data.contains_n(run=1234, workspace=[2]), 0)
        self.assertEqual(data.contains_n(run=1234, workspace=[2], filename="C:\\dir1\\file4.nxs"), 0)
示例#18
0
def setup_context_for_tests(parent_object):
    parent_object.loaded_data = MuonLoadData()
    parent_object.loaded_data.get_main_field_direction = mock.MagicMock(return_value='transverse')
    parent_object.data_context = MuonDataContext(load_data=parent_object.loaded_data)
    parent_object.gui_context = MuonGuiContext()
    parent_object.group_context = MuonGroupPairContext(parent_object.data_context.check_group_contains_valid_detectors)
    parent_object.phase_table_context = PhaseTableContext()
    parent_object.fitting_context = FittingContext()
    parent_object.context = MuonContext(muon_data_context=parent_object.data_context, muon_group_context=parent_object.group_context,
                                        muon_gui_context=parent_object.gui_context, muon_phase_context=parent_object.phase_table_context,
                                        fitting_context=parent_object.fitting_context)
示例#19
0
    def test_that_remove_method_can_remove_several_entries_at_once(self):
        data = MuonLoadData()

        data.add_data(run=1234, workspace=[1], filename="C:\\dir1\\file1.nxs")
        data.add_data(run=1234, workspace=[2], filename="C:\\dir1\\file2.nxs")
        data.add_data(run=1234, workspace=[3], filename="C:\\dir1\\file3.nxs")
        self.assertEqual(data.num_items(), 3)

        data.remove_data(run=1234)

        self.assert_empty(data)
示例#20
0
    def test_that_contains_is_true_when_data_contains_entry_which_matches_to_a_single_keyword_and_false_otherwise(self):
        data = MuonLoadData()

        data.add_data(run=1234, workspace=[1], filename="C:\\dir1\\file1.nxs")
        data.add_data(run=1235, workspace=[2], filename="C:\\dir1\\file2.nxs")
        data.add_data(run=1234, workspace=[3], filename="C:\\dir1\\file3.nxs")

        self.assertTrue(data.contains(run=1234))
        self.assertTrue(data.contains(filename="C:\\dir1\\file1.nxs"))

        self.assertFalse(data.contains(run=9999))
        self.assertFalse(data.contains(filename="C:\\dir1\\file4.nxs"))
示例#21
0
    def __init__(self, parent=None):
        super(MuonAnalysisGui, self).__init__(parent)
        self.setFocusPolicy(QtCore.Qt.StrongFocus)

        try:
            check_facility()
        except AttributeError as error:
            self.warning_popup(error.args[0])

        # initialise the data storing classes of the interface
        self.loaded_data = MuonLoadData()
        self.context = MuonDataContext(load_data=self.loaded_data)

        # construct all the widgets.
        self.load_widget = LoadWidget(self.loaded_data, self.context, self)
        self.grouping_tab_widget = GroupingTabWidget(self.context)
        self.home_tab = HomeTabWidget(self.context, self)

        self.setup_tabs()
        self.help_widget = HelpWidget()

        central_widget = QtGui.QWidget()
        vertical_layout = QtGui.QVBoxLayout()

        vertical_layout.addWidget(self.load_widget.load_widget_view)
        vertical_layout.addWidget(self.tabs)
        vertical_layout.addWidget(self.help_widget.view)
        central_widget.setLayout(vertical_layout)

        self.setCentralWidget(central_widget)
        self.setWindowTitle("Muon Analysis version 2")

        self.home_tab.group_widget.pairAlphaNotifier.add_subscriber(
            self.grouping_tab_widget.group_tab_presenter.loadObserver)

        self.grouping_tab_widget.group_tab_presenter.groupingNotifier.add_subscriber(
            self.home_tab.home_tab_widget.groupingObserver)

        self.context.instrumentNotifier.add_subscriber(
            self.home_tab.home_tab_widget.instrumentObserver)

        self.context.instrumentNotifier.add_subscriber(
            self.load_widget.load_widget.instrumentObserver)

        self.context.instrumentNotifier.add_subscriber(
            self.grouping_tab_widget.group_tab_presenter.instrumentObserver)

        self.load_widget.load_widget.loadNotifier.add_subscriber(
            self.home_tab.home_tab_widget.loadObserver)

        self.load_widget.load_widget.loadNotifier.add_subscriber(
            self.grouping_tab_widget.group_tab_presenter.loadObserver)
示例#22
0
    def __init__(self, load_data=MuonLoadData()):
        """
        Currently, only a single run is loaded into the Home/Grouping tab at once. This is held in the _current_data
        member. The load widget may load multiple runs at once, these are stored in the _loaded_data member.
        Groups and Pairs associated to the current run are stored in _grousp and _pairs as ordered dictionaries.
        """
        self._groups = OrderedDict()
        self._pairs = OrderedDict()

        self._loaded_data = load_data
        self._current_data = {
            "workspace": load_utils.empty_loaded_data()
        }  # self.get_result(False)
示例#23
0
def setup_context():
    loaded_data = MuonLoadData()
    loaded_data.get_main_field_direction = mock.MagicMock(
        return_value='transverse')
    data_context = MuonDataContext(loaded_data)
    gui_context = MuonGuiContext()
    group_context = MuonGroupPairContext(
        data_context.check_group_contains_valid_detectors)
    phase_table_context = PhaseTableContext()
    return MuonContext(muon_data_context=data_context,
                       muon_group_context=group_context,
                       muon_gui_context=gui_context,
                       muon_phase_context=phase_table_context)
示例#24
0
    def setUp(self):
        self._qapp = mock_widget.mockQapp()
        # Store an empty widget to parent all the views, and ensure they are deleted correctly
        self.obj = QtGui.QWidget()

        self.data = MuonLoadData()
        self.context = MuonDataContext(self.data)
        self.context.instrument = 'EMU'
        self.load_file_view = BrowseFileWidgetView(self.obj)
        self.load_run_view = LoadRunWidgetView(self.obj)
        self.load_file_model = BrowseFileWidgetModel(self.data, self.context)
        self.load_run_model = LoadRunWidgetModel(self.data, self.context)

        self.presenter = LoadWidgetPresenter(
            LoadWidgetView(parent=self.obj,
                           load_file_view=self.load_file_view,
                           load_run_view=self.load_run_view),
            LoadWidgetModel(self.data, self.context))
        self.presenter.set_load_file_widget(
            BrowseFileWidgetPresenter(self.load_file_view,
                                      self.load_file_model))
        self.presenter.set_load_run_widget(
            LoadRunWidgetPresenter(self.load_run_view, self.load_run_model))

        self.filepath = FileFinder.findRuns('MUSR00022725.nxs')[0]

        self.load_patcher = mock.patch(
            'Muon.GUI.Common.load_file_widget.model.load_utils.load_workspace_from_filename'
        )
        self.addCleanup(self.load_patcher.stop)
        self.load_mock = self.load_patcher.start()

        self.load_run_patcher = mock.patch(
            'Muon.GUI.Common.load_run_widget.load_run_model.load_utils.load_workspace_from_filename'
        )
        self.addCleanup(self.load_run_patcher.stop)
        self.load_run_mock = self.load_run_patcher.start()

        self.mock_workspace = self.create_fake_workspace(1)
        self.mock_loading_from_browse(self.mock_workspace,
                                      "C:\dir1\dir2\dir3\EMU0001234.nxs", 1234)
        file_utils.get_current_run_filename = mock.Mock(
            return_value="C:\dir1\dir2\dir3\EMU0001234.nxs")

        self.presenter.load_file_widget._view.warning_popup = mock.MagicMock()
        self.presenter.load_run_widget._view.warning_popup = mock.MagicMock()

        self.popup_patcher = mock.patch('Muon.GUI.Common.thread_model.warning')
        self.addCleanup(self.popup_patcher.stop)
        self.popup_mock = self.popup_patcher.start()
    def setUp(self):
        self.filepath = FileFinder.findRuns('EMU00019489.nxs')[0]
        self.load_result, self.run_number, self.filename, _ = load_workspace_from_filename(
            self.filepath)
        self.loaded_data = MuonLoadData()
        self.context = MuonDataContext(load_data=self.loaded_data)
        self.context.instrument = 'EMU'

        self.loaded_data.add_data(workspace=self.load_result,
                                  run=[self.run_number],
                                  filename=self.filename,
                                  instrument='EMU')
        self.context.current_runs = [[self.run_number]]
        self.context.update_current_data()
示例#26
0
    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()
示例#27
0
 def populate_loaded_data(self):
     data = MuonLoadData()
     data.add_data(run=1234,
                   workspace=[1],
                   filename="C:\\dir1\\file1.nxs",
                   instrument='EMU')
     data.add_data(run=1235,
                   workspace=[2],
                   filename="C:\\dir1\\file2.nxs",
                   instrument='EMU')
     data.add_data(run=1236,
                   workspace=[3],
                   filename="C:\\dir1\\file3.nxs",
                   instrument='EMU')
     return data
示例#28
0
    def test_model_is_cleared_correctly(self, load_utils_mock):
        files = [r'EMU00019489.nxs', r'EMU00019490.nxs', r'EMU00019491.nxs']
        load_return_vals = [([1, 2, 3], filename, 19489 + i) for i, filename in enumerate(files)]

        model = LoadRunWidgetModel(MuonLoadData())
        load_utils_mock.load_workspace_from_filename = mock.Mock()
        load_utils_mock.load_workspace_from_filename.side_effect = load_return_vals

        model.loadData(files)
        model.execute()
        self.assertEqual(len(model.loaded_runs), 3)
        model.clear_loaded_data()
        self.assertEqual(model.loaded_workspaces, [])
        self.assertEqual(model.loaded_filenames, [])
        self.assertEqual(model.loaded_runs, [])
示例#29
0
    def test_that_adding_then_removing_single_item_leaves_data_empty(self):
        data = MuonLoadData()

        data.add_data(run=1234, workspace=[1], filename="C:\\dir1\\file1.nxs")
        self.assertEqual(data.num_items(), 1)
        data.remove_data(run=1234)

        self.assert_empty(data)

        data.add_data(run=1234, workspace=[1], filename="C:\\dir1\\file1.nxs")
        data.remove_data(workspace=[1])
        self.assert_empty(data)

        data.add_data(run=1234, workspace=[1], filename="C:\\dir1\\file1.nxs")
        data.remove_data(filename="C:\\dir1\\file1.nxs")
        self.assert_empty(data)
    def setUp(self):
        self._qapp = mock_widget.mockQapp()
        self.data = MuonLoadData()
        self.context = MuonDataContext
        self.context.instrument = 'EMU'
        self.view = BrowseFileWidgetView()
        self.model = BrowseFileWidgetModel(self.data, self.context)

        self.view.disable_load_buttons = mock.Mock()
        self.view.enable_load_buttons = mock.Mock()
        self.view.warning_popup = mock.Mock()

        self.presenter = BrowseFileWidgetPresenter(self.view, self.model)

        patcher = mock.patch('Muon.GUI.Common.load_file_widget.model.load_utils')
        self.addCleanup(patcher.stop)
        self.load_utils_patcher = patcher.start()