def setUp(self):
        self._qapp = mock_widget.mockQapp()
        self.obj = QtGui.QWidget()
        ConfigService['default.instrument'] = 'MUSR'
        setup_context_for_tests(self)
        self.gui_context['RebinType'] = 'None'
        self.view = HomeGroupingWidgetView(self.obj)
        self.model = HomeGroupingWidgetModel(self.context)
        self.presenter = HomeGroupingWidgetPresenter(self.view, self.model)

        self.view.warning_popup = mock.MagicMock()
        self.view.instrument_changed_warning = mock.MagicMock(return_value=1)

        file_path = FileFinder.findRuns('MUSR00022725.nxs')[0]
        ws, run, filename = load_utils.load_workspace_from_filename(file_path)
        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.update_current_data()
        test_pair = MuonPair('test_pair', 'top', 'bottom', alpha=0.75)
        self.group_context.add_pair(pair=test_pair)
        self.presenter.update_group_pair_list()
Пример #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.obj = QWidget()
        setup_context_for_tests(self)
        self.gui_context['RebinType'] = 'None'
        self.view = HomeGroupingWidgetView(self.obj)
        self.model = HomeGroupingWidgetModel(self.context)
        self.presenter = HomeGroupingWidgetPresenter(self.view, self.model)

        self.view.warning_popup = mock.MagicMock()
        self.view.instrument_changed_warning = mock.MagicMock(return_value=1)
    def setUp(self):
        self._qapp = mock_widget.mockQapp()
        self.obj = QtGui.QWidget()
        ConfigService['default.instrument'] = 'MUSR'
        setup_context_for_tests(self)
        self.gui_context['RebinType'] = 'None'
        self.view = HomeGroupingWidgetView(self.obj)
        self.model = HomeGroupingWidgetModel(self.context)
        self.presenter = HomeGroupingWidgetPresenter(self.view, self.model)

        self.view.warning_popup = mock.MagicMock()
        self.view.instrument_changed_warning = mock.MagicMock(return_value=1)

        file_path = FileFinder.findRuns('MUSR00022725.nxs')[0]
        ws, run, filename = load_utils.load_workspace_from_filename(file_path)
        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.update_current_data()
        test_pair = MuonPair('test_pair', 'top', 'bottom', alpha=0.75)
        self.group_context.add_pair(pair=test_pair)
        self.presenter.update_group_pair_list()
class HomeTabGroupingPresenterTest(unittest.TestCase):
    def setUp(self):
        self._qapp = mock_widget.mockQapp()
        self.obj = QtGui.QWidget()
        ConfigService['default.instrument'] = 'MUSR'
        setup_context_for_tests(self)
        self.gui_context['RebinType'] = 'None'
        self.view = HomeGroupingWidgetView(self.obj)
        self.model = HomeGroupingWidgetModel(self.context)
        self.presenter = HomeGroupingWidgetPresenter(self.view, self.model)

        self.view.warning_popup = mock.MagicMock()
        self.view.instrument_changed_warning = mock.MagicMock(return_value=1)

        file_path = FileFinder.findRuns('MUSR00022725.nxs')[0]
        ws, run, filename = load_utils.load_workspace_from_filename(file_path)
        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.update_current_data()
        test_pair = MuonPair('test_pair', 'top', 'bottom', alpha=0.75)
        self.group_context.add_pair(pair=test_pair)
        self.presenter.update_group_pair_list()

    def tearDown(self):
        self.obj = None

    def test_group_pair_selector_contains_groups_and_pairs(self):
        self.assertEqual(self.view.grouppair_selector.itemText(0), 'top')
        self.assertEqual(self.view.grouppair_selector.itemText(1), 'bkwd')
        self.assertEqual(self.view.grouppair_selector.itemText(2), 'bottom')
        self.assertEqual(self.view.grouppair_selector.itemText(3), 'fwd')
        self.assertEqual(self.view.grouppair_selector.itemText(4), 'test_pair')

    def test_that_changeing_to_pair_displays_alpha(self):
        self.assertTrue(self.view.alpha_label_2.isHidden())
        self.assertTrue(self.view.alpha_edit.isHidden())

        self.view.grouppair_selector.setCurrentIndex(4)

        self.assertFalse(self.view.alpha_label_2.isHidden())
        self.assertFalse(self.view.alpha_edit.isHidden())
        self.assertEqual(self.view.alpha_edit.text(), '0.75')

    def test_that_changeing_alpha_correctly_updates_model(self):
        self.view.grouppair_selector.setCurrentIndex(4)
        observer = Observer()
        observer.update = mock.MagicMock()
        self.presenter.pairAlphaNotifier.add_subscriber(observer)

        self.view.alpha_edit.setText('0.87')
        self.view.alpha_edit.editingFinished.emit()

        self.assertEqual(self.model.get_alpha('test_pair'), 0.87)
        observer.update.assert_called_once_with(
            self.presenter.pairAlphaNotifier, None)

    def test_period_changes_are_propogated_to_model(self):
        self.model.number_of_periods = mock.MagicMock(return_value=5)

        self.view.summed_period_edit.setText('1, 3, 5')
        self.view.subtracted_period_edit.setText('2, 4')
        self.view.summed_period_edit.editingFinished.emit()

        self.view.warning_popup.assert_not_called()
        self.assertEqual(self.model.get_summed_periods(), [1, 3, 5])
        self.assertEqual(self.model.get_subtracted_periods(), [2, 4])

    def test_invalid_periods_are_removed_and_warning_given(self):
        self.model.number_of_periods = mock.MagicMock(return_value=5)

        self.view.summed_period_edit.setText('1, 3, 5')
        self.view.subtracted_period_edit.setText('2, 4, 6')
        self.view.summed_period_edit.editingFinished.emit()

        self.view.warning_popup.assert_called_once_with(
            'The following periods are invalid : 6')
        self.assertEqual(self.model.get_summed_periods(), [1, 3, 5])
        self.assertEqual(self.model.get_subtracted_periods(), [2, 4])
