Пример #1
0
    def setUp(self):
        self.context = mock.MagicMock()
        self.plotting_window_model = mock.MagicMock()
        self.view = mock.MagicMock()
        self.model = mock.MagicMock()
        self.workspace_list = ['MUSR62260; Group; bottom; Asymmetry; MA',
                               'MUSR62261; Group; bottom; Asymmetry; MA']

        self.presenter = HomePlotWidgetPresenter(self.view, self.model, self.context)
        self.presenter.get_plot_title = mock.MagicMock(return_value='MUSR62260-62261 bottom')
Пример #2
0
    def __init__(self, context, parent):
        self.inst_view = InstrumentWidgetView(parent)
        self.grp_view = HomeGroupingWidgetView(parent)
        self.run_info_view = HomeRunInfoWidgetView(parent)
        self.plot_view = HomePlotWidgetView(parent)

        # keep a handle to the presenters of sub-widgets
        self.instrument_widget = InstrumentWidgetPresenter(self.inst_view,
                                                           InstrumentWidgetModel(context=context))
        self.group_widget = HomeGroupingWidgetPresenter(self.grp_view, HomeGroupingWidgetModel(context=context))
        self.run_info_widget = HomeRunInfoWidgetPresenter(self.run_info_view,
                                                          HomeRunInfoWidgetModel(context=context))
        self.plot_widget = HomePlotWidgetPresenter(self.plot_view, HomePlotWidgetModel(), context)
        self.home_tab_view = HomeTabView(parent=parent,
                                         widget_list=[self.inst_view,
                                                      self.grp_view,
                                                      self.plot_view,
                                                      self.run_info_view])
        self.home_tab_model = HomeTabModel(context=context)
        self.home_tab_widget = HomeTabPresenter(self.home_tab_view, self.home_tab_model,
                                                subwidgets=[self.instrument_widget,
                                                            self.group_widget,
                                                            self.plot_widget,
                                                            self.run_info_widget])

        context.update_view_from_model_notifier.add_subscriber(self.home_tab_widget.update_view_from_model_observer)
Пример #3
0
    def __init__(self, context, parent):
        self.inst_view = InstrumentWidgetView(parent)
        self.grp_view = HomeGroupingWidgetView(parent)
        self.plot_view = HomePlotWidgetView(parent)
        self.run_info_view = HomeRunInfoWidgetView(parent)

        # keep a handle to the presenters of sub-widgets
        self.instrument_widget = InstrumentWidgetPresenter(
            self.inst_view, InstrumentWidgetModel(muon_data=context))
        self.group_widget = HomeGroupingWidgetPresenter(
            self.grp_view, HomeGroupingWidgetModel(muon_data=context))
        self.plot_widget = HomePlotWidgetPresenter(self.plot_view,
                                                   HomePlotWidgetModel())
        self.run_info_widget = HomeRunInfoWidgetPresenter(
            self.run_info_view, HomeRunInfoWidgetModel(muon_data=context))

        self.home_tab_view = HomeTabView(parent=parent,
                                         widget_list=[
                                             self.inst_view, self.grp_view,
                                             self.plot_view, self.run_info_view
                                         ])
        self.home_tab_model = HomeTabModel(muon_data=context)
        self.home_tab_widget = HomeTabPresenter(self.home_tab_view,
                                                self.home_tab_model,
                                                subwidgets=[
                                                    self.instrument_widget,
                                                    self.group_widget,
                                                    self.plot_widget,
                                                    self.run_info_widget
                                                ])
Пример #4
0
    def setUp(self):
        self._qapp = mock_widget.mockQapp()
        self.obj = QtGui.QWidget()
        self.view = HomePlotWidgetView(self.obj)
        self.model = HomePlotWidgetModel()
        self.presenter = HomePlotWidgetPresenter(self.view, self.model)

        self.view.warning_popup = mock.MagicMock()
    def setUp(self):
        self.context = setup_context(True)
        self.plotting_window_model = mock.MagicMock()
        self.view = mock.MagicMock()
        self.model = mock.MagicMock()
        self.workspace_list = [
            'MUSR62260; Group; bottom; Asymmetry; FD',
            'MUSR62261; Group; bottom; Asymmetry; FD',
            'FFT; Re MUSR62260; Group; fwd; Asymmetry; FD; Im MUSR62260; Group; fwd; Asymmetry; FD_Im'
            'FFT; Re MUSR62260; Group; fwd; Asymmetry; FD; Im MUSR62260; Group; fwd; Asymmetry; FD_Re'
            'FFT; Re MUSR62260; Group; fwd; Asymmetry; FD; Im MUSR62260; Group; fwd; Asymmetry; FD_mod'
            'MUSR62260_raw_data FD; MaxEnt'
        ]

        self.presenter = HomePlotWidgetPresenter(self.view, self.model,
                                                 self.context)
        self.presenter.get_plot_title = mock.MagicMock(
            return_value='MUSR62260-62261 bottom')
