def test_that_the_view_has_been_initialized_with_the_raw_data_option_shown( self): self.view = FitFunctionOptionsView() self.view.show() self.assertTrue( not self.view.fit_options_table.isRowHidden(RAW_DATA_TABLE_ROW))
def __init__(self, parent: QWidget = None): """Initialize the BasicFittingView and create the FitControlsView and a FitFunctionOptionsView.""" super(BasicFittingView, self).__init__(parent) self.setupUi(self) self.fit_controls = FitControlsView(self) self.workspace_selector = CyclicDataSelectorView(self) self.fit_function_options = FitFunctionOptionsView(self) self.fit_controls_layout.addWidget(self.fit_controls) self.workspace_selector_layout.addWidget(self.workspace_selector) self.fit_function_options_layout.addWidget(self.fit_function_options) self.disable_tab_observer = GenericObserver(self.disable_view) self.enable_tab_observer = GenericObserver(self.enable_view) self.disable_view()
def setUp(self): self.view = FitFunctionOptionsView() self.view.show()
class FitFunctionOptionsViewTest(unittest.TestCase): @classmethod def setUpClass(cls): FrameworkManager.Instance() def setUp(self): self.view = FitFunctionOptionsView() self.view.show() def tearDown(self): self.assertTrue(self.view.close()) def test_that_the_view_has_been_initialized_with_the_raw_data_option_shown( self): self.view = FitFunctionOptionsView() self.view.show() self.assertTrue( not self.view.fit_options_table.isRowHidden(RAW_DATA_TABLE_ROW)) def test_that_the_view_has_been_initialized_with_the_raw_data_option_hidden( self): self.view = FitFunctionOptionsView() self.view.hide_fit_raw_checkbox() self.view.show() self.assertTrue( self.view.fit_options_table.isRowHidden(RAW_DATA_TABLE_ROW)) def test_that_update_fit_status_labels_will_display_no_fit_if_the_success_list_is_empty( self): fit_status, chi_squared = "success", 1.1 self.view.update_fit_status_labels(fit_status, chi_squared) self.assertEqual(self.view.fit_status_success_failure.text(), "Success") self.assertEqual(self.view.fit_status_chi_squared.text(), "Chi squared: 1.1") def test_that_update_fit_status_labels_will_display_fit_successful_if_all_fits_are_successful( self): fit_status, chi_squared = None, 0.0 self.view.update_fit_status_labels(fit_status, chi_squared) self.assertEqual(self.view.fit_status_success_failure.text(), "No Fit") self.assertEqual(self.view.fit_status_chi_squared.text(), "Chi squared: 0") def test_that_update_fit_status_labels_will_display_fits_failed_if_some_of_the_fits_fail( self): fit_status, chi_squared = "failed for some reason", 2.2 self.view.update_fit_status_labels(fit_status, chi_squared) self.assertEqual(self.view.fit_status_success_failure.text(), f"Failure: {fit_status}") self.assertEqual(self.view.fit_status_chi_squared.text(), "Chi squared: 2.2") def test_that_clear_fit_status_will_clear_the_fit_status_and_chi_squared( self): fit_status, chi_squared = "failed for some reason", 2.2 self.view.update_fit_status_labels(fit_status, chi_squared) self.view.clear_fit_status() self.assertEqual(self.view.fit_status_success_failure.text(), "No Fit") self.assertEqual(self.view.fit_status_chi_squared.text(), "Chi squared: 0.0") def test_that_set_datasets_in_function_browser_will_set_the_datasets_in_the_function_browser( self): dataset_names = ["Name1", "Name2", "Name3"] self.view.set_datasets_in_function_browser(dataset_names) self.assertEqual(self.view.number_of_datasets(), 3) def test_that_set_current_dataset_index_will_set_the_current_dataset_index_in_the_function_browser( self): dataset_names = ["Name1", "Name2", "Name3"] self.view.set_datasets_in_function_browser(dataset_names) self.view.set_current_dataset_index(2) self.assertEqual(self.view.function_browser.getCurrentDataset(), 2) def test_that_update_function_browser_parameters_will_update_the_parameters_of_the_function_for_single_fit( self): old_function = "name=FlatBackground,A0=0" simultaneous_mode = False self.view.function_browser.setFunction(old_function) self.assertEqual(str(self.view.fit_object), old_function) updated_function = self.view.fit_object.setParameter("A0", 1.0) self.view.update_function_browser_parameters(simultaneous_mode, updated_function) self.assertEqual(str(self.view.fit_object), str(updated_function)) def test_that_update_function_browser_parameters_will_set_the_function_if_in_simultaneous_mode( self): old_function = "name=FlatBackground,A0=0" simultaneous_mode = True self.view.function_browser.setFunction(old_function) self.assertEqual(str(self.view.fit_object), old_function) updated_function = self.view.fit_object.setParameter("A0", 1.0) self.view.update_function_browser_parameters(simultaneous_mode, updated_function) self.assertEqual(str(self.view.fit_object), str(updated_function)) def test_that_update_function_browser_parameters_will_clear_the_function_if_the_function_provided_is_none( self): old_function = "name=FlatBackground,A0=0" simultaneous_mode = False self.view.function_browser.setFunction(old_function) self.assertEqual(str(self.view.fit_object), old_function) self.view.update_function_browser_parameters(simultaneous_mode, None) self.assertEqual(self.view.fit_object, None) def test_that_set_fit_function_will_set_the_function_in_the_browser(self): fit_function = FunctionFactory.createFunction("FlatBackground") self.view.set_fit_function(fit_function) self.assertEqual(str(self.view.current_fit_function()), str(fit_function)) def test_that_it_is_possible_to_set_the_start_x_to_a_different_value(self): new_value = 5.0 self.view.start_x = new_value self.assertEqual(self.view.start_x, new_value) def test_that_it_is_possible_to_set_the_end_x_to_a_different_value(self): new_value = 5.0 self.view.end_x = new_value self.assertEqual(self.view.end_x, new_value) def test_that_the_fit_to_raw_checkbox_value_can_be_changed_as_expected( self): self.view.fit_to_raw = False self.assertTrue(not self.view.fit_to_raw) self.view.fit_to_raw = True self.assertTrue(self.view.fit_to_raw) def test_that_the_function_name_can_be_changed_as_expected(self): new_function_name = "Test Function Name" self.view.function_name = new_function_name self.assertEqual(self.view.function_name, new_function_name) def test_that_set_covariance_button_enabled_can_disable_the_covariance_button( self): self.assertTrue(self.view.covariance_matrix_button.isEnabled()) self.view.set_covariance_button_enabled(False) self.assertTrue(not self.view.covariance_matrix_button.isEnabled()) def test_that_set_covariance_button_enabled_can_enable_the_covariance_button( self): self.view.set_covariance_button_enabled(False) self.view.set_covariance_button_enabled(True) self.assertTrue(self.view.covariance_matrix_button.isEnabled()) def test_that_show_normalised_covariance_matrix_will_not_raise_an_error( self): ws = CreateEmptyTableWorkspace() wrapper = StaticWorkspaceWrapper("CovarianceMatrix", ws) self.view.show_normalised_covariance_matrix(wrapper.workspace, wrapper.workspace_name)
class BasicFittingView(ui_form, base_widget): """ The BasicFittingView has a FitControlsView and a FitFunctionOptionsView. It can be used for Single Fitting. """ def __init__(self, parent: QWidget = None): """Initialize the BasicFittingView and create the FitControlsView and a FitFunctionOptionsView.""" super(BasicFittingView, self).__init__(parent) self.setupUi(self) self.fit_controls = FitControlsView(self) self.workspace_selector = CyclicDataSelectorView(self) self.fit_function_options = FitFunctionOptionsView(self) self.fit_controls_layout.addWidget(self.fit_controls) self.workspace_selector_layout.addWidget(self.workspace_selector) self.fit_function_options_layout.addWidget(self.fit_function_options) self.disable_tab_observer = GenericObserver(self.disable_view) self.enable_tab_observer = GenericObserver(self.enable_view) self.disable_view() def set_slot_for_fit_generator_clicked(self, slot) -> None: """Connect the slot for the Fit Generator button.""" self.fit_controls.set_slot_for_fit_generator_clicked(slot) def set_slot_for_fit_button_clicked(self, slot) -> None: """Connect the slot for the Fit button.""" self.fit_controls.set_slot_for_fit_button_clicked(slot) def set_slot_for_undo_fit_clicked(self, slot) -> None: """Connect the slot for the Undo Fit button.""" self.fit_controls.set_slot_for_undo_fit_clicked(slot) def set_slot_for_plot_guess_changed(self, slot) -> None: """Connect the slot for the Plot Guess checkbox.""" self.fit_controls.set_slot_for_plot_guess_changed(slot) def set_slot_for_dataset_changed(self, slot) -> None: """Connect the slot for the display workspace combo box being changed.""" self.workspace_selector.set_slot_for_dataset_changed(slot) def set_slot_for_covariance_matrix_clicked(self, slot) -> None: """Connect the slot for the Covariance Matrix button being clicked.""" self.fit_function_options.set_slot_for_covariance_matrix_clicked(slot) def set_slot_for_fit_name_changed(self, slot) -> None: """Connect the slot for the fit name being changed by the user.""" self.fit_function_options.set_slot_for_fit_name_changed(slot) def set_slot_for_function_structure_changed(self, slot) -> None: """Connect the slot for the function structure changing.""" self.fit_function_options.set_slot_for_function_structure_changed(slot) def set_slot_for_function_parameter_changed(self, slot) -> None: """Connect the slot for a function parameter changing.""" self.fit_function_options.set_slot_for_function_parameter_changed(slot) def set_slot_for_function_attribute_changed(self, slot) -> None: """Connect the slot for a function attribute changing.""" self.fit_function_options.set_slot_for_function_attribute_changed(slot) def set_slot_for_start_x_updated(self, slot) -> None: """Connect the slot for the start x option.""" self.fit_function_options.set_slot_for_start_x_updated(slot) def set_slot_for_end_x_updated(self, slot) -> None: """Connect the slot for the end x option.""" self.fit_function_options.set_slot_for_end_x_updated(slot) def set_slot_for_exclude_range_state_changed(self, slot) -> None: """Connect the slot for the exclude range checkbox.""" self.fit_function_options.set_slot_for_exclude_range_state_changed( slot) def set_slot_for_exclude_start_x_updated(self, slot) -> None: """Connect the slot for the exclude start x option.""" self.fit_function_options.set_slot_for_exclude_start_x_updated(slot) def set_slot_for_exclude_end_x_updated(self, slot) -> None: """Connect the slot for the exclude end x option.""" self.fit_function_options.set_slot_for_exclude_end_x_updated(slot) def set_slot_for_minimizer_changed(self, slot) -> None: """Connect the slot for changing the Minimizer.""" self.fit_function_options.set_slot_for_minimizer_changed(slot) def set_slot_for_evaluation_type_changed(self, slot) -> None: """Connect the slot for changing the Evaluation type.""" self.fit_function_options.set_slot_for_evaluation_type_changed(slot) def set_slot_for_use_raw_changed(self, slot) -> None: """Connect the slot for the Use raw option.""" self.fit_function_options.set_slot_for_use_raw_changed(slot) def set_workspace_combo_box_label(self, text: str) -> None: """Sets the label text next to the workspace selector combobox.""" self.workspace_selector.set_data_combo_box_label(text) def set_datasets_in_function_browser(self, dataset_names: list) -> None: """Sets the datasets stored in the FunctionBrowser.""" self.fit_function_options.set_datasets_in_function_browser( dataset_names) def set_current_dataset_index(self, dataset_index: int) -> None: """Sets the index of the current dataset.""" if dataset_index is not None: self.fit_function_options.set_current_dataset_index(dataset_index) def set_number_of_undos(self, number_of_undos: int) -> None: """Sets the allowed number of 'Undo Fit' events.""" self.fit_controls.set_number_of_undos(number_of_undos) def update_dataset_name_combo_box(self, dataset_names: list, emit_signal: bool = True) -> None: """Update the data in the parameter display combo box.""" self.workspace_selector.update_dataset_name_combo_box( dataset_names, emit_signal) def update_local_fit_status_and_chi_squared(self, fit_status: str, chi_squared: float) -> None: """Updates the view to show the status and results from a fit.""" if fit_status is not None: self.fit_function_options.update_fit_status_labels( fit_status, chi_squared) else: self.fit_function_options.clear_fit_status() def update_global_fit_status(self, fit_statuses: list, _: int = None) -> None: """Updates the global fit status label.""" self.fit_controls.update_global_fit_status_label( [status == "success" for status in fit_statuses if status]) def update_fit_function(self, fit_function: IFunction) -> None: """Updates the parameters of a fit function shown in the view.""" self.fit_function_options.update_function_browser_parameters( False, fit_function) @property def current_dataset_name(self) -> str: """Returns the selected dataset name.""" return self.workspace_selector.current_dataset_name @current_dataset_name.setter def current_dataset_name(self, dataset_name: str) -> None: """Sets the currently selected dataset name.""" self.workspace_selector.current_dataset_name = dataset_name def number_of_datasets(self) -> int: """Returns the number of dataset names loaded into the widget.""" return self.workspace_selector.number_of_datasets() @property def current_dataset_index(self) -> int: """Returns the index of the currently displayed dataset.""" return self.workspace_selector.current_dataset_index @property def fit_object(self) -> IFunction: """Returns the global fitting function.""" return self.fit_function_options.fit_object def current_fit_function(self) -> IFunction: """Returns the current fitting function in the view.""" return self.fit_function_options.current_fit_function() @property def minimizer(self) -> str: """Returns the selected minimizer.""" return self.fit_function_options.minimizer @property def start_x(self) -> float: """Returns the selected start X.""" return self.fit_function_options.start_x @start_x.setter def start_x(self, value: float) -> None: """Sets the selected start X.""" self.fit_function_options.start_x = value @property def end_x(self) -> float: """Returns the selected end X.""" return self.fit_function_options.end_x @end_x.setter def end_x(self, value: float) -> None: """Sets the selected end X.""" self.fit_function_options.end_x = value @property def exclude_range(self) -> bool: """Returns true if the Exclude Range option is ticked.""" return self.fit_function_options.exclude_range @property def exclude_start_x(self) -> float: """Returns the start X for the excluded region.""" return self.fit_function_options.exclude_start_x @exclude_start_x.setter def exclude_start_x(self, value: float) -> None: """Sets the selected exclude start X.""" self.fit_function_options.exclude_start_x = value @property def exclude_end_x(self) -> float: """Returns the end X for the excluded region.""" return self.fit_function_options.exclude_end_x @exclude_end_x.setter def exclude_end_x(self, value: float) -> None: """Sets the selected exclude end X.""" self.fit_function_options.exclude_end_x = value @property def evaluation_type(self) -> str: """Returns the selected evaluation type.""" return self.fit_function_options.evaluation_type @property def fit_to_raw(self) -> bool: """Returns whether or not fitting to raw data is ticked.""" return self.fit_function_options.fit_to_raw @fit_to_raw.setter def fit_to_raw(self, check: bool) -> None: """Sets whether or not you are fitting to raw data.""" self.fit_function_options.fit_to_raw = check @property def plot_guess(self) -> bool: """Returns true if plot guess is ticked.""" return self.fit_controls.plot_guess @plot_guess.setter def plot_guess(self, check: bool) -> None: """Sets whether or not plot guess is ticked.""" self.fit_controls.plot_guess = check @property def function_name(self) -> str: """Returns the function name being used.""" return self.fit_function_options.function_name @function_name.setter def function_name(self, function_name: str) -> None: """Sets the function name being used.""" self.fit_function_options.function_name = function_name def warning_popup(self, message: str) -> None: """Displays a warning message.""" warning(message, parent=self) @property def global_parameters(self) -> list: """Returns a list of global parameters.""" return self.fit_function_options.global_parameters def parameter_value(self, full_parameter: str) -> float: """Returns the value of the specified parameter.""" return self.fit_function_options.parameter_value(full_parameter) def attribute_value(self, full_attribute: str): """Returns the value of the specified attribute.""" return self.fit_function_options.attribute_value(full_attribute) def switch_to_simultaneous(self) -> None: """Switches the view to simultaneous fit mode.""" self.fit_function_options.switch_to_simultaneous() def switch_to_single(self) -> None: """Switches the view to single fit mode.""" self.fit_function_options.switch_to_single() def hide_exclude_range_checkbox(self) -> None: """Hides the Exclude Range checkbox in the fitting options.""" self.fit_function_options.hide_exclude_range_checkbox() def hide_fit_raw_checkbox(self) -> None: """Hides the Fit Raw checkbox in the fitting options.""" self.fit_function_options.hide_fit_raw_checkbox() def hide_evaluate_function_as_checkbox(self) -> None: """Hides the Evaluate Function as checkbox in the fitting options.""" self.fit_function_options.hide_evaluate_function_as_checkbox() def set_start_and_end_x_labels(self, start_x_label: str, end_x_label: str) -> None: """Sets the labels to use for the start and end X labels in the fit options table.""" self.fit_function_options.set_start_and_end_x_labels( start_x_label, end_x_label) def set_exclude_start_and_end_x_visible(self, visible: bool) -> None: """Sets whether the exclude start and end x options are visible.""" self.fit_function_options.set_exclude_start_and_end_x_visible(visible) def set_covariance_button_enabled(self, enabled: bool) -> None: """Sets whether the Covariance Matrix button is enabled or not.""" self.fit_function_options.set_covariance_button_enabled(enabled) def show_normalised_covariance_matrix(self, covariance_ws: ITableWorkspace, workspace_name: str) -> None: """Shows the normalised covariance matrix in a separate table display window.""" self.fit_function_options.show_normalised_covariance_matrix( covariance_ws, workspace_name) def disable_view(self) -> None: """Disable all widgets in this fitting widget.""" self.setEnabled(False) def enable_view(self) -> None: """Enable all widgets in this fitting widget.""" self.setEnabled(self.workspace_selector.number_of_datasets() != 0)
def setUp(self): self.view = FitFunctionOptionsView() self.view.show() self.assert_widget_created()