class LoadRunWidgetModelEATest(unittest.TestCase):
    def setUp(self):
        setup_context_for_ea_tests(self)
        self.model = LoadRunWidgetModel(self.loaded_data, self.context)

    def test_model_initialized_with_empty_lists_of_loaded_data(self):
        self.assertEqual(self.model._current_run, None)
        self.assertEqual(self.model._directory, "")
        self.assertEqual(self.model._runs, [])
        self.assertEqual(self.model._loaded_data_store.get_data(), None)
        self.assertEqual(self.model._data_context.run_info, [])

    def test_executing_load_without_runs_does_nothing(self):
        self.model.execute()
        self.assertEqual(self.model._current_run, None)
        self.assertEqual(self.model._directory, "")
        self.assertEqual(self.model._runs, [])
        self.assertEqual(self.model._loaded_data_store.get_data(), None)
        self.assertEqual(self.model._data_context.run_info, [])

    @mock.patch(
        'mantidqtinterfaces.Muon.GUI.ElementalAnalysis2.load_widget.load_models.LoadElementalAnalysisData'
    )
    def test_execute_successfully_loads_valid_run_single(
            self, load_ea_data_mock):
        # Mock the load algorithm
        grpws = mock.Mock()
        grpws.getNames.return_value = ['1234; Detector 1', '1234; Detector 3']
        mocked_path = mock.NonCallableMock()
        load_return_vals = grpws, mocked_path

        load_ea_data_mock.return_value = load_return_vals

        self.model._runs = [1234]
        self.model.execute()
        self.assertEqual(self.model._directory, mocked_path)
        run_info = self.model._data_context.run_info[0]
        self.assertIsInstance(run_info, RunObject)
        self.assertEqual(run_info._run_number, 1234)
        self.assertEqual(run_info._detectors, ["Detector 1", "Detector 3"])
        self.assertEqual(run_info._groupworkspace, grpws)
        self.assertTrue(len(self.model.loaded_runs) > 0)

    @mock.patch(
        'mantidqtinterfaces.Muon.GUI.ElementalAnalysis2.load_widget.load_models.LoadElementalAnalysisData'
    )
    def test_model_is_cleared_correctly(self, load_ea_data_mock):
        grpws = mock.Mock()
        grpws.getNames.return_value = ['1234; Detector 1', '1234; Detector 3']
        mocked_path = mock.NonCallableMock()
        load_return_vals = grpws, mocked_path

        load_ea_data_mock.return_value = load_return_vals

        self.model._runs = [1234, 1255]
        self.model.execute()
        self.assertEqual(len(self.model.loaded_runs), 2)
        self.model.clear_loaded_data()
        self.assertEqual(self.model.loaded_runs, [])
예제 #2
0
    def __init__(self, loaded_data, context, parent):
        # set up the views
        self.load_file_view = BrowseFileWidgetView(parent)
        self.load_file_view.hide_browse()
        self.load_run_view = LoadRunWidgetView(parent)
        self.load_run_view.hide_current_run_button()
        self.load_run_view.hide_instrument_label()
        self.load_widget_view = LoadWidgetView(
            parent=parent,
            load_file_view=self.load_file_view,
            load_run_view=self.load_run_view)
        self.load_widget = LoadWidgetPresenterEA(
            self.load_widget_view, LoadWidgetModel(loaded_data, context))

        self.file_widget = BrowseFileWidgetPresenter(
            self.load_file_view, BrowseFileWidgetModel(loaded_data, context))
        self.run_widget = LoadRunWidgetPresenterEA(
            self.load_run_view, LoadRunWidgetModel(loaded_data, context))

        self.load_widget.set_load_file_widget(self.file_widget)
        self.load_widget.set_load_run_widget(self.run_widget)

        self.load_widget.set_current_instrument(
            context.data_context.instrument)

        self.run_widget.updated_directory.add_subscriber(
            self.file_widget.updated_file_path)
    def setUp(self):
        # Store an empty widget to parent all the views, and ensure they are deleted correctly
        self.obj = QWidget()

        setup_context_for_ea_tests(self)

        self.view = mock.Mock()
        self.model = LoadRunWidgetModel(self.loaded_data, self.context)
        self.presenter = LoadRunWidgetPresenterEA(self.view, self.model)

        self.view.warning_popup = mock.Mock()
        self.model.execute = mock.Mock()

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

        setup_context_for_ea_tests(self)
        self.load_file_view = BrowseFileWidgetView(self.obj)
        self.load_run_view = LoadRunWidgetView(self.obj)
        self.load_run_view.set_current_instrument = mock.Mock()
        self.view = LoadWidgetView(parent=self.obj,
                                   load_file_view=self.load_file_view,
                                   load_run_view=self.load_run_view)
        self.model = LoadWidgetModel(self.loaded_data, self.context)
        self.model.instrument = mock.Mock()
        self.presenter = LoadWidgetPresenterEA(self.view, self.model)
        loaded_data = mock.Mock()
        context = mock.Mock()
        self.run_widget = LoadRunWidgetPresenterEA(
            self.load_run_view, LoadRunWidgetModel(loaded_data, context))
        self.presenter.set_load_run_widget(self.run_widget)
예제 #5
0
 def setUp(self):
     setup_context_for_ea_tests(self)
     self.model = LoadRunWidgetModel(self.loaded_data, self.context)