Пример #6
0
class HomeTabPlotPresenterTest(unittest.TestCase):
    def setUp(self):
        self.context = mock.MagicMock()
        self.plotting_window_model = mock.MagicMock()
        self.view = mock.MagicMock()
        self.model = mock.MagicMock()
        self.workspace_list = [
            'MUSR62260; Group; bottom; Asymmetry; MA',
            'MUSR62261; Group; bottom; Asymmetry; MA'
        ]

        self.presenter = HomePlotWidgetPresenter(self.view, self.model,
                                                 self.context)
        self.presenter.get_plot_title = mock.MagicMock(
            return_value='MUSR62260-62261 bottom')

    def test_use_rebin_changed_resets_use_raw_to_true_if_no_rebin_specified(
            self):
        self.view.if_raw.return_value = False
        self.context._do_rebin.return_value = False

        self.presenter.handle_use_raw_workspaces_changed()

        self.model.plot.assert_not_called()
        self.view.warning_popup.assert_called_once_with(
            'No rebin options specified')

    def test_use_rebin_changed_replots_figure_with_appropriate_data(self):
        self.presenter.get_workspaces_to_plot = mock.MagicMock(
            return_value=self.workspace_list)
        self.presenter.get_plot_title = mock.MagicMock(
            return_value='MUSR62260-62261 bottom')

        self.presenter.handle_use_raw_workspaces_changed()

        self.model.plot.assert_called_once_with([
            'MUSR62260; Group; bottom; Asymmetry; MA',
            'MUSR62261; Group; bottom; Asymmetry; MA'
        ], 'MUSR62260-62261 bottom', 'Time', False, mock.ANY)

    def test_handle_data_updated_does_nothing_if_workspace_list_has_not_changed(
            self):
        self.presenter.get_workspaces_to_plot = mock.MagicMock(
            return_value=self.workspace_list)
        self.model.plotted_workspaces = self.workspace_list

        self.presenter.handle_data_updated()

        self.model.plot.assert_not_called()

    def test_plot_called_by_handle_data_updated_if_run_list_changed(self):
        self.presenter.get_workspaces_to_plot = mock.MagicMock(
            return_value=self.workspace_list)
        self.model.plotted_workspaces = []
        self.presenter.get_plot_title = mock.MagicMock(
            return_value='MUSR62260-62261 bottom')

        self.presenter.handle_data_updated()

        self.model.plot.assert_called_once_with(self.workspace_list,
                                                'MUSR62260-62261 bottom',
                                                'Time', False, mock.ANY)

    def test_handle_plot_type_changed_displays_a_warning_if_trying_to_plot_counts_on_a_pair(
            self):
        self.context.group_pair_context.__getitem__.return_value = MuonPair(
            'long', 'bwd', 'fwd')
        self.view.get_selected.return_value = 'Counts'

        self.presenter.handle_plot_type_changed()

        self.model.plot.assert_not_called()
        self.view.warning_popup.assert_called_once_with(
            'Pair workspaces have no counts workspace')

    def test_handle_plot_type_changed_calls_plot(self):
        self.context.group_pair_context.__getitem__.return_value = MuonGroup(
            'bottom', [])
        self.presenter.get_workspaces_to_plot = mock.MagicMock(
            return_value=self.workspace_list)
        self.view.get_selected.return_value = 'Counts'

        self.presenter.handle_plot_type_changed()

        self.model.plot.assert_called_once_with(self.workspace_list,
                                                'MUSR62260-62261 bottom',
                                                'Time', True, mock.ANY)

    def test_handle_group_pair_to_plot_changed_does_nothing_if_group_not_changed(
            self):
        self.model.plotted_group = 'bottom'
        self.context.group_pair_context.selected = 'bottom'

        self.presenter.handle_group_pair_to_plot_changed()

        self.model.plot.assert_not_called()

    def test_handle_group_pair_to_plot_changed_does_nothing_if_plot_window_does_not_exist(
            self):
        self.model.plotted_group = 'top'
        self.context.group_pair_context.selected = 'bottom'
        self.model.plot_figure = None

        self.presenter.handle_group_pair_to_plot_changed()

        self.model.plot.assert_not_called()

    def test_handle_group_pair_to_plot_calls_plot(self):
        self.model.plotted_group = 'top'
        self.context.group_pair_context.selected = 'bottom'
        self.presenter.get_workspaces_to_plot = mock.MagicMock(
            return_value=self.workspace_list)

        self.presenter.handle_group_pair_to_plot_changed()

        self.model.plot.assert_called_once_with(self.workspace_list,
                                                'MUSR62260-62261 bottom',
                                                'Time', False, mock.ANY)

    def test_handle_fit_completed_adds_appropriate_fits_to_plot(self):
        self.model.plotted_workspaces = self.workspace_list
        self.model.plotted_workspaces_inverse_binning = {}
        fit_information = FitInformation(
            mock.MagicMock(), 'GaussOsc',
            ['MUSR62260; Group; bottom; Asymmetry; MA'],
            ['MUSR62260; Group; bottom; Asymmetry; MA; Fitted;'])
        self.context.fitting_context.fit_list.__getitem__.return_value = fit_information
        self.context.fitting_context.number_of_fits = 1

        self.presenter.handle_fit_completed()

        self.assertEqual(self.model.add_workspace_to_plot.call_count, 2)
        self.model.add_workspace_to_plot.assert_any_call(
            'MUSR62260; Group; bottom; Asymmetry; MA; Fitted;', 1,
            'MUSR62260; Group; bottom; Asymmetry; MA; Fitted;: Fit')
        self.model.add_workspace_to_plot.assert_called_with(
            'MUSR62260; Group; bottom; Asymmetry; MA; Fitted;', 2,
            'MUSR62260; Group; bottom; Asymmetry; MA; Fitted;: Diff')