class HomeTabGroupingPresenterTest(unittest.TestCase):
    def setUp(self):
        self._qapp = mock_widget.mockQapp()
        self.obj = QtGui.QWidget()
        ConfigService['default.instrument'] = 'MUSR'
        setup_context_for_tests(self)
        self.gui_context['RebinType'] = 'None'
        self.view = HomeGroupingWidgetView(self.obj)
        self.model = HomeGroupingWidgetModel(self.context)
        self.presenter = HomeGroupingWidgetPresenter(self.view, self.model)

        self.view.warning_popup = mock.MagicMock()
        self.view.instrument_changed_warning = mock.MagicMock(return_value=1)

        file_path = FileFinder.findRuns('MUSR00022725.nxs')[0]
        ws, run, filename = load_utils.load_workspace_from_filename(file_path)
        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.update_current_data()
        test_pair = MuonPair('test_pair', 'top', 'bottom', alpha=0.75)
        self.group_context.add_pair(pair=test_pair)
        self.presenter.update_group_pair_list()

    def tearDown(self):
        self.obj = None

    def test_group_pair_selector_contains_groups_and_pairs(self):
        self.assertEqual(self.view.grouppair_selector.itemText(0), 'top')
        self.assertEqual(self.view.grouppair_selector.itemText(1), 'bkwd')
        self.assertEqual(self.view.grouppair_selector.itemText(2), 'bottom')
        self.assertEqual(self.view.grouppair_selector.itemText(3), 'fwd')
        self.assertEqual(self.view.grouppair_selector.itemText(4), 'test_pair')

    def test_that_changeing_to_pair_displays_alpha(self):
        self.assertTrue(self.view.alpha_label_2.isHidden())
        self.assertTrue(self.view.alpha_edit.isHidden())

        self.view.grouppair_selector.setCurrentIndex(4)

        self.assertFalse(self.view.alpha_label_2.isHidden())
        self.assertFalse(self.view.alpha_edit.isHidden())
        self.assertEqual(self.view.alpha_edit.text(), '0.75')

    def test_that_changeing_alpha_correctly_updates_model(self):
        self.view.grouppair_selector.setCurrentIndex(4)
        observer = Observer()
        observer.update = mock.MagicMock()
        self.presenter.pairAlphaNotifier.add_subscriber(observer)

        self.view.alpha_edit.setText('0.87')
        self.view.alpha_edit.editingFinished.emit()

        self.assertEqual(self.model.get_alpha('test_pair'), 0.87)
        observer.update.assert_called_once_with(self.presenter.pairAlphaNotifier, None)

    def test_period_changes_are_propogated_to_model(self):
        self.model.number_of_periods = mock.MagicMock(return_value=5)

        self.view.summed_period_edit.setText('1, 3, 5')
        self.view.subtracted_period_edit.setText('2, 4')
        self.view.summed_period_edit.editingFinished.emit()

        self.view.warning_popup.assert_not_called()
        self.assertEqual(self.model.get_summed_periods(), [1,3,5])
        self.assertEqual(self.model.get_subtracted_periods(), [2, 4])

    def test_invalid_periods_are_removed_and_warning_given(self):
        self.model.number_of_periods = mock.MagicMock(return_value=5)

        self.view.summed_period_edit.setText('1, 3, 5')
        self.view.subtracted_period_edit.setText('2, 4, 6')
        self.view.summed_period_edit.editingFinished.emit()

        self.view.warning_popup.assert_called_once_with('The following periods are invalid : 6')
        self.assertEqual(self.model.get_summed_periods(), [1,3,5])
        self.assertEqual(self.model.get_subtracted_periods(), [2, 4])