Пример #1
0
    def test_that_subscribers_notified_when_instrument_changed(self):
        observer = Observer()
        observer.update = mock.MagicMock()
        self.data_context.instrumentNotifier.add_subscriber(observer)

        self.view.set_instrument('MUSR', block=True)
        self.view.set_instrument('CHRONUS')

        observer.update.assert_called_once_with(self.data_context.instrumentNotifier, 'CHRONUS')
Пример #2
0
    def test_that_signal_is_not_sent_if_item_updated_to_same_value(self):
        context = MuonGuiContext()
        observer = Observer()
        observer.update = mock.MagicMock()
        context.add_subscriber(observer)
        context.update({'FirstGoodData': 12.0})

        context.update_and_send_signal(FirstGoodData=12.0)

        observer.update.assert_not_called()
Пример #3
0
    def test_that_signal_is_sent_when_item_updates(self):
        context = MuonGuiContext()
        observer = Observer()
        observer.update = mock.MagicMock()

        context.add_subscriber(observer)

        context.update_and_send_signal(FirstGoodData=12.0)

        observer.update.assert_called_once_with(context.gui_variables_notifier, {'FirstGoodData': 12.0})
Пример #4
0
    def test_add_subscribers(self):
        # Make some fake observers
        observer_1 = Observer()
        observer_2 = Observer()
        self.presenter.add_subscribers([observer_1, observer_2])

        self.assertEqual([observer_1, observer_2], self.presenter.group_widget.
                         selected_diff_changed_notifier._subscribers)
        self.assertEqual([observer_1, observer_2], self.presenter.pair_widget.
                         selected_diff_changed_notifier._subscribers)
Пример #5
0
    def test_that_changeing_alpha_correctly_updates_model(self):
        perform_musr_file_finder(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)
Пример #6
0
    def setUp(self):
        self.obj = QWidget()
        setup_context_for_tests(self)
        self.gui_variable_observer = Observer()

        self.gui_context.gui_variables_notifier.add_subscriber(self.gui_variable_observer)
        self.data_context.instrument = 'MUSR'
        self.view = InstrumentWidgetView(self.obj)
        self.view.set_instrument('MUSR', block=True)
        self.model = InstrumentWidgetModel(self.context)
        self.presenter = InstrumentWidgetPresenter(self.view, self.model)

        self.view.warning_popup = mock.MagicMock()
        self.view.instrument_changed_warning = mock.MagicMock(return_value=1)
        self.gui_variable_observer.update = mock.MagicMock()
Пример #7
0
    def setUp(self):
        # Store an empty widget to parent all the views, and ensure they are deleted correctly
        self.obj = QWidget()

        setup_context_for_tests(self)

        self.gui_variable_observer = Observer()

        self.gui_context.gui_variables_notifier.add_subscriber(self.gui_variable_observer)
        self.model = GroupingTabModel(context=self.context)
        self.view = GroupingTableView(parent=self.obj)
        self.presenter = GroupingTablePresenter(self.view, self.model)

        self.view.enter_group_name = mock.Mock(side_effect=group_name())
        self.view.warning_popup = mock.Mock()
        self.gui_variable_observer.update = mock.MagicMock()
Пример #8
0
    def setUp(self):
        # Store an empty widget to parent all the views, and ensure they are deleted correctly
        self.obj = QWidget()

        setup_context_for_tests(self)

        self.gui_variable_observer = Observer()

        self.gui_context.gui_variables_notifier.add_subscriber(self.gui_variable_observer)
        self.model = GroupingTabModel(context=self.context)
        self.presenter = DifferencePresenter(self.model)

        # Mock user input for getting diff name
        self.presenter.group_view.enter_diff_name = mock.Mock(side_effect=enter_diff_name_side_effect())
        self.presenter.pair_view.enter_diff_name = mock.Mock(side_effect=enter_diff_name_side_effect())

        # Mock warning methods
        self.presenter.group_view.warning_popup = mock.Mock()
        self.presenter.pair_view.warning_popup = mock.Mock()
Пример #9
0
 def __init__(self, outer):
     Observer.__init__(self)
     self.outer = outer
Пример #10
0
 def __init__(self, callback):
     Observer.__init__(self)
     self.callback = callback