Example #1
0
    def test_adding_new_fit_updates_log_values(self):
        existing_selection = {
            'run_number': [0, False, True],
            'run_start': [1, True, True]
        }
        self.mock_view.log_values.return_value = existing_selection
        final_selection = {
            'run_number': [0, False, True],
            'run_start': [1, True, True],
            'magnetic_field': [2, True, True]
        }
        self.mock_model.log_selection.return_value = final_selection

        presenter = ResultsTabPresenter(self.mock_view, self.mock_model)
        presenter._get_workspace_list = mock.MagicMock(return_value=(['ws1', 'ws3'], "func1"))
        # previous test verifies this is correct on construction
        self.mock_view.set_output_results_button_enabled.reset_mock()
        presenter.on_new_fit_performed()

        self.mock_view.log_values.assert_called_once_with()
        self.mock_model.log_selection.assert_called_once_with(
            existing_selection=existing_selection)
        final_selection = {
            'run_number': [0, False, True],
            'run_start': [1, True, True],
            'magnetic_field': [2, True, True]
        }
        self.mock_view.set_log_values.assert_called_once_with(final_selection)
Example #2
0
    def test_adding_new_fit_to_existing_fits_preserves_current_selections(
            self):
        orig_ws_list_state = ['ws1', 'ws3']
        final_ws_list_state = ['ws1', 'ws3']
        test_functions = ['func1', 'func2']
        self.mock_model.fit_functions.return_value = test_functions
        self.mock_model.fit_selection.return_value = final_ws_list_state
        self.mock_view.fit_result_workspaces.return_value = orig_ws_list_state

        presenter = ResultsTabPresenter(self.mock_view, self.mock_model)
        presenter._get_workspace_list = mock.MagicMock(
            return_value=(['ws1', 'ws3'], "func1"))
        # previous test verifies this is correct on construction
        self.mock_view.set_output_results_button_enabled.reset_mock()
        presenter.on_new_fit_performed()

        self.mock_model.fit_functions.assert_called_once_with()
        self.mock_model.fit_selection.assert_called_once_with(
            orig_ws_list_state)
        self.mock_view.set_fit_function_names.assert_called_once_with(
            test_functions)
        self.mock_view.set_fit_result_workspaces.assert_called_once_with(
            final_ws_list_state)
        self.mock_view.set_output_results_button_enabled.assert_called_once_with(
            True)
    def test_if_no_fits_in_context_then_output_results_is_disabled(self):
        self.mock_model._fit_context.clear()
        presenter = ResultsTabPresenter(self.mock_view, self.mock_model)
        presenter.on_new_fit_performed()
        expected_calls = [mock.call(False), mock.call(True)]  # Called once in init of view and once on new fit

        self.mock_view.set_output_results_button_enabled.assert_has_calls(expected_calls)
    def test_adding_new_fit_to_existing_fits_preserves_current_selections(
            self):
        orig_ws_list_state = {
            name: [index, checked, True]
            for index, (name, checked) in enumerate((('ws1', True), ('ws2',
                                                                     False)))
        }
        final_ws_list_state = {
            name: [index, checked, True]
            for index, (name, checked) in enumerate((('ws1', True),
                                                     ('ws2', False), ('ws3',
                                                                      True)))
        }
        test_functions = ['func1', 'func2']
        self.mock_model.fit_functions.return_value = test_functions
        self.mock_model.fit_selection.return_value = final_ws_list_state
        self.mock_view.fit_result_workspaces.return_value = orig_ws_list_state

        presenter = ResultsTabPresenter(self.mock_view, self.mock_model)
        # previous test verifies this is correct on construction
        self.mock_view.set_output_results_button_enabled.reset_mock()
        presenter.on_new_fit_performed()

        self.mock_model.fit_functions.assert_called_once_with()
        self.mock_model.fit_selection.assert_called_once_with(
            existing_selection=orig_ws_list_state)
        self.mock_view.set_fit_function_names.assert_called_once_with(
            test_functions)
        self.mock_view.fit_result_workspaces.assert_called_once_with()
        self.mock_view.set_fit_result_workspaces.assert_called_once_with(
            final_ws_list_state)
        self.mock_view.set_output_results_button_enabled.assert_called_once_with(
            True)