class HomeTabPlotPresenterFreqTest(unittest.TestCase):
    def setUp(self):
        self.context = setup_context(True)
        self.plotting_window_model = mock.MagicMock()
        self.view = mock.MagicMock()
        self.model = mock.MagicMock()
        self.workspace_list = [
            'MUSR62260; Group; bottom; Asymmetry; FD',
            'MUSR62261; Group; bottom; Asymmetry; FD',
            'FFT; Re MUSR62260; Group; fwd; Asymmetry; FD; Im MUSR62260; Group; fwd; Asymmetry; FD_Im'
            'FFT; Re MUSR62260; Group; fwd; Asymmetry; FD; Im MUSR62260; Group; fwd; Asymmetry; FD_Re'
            'FFT; Re MUSR62260; Group; fwd; Asymmetry; FD; Im MUSR62260; Group; fwd; Asymmetry; FD_mod'
            'MUSR62260_raw_data FD; MaxEnt'
        ]

        self.presenter = HomePlotWidgetPresenter(self.view, self.model,
                                                 self.context)
        self.presenter.get_plot_title = mock.MagicMock(
            return_value='MUSR62260-62261 bottom')

    def test_time_plot_in_FDA(self):
        self.presenter.get_workspaces_to_plot = mock.MagicMock(
            return_value=[self.workspace_list[0], self.workspace_list[1]])
        self.presenter.get_plot_title = mock.MagicMock(
            return_value='MUSR62260-62261 bottom')

        self.presenter.handle_use_raw_workspaces_changed()

        self.model.plot.assert_called_once_with([
            'MUSR62260; Group; bottom; Asymmetry; FD',
            'MUSR62261; Group; bottom; Asymmetry; FD'
        ], 'MUSR62260-62261 bottom', 'Time', False,
                                                "Frequency Domain Analysis")

    def test_plot_type_changed(self):
        self.view.get_selected.return_value = "Asymmetry"
        self.assertEquals(self.view.get_selected(), "Asymmetry")

        self.view.get_selected.return_value = "Frequency Re"
        self.presenter.handle_plot_type_changed()
        self.assertEquals(self.context._frequency_context.plot_type, "Re")

    def test_plot_type_changed_to_time(self):
        self.view.get_selected.return_value = "Frequency Re"

        self.view.get_selected.return_value = "Asymmetry"
        self.presenter.handle_plot_type_changed()
        self.assertEquals(self.context._frequency_context.plot_type, "")

    def test_get_workspace_to_plot(self):
        self.view.get_selected.return_value = "Frequency Re"
        self.presenter.get_freq_workspaces_to_plot = mock.Mock()

        self.presenter.get_workspaces_to_plot("fwd", True,
                                              self.view.get_selected())
        self.assertEquals(
            self.presenter.get_freq_workspaces_to_plot.call_count, 1)

    def test_get_workspaces_to_plot_freq(self):
        self.view.get_selected.return_value = "Frequency Re"
        self.context.data_context.current_runs = [[62260]]
        self.context.get_names_of_frequency_domain_workspaces_to_fit = mock.Mock(
        )
        self.presenter.get_freq_workspaces_to_plot("fwd",
                                                   self.view.get_selected())

        self.assertEquals(
            self.context.get_names_of_frequency_domain_workspaces_to_fit.
            call_count, 1)
        self.context.get_names_of_frequency_domain_workspaces_to_fit.assert_called_once_with(
            "62260", "fwd", True, "Re")

    def test_get_2_workspaces_to_plot_freq(self):
        self.view.get_selected.return_value = "Frequency Re"
        self.context.data_context.current_runs = [[62260], [62261]]
        self.context.get_names_of_frequency_domain_workspaces_to_fit = mock.Mock(
        )
        self.presenter.get_freq_workspaces_to_plot("fwd",
                                                   self.view.get_selected())

        self.assertEquals(
            self.context.get_names_of_frequency_domain_workspaces_to_fit.
            call_count, 1)
        self.context.get_names_of_frequency_domain_workspaces_to_fit.assert_called_once_with(
            "62260, 62261", "fwd", True, "Re")

    def test_get_domain_freq(self):
        self.view.get_selected.return_value = "Frequency Re"
        self.assertEquals(self.presenter.get_domain(), "Frequency")

    def test_get_domain_time(self):
        self.view.get_selected.return_value = "Asymmetry"
        self.assertEquals(self.presenter.get_domain(), "Time")