Example #1
0
    def test_get_layout_dict(self, mock_CONF):
        presenter = GeneralSettings(None, view=Mock())
        # setup CONF.get returns dictionary
        test_dict = {'a': 1}
        mock_CONF.get.return_value = test_dict

        self.assertEqual(test_dict, presenter.get_layout_dict())
Example #2
0
    def test_action_total_number_checkpoints(self, mock_ConfigService):
        presenter = GeneralSettings(None)
        # reset any effects from the constructor
        mock_ConfigService.setString.reset_mock()

        num_checkpoints = "532532"
        presenter.action_total_number_checkpoints(num_checkpoints)
        mock_ConfigService.setString.assert_called_once_with(GeneralSettings.PR_NUMBER_OF_CHECKPOINTS, num_checkpoints)
    def test_action_instrument_changed(self, mock_ConfigService):
        presenter = GeneralSettings(None)
        # reset any effects from the constructor
        mock_ConfigService.setString.reset_mock()

        new_instr = "apples"
        presenter.action_instrument_changed(new_instr)
        mock_ConfigService.setString.assert_called_once_with(GeneralSettings.INSTRUMENT, new_instr)
Example #4
0
    def test_action_instrument_changed(self, mock_ConfigService):
        presenter = GeneralSettings(None)
        # reset any effects from the constructor
        mock_ConfigService.setString.reset_mock()

        new_instr = "apples"
        presenter.action_instrument_changed(new_instr)
        mock_ConfigService.setString.assert_called_once_with(GeneralProperties.INSTRUMENT.value, new_instr)
    def test_action_total_number_checkpoints(self, mock_ConfigService):
        presenter = GeneralSettings(None)
        # reset any effects from the constructor
        mock_ConfigService.setString.reset_mock()

        num_checkpoints = "532532"
        presenter.action_total_number_checkpoints(num_checkpoints)
        mock_ConfigService.setString.assert_called_once_with(GeneralSettings.PR_NUMBER_OF_CHECKPOINTS, num_checkpoints)
    def test_action_time_between_recovery(self, mock_ConfigService):
        presenter = GeneralSettings(None)
        # reset any effects from the constructor
        mock_ConfigService.setString.reset_mock()

        time = "6000"
        presenter.action_time_between_recovery(time)
        mock_ConfigService.setString.assert_called_once_with(GeneralSettings.PR_TIME_BETWEEN_RECOVERY, time)
Example #7
0
    def test_action_time_between_recovery(self, mock_ConfigService):
        presenter = GeneralSettings(None)
        # reset any effects from the constructor
        mock_ConfigService.setString.reset_mock()

        time = "6000"
        presenter.action_time_between_recovery(time)
        mock_ConfigService.setString.assert_called_once_with(GeneralProperties.PR_TIME_BETWEEN_RECOVERY.value, time)
Example #8
0
 def test_action_font_selected(self, mock_conf):
     presenter = GeneralSettings(None)
     # reset any effects from the constructor
     mock_conf.set.reset_mock()
     mock_font = Mock()
     mock_font.toString.return_value = "Serif"
     presenter.action_font_selected(mock_font)
     mock_conf.set.assert_called_once_with(GeneralProperties.FONT.value, "Serif")
Example #9
0
    def test_action_facility_changed(self, mock_ConfigService):
        presenter = GeneralSettings(None)
        mock_ConfigService.setFacility.reset_mock()

        new_facility = "TEST_LIVE"
        presenter.action_facility_changed(new_facility)

        mock_ConfigService.setFacility.assert_called_once_with(new_facility)

        self.assertEqual(1, presenter.view.instrument.count())
    def test_action_facility_changed(self, mock_ConfigService):
        presenter = GeneralSettings(None)
        mock_ConfigService.setFacility.reset_mock()

        new_facility = "WWW"
        presenter.action_facility_changed(new_facility)

        mock_ConfigService.setFacility.assert_called_once_with(new_facility)

        self.assertEqual(2, presenter.view.instrument.count())
    def test_action_prompt_save_editor_modified(self, mock_CONF):
        presenter = GeneralSettings(None)

        presenter.action_prompt_save_editor_modified(True)

        mock_CONF.set.assert_called_once_with(GeneralSettings.PROMPT_SAVE_EDITOR_MODIFIED, True)
        mock_CONF.set.reset_mock()

        presenter.action_prompt_save_editor_modified(False)

        mock_CONF.set.assert_called_once_with(GeneralSettings.PROMPT_SAVE_EDITOR_MODIFIED, False)
    def test_action_prompt_save_on_close(self, mock_conf):
        presenter = GeneralSettings(None)

        presenter.action_prompt_save_on_close(True)

        mock_conf.set.assert_called_once_with(GeneralSettings.PROMPT_SAVE_ON_CLOSE, True)
        mock_conf.set.reset_mock()

        presenter.action_prompt_save_on_close(False)

        mock_conf.set.assert_called_once_with(GeneralSettings.PROMPT_SAVE_ON_CLOSE, False)
Example #13
0
    def test_fill_layout_display(self, mock_CONF):
        presenter = GeneralSettings(None, view=Mock())
        # setup CONF.get returns dictionary
        test_dict = {'a': 1, 'b': 2, 'c': 3}
        mock_CONF.get.return_value = test_dict
        # setup mock commands
        presenter.view.layout_display.addItem = Mock()

        presenter.fill_layout_display()

        calls = [call('a'), call('b'), call('c')]
        presenter.view.layout_display.addItem.assert_has_calls(calls)
    def test_action_project_recovery_enabled(self, mock_ConfigService):
        presenter = GeneralSettings(None)
        # reset any effects from the constructor
        mock_ConfigService.setString.reset_mock()

        presenter.action_project_recovery_enabled(True)
        mock_ConfigService.setString.assert_called_once_with(GeneralSettings.PR_RECOVERY_ENABLED, "True")

        mock_ConfigService.setString.reset_mock()

        presenter.action_project_recovery_enabled(False)
        mock_ConfigService.setString.assert_called_once_with(GeneralSettings.PR_RECOVERY_ENABLED, "False")
    def test_action_show_invisible_workspaces(self, mock_ConfigService):
        presenter = GeneralSettings(None)
        # reset any effects from the constructor
        mock_ConfigService.setString.reset_mock()

        presenter.action_show_invisible_workspaces(True)
        mock_ConfigService.setString.assert_called_once_with(GeneralSettings.SHOW_INVISIBLE_WORKSPACES, "True")

        mock_ConfigService.setString.reset_mock()

        presenter.action_show_invisible_workspaces(False)
        mock_ConfigService.setString.assert_called_once_with(GeneralSettings.SHOW_INVISIBLE_WORKSPACES, "False")
Example #16
0
    def test_load_current_setting_values(self, mock_ConfigService, mock_CONF):
        # load current setting is called automatically in the constructor
        GeneralSettings(None)

        # calls().__bool__() are the calls to bool() on the retrieved value from ConfigService.getString
        # In python 3 it __bool__ is called otherwise __nonzero__ is used
        if sys.version_info < (3, ):
            mock_CONF.get.assert_has_calls([
                call(GeneralSettings.PROMPT_SAVE_ON_CLOSE),
                call().__nonzero__(),
                call(GeneralSettings.PROMPT_SAVE_EDITOR_MODIFIED),
                call().__nonzero__()
            ])
        else:
            mock_CONF.get.assert_has_calls([
                call(GeneralSettings.PROMPT_SAVE_ON_CLOSE),
                call().__bool__(),
                call(GeneralSettings.PROMPT_SAVE_EDITOR_MODIFIED),
                call().__bool__()
            ])

        mock_ConfigService.getString.assert_has_calls([
            call(GeneralSettings.PR_RECOVERY_ENABLED),
            call(GeneralSettings.PR_TIME_BETWEEN_RECOVERY),
            call(GeneralSettings.PR_NUMBER_OF_CHECKPOINTS),
            call(GeneralSettings.USE_NOTIFICATIONS),
            call(GeneralSettings.CRYSTALLOGRAPY_CONV),
            call(GeneralSettings.OPENGL)
        ])
Example #17
0
    def test_setup_checkbox_signals(self):
        presenter = GeneralSettings(None)

        self.assert_connected_once(
            presenter.view.crystallography_convention,
            presenter.view.crystallography_convention.stateChanged)

        self.assert_connected_once(presenter.view.use_open_gl,
                                   presenter.view.use_open_gl.stateChanged)

        self.assert_connected_once(
            presenter.view.show_invisible_workspaces,
            presenter.view.show_invisible_workspaces.stateChanged)

        self.assert_connected_once(
            presenter.view.project_recovery_enabled,
            presenter.view.project_recovery_enabled.stateChanged)

        self.assert_connected_once(
            presenter.view.time_between_recovery,
            presenter.view.time_between_recovery.valueChanged)

        self.assert_connected_once(
            presenter.view.total_number_checkpoints,
            presenter.view.total_number_checkpoints.valueChanged)
Example #18
0
    def __init__(self,
                 parent,
                 view=None,
                 general_settings=None,
                 categories_settings=None,
                 plot_settings=None,
                 fitting_settings=None):
        self.view = view if view else SettingsView(parent, self)
        self.general_settings = general_settings if general_settings else GeneralSettings(
            parent)
        self.categories_settings = categories_settings if categories_settings else CategoriesSettings(
            parent)
        self.plot_settings = plot_settings if plot_settings else PlotSettings(
            parent)
        self.fitting_settings = fitting_settings if fitting_settings else FittingSettings(
            parent)
        self.parent = parent

        self.view.sections.addItems(list(self.SETTINGS_TABS.values()))
        self.current = self.general_settings.view
        self.view.container.addWidget(self.general_settings.view)
        self.view.container.addWidget(self.categories_settings.view)
        self.view.container.addWidget(self.plot_settings.view)
        self.view.container.addWidget(self.fitting_settings.view)

        self.view.help_button.clicked.connect(self.action_open_help_window)
        self.ask_before_close = False
Example #19
0
    def test_setup_general_group_signals(self):
        presenter = GeneralSettings(None)

        self.assert_connected_once(presenter.view.main_font,
                                   presenter.view.main_font.clicked)
        self.assert_connected_once(presenter.view.window_behaviour,
                                   presenter.view.window_behaviour.currentTextChanged)
Example #20
0
    def test_load_layout(self, mock_CONF):
        presenter = GeneralSettings(None, view=Mock())
        # setup parent
        mock_parent = Mock()
        presenter.parent = mock_parent
        # setup item selection
        list_item = Mock()
        list_item.text.return_value = 'a'
        presenter.view.layout_display.currentItem = Mock(return_value=list_item)
        # setup CONF.get returns dictionary
        test_dict = {'a': 1}
        mock_CONF.get = Mock(return_value=test_dict)

        presenter.load_layout()

        mock_CONF.get.assert_called_once_with(GeneralProperties.USER_LAYOUT.value, type=dict)
        mock_parent.restoreState.assert_called_once_with(test_dict['a'], SAVE_STATE_VERSION)
Example #21
0
    def test_setup_facilities_with_invalid_default_instrument_chooses_first(self, mock_ConfigService):
        mock_ConfigService.getInstrument.side_effect = [RuntimeError("Invalid instrument name"),
                                                        mock_ConfigService.mock_instrument]
        presenter = GeneralSettings(None)

        self.assertEqual(mock_ConfigService.mock_instrument.name(),
                         presenter.view.instrument.currentText())
        self.assert_connected_once(presenter.view.facility, presenter.view.facility.currentTextChanged)
        self.assert_connected_once(presenter.view.instrument, presenter.view.instrument.currentTextChanged)
Example #22
0
    def test_setup_confirmations(self):
        presenter = GeneralSettings(None)

        # check that the signals are connected to something
        self.assert_connected_once(presenter.view.prompt_save_on_close,
                                   presenter.view.prompt_save_on_close.stateChanged)

        self.assert_connected_once(presenter.view.prompt_save_editor_modified,
                                   presenter.view.prompt_save_editor_modified.stateChanged)
Example #23
0
    def test_save_layout(self, mock_CONF):
        presenter = GeneralSettings(None, view=Mock())
        # setup parent
        mock_parent = Mock()
        mock_parent.saveState.return_value = "value"
        presenter.parent = mock_parent
        # setup CONF.get returns dictionary
        test_dict = {'a': 1}
        mock_CONF.get = Mock(return_value=test_dict)
        # setup mock commands
        presenter.view.new_layout_name.text = Mock(return_value='key')
        presenter.view.new_layout_name.clear = Mock()

        presenter.save_layout()

        calls = [call(presenter.USER_LAYOUT), call(presenter.USER_LAYOUT)]
        mock_CONF.get.assert_has_calls(calls)
        mock_parent.saveState.assert_called_once_with()
        mock_parent.populate_layout_menu.assert_called_once_with()
Example #24
0
    def test_delete_layout(self, mock_CONF):
        presenter = GeneralSettings(None, view=Mock())
        # setup parent
        mock_parent = Mock()
        presenter.parent = mock_parent
        # setup item selection
        list_item = Mock()
        list_item.text.return_value = 'a'
        presenter.view.layout_display.currentItem = Mock(return_value=list_item)
        # setup CONF.get returns dictionary
        test_dict = {'a': 1}
        mock_CONF.get = Mock(return_value=test_dict)

        presenter.delete_layout()

        calls = [call(presenter.USER_LAYOUT), call(presenter.USER_LAYOUT)]
        mock_CONF.get.assert_has_calls(calls)
        mock_CONF.set.assert_called_once_with(presenter.USER_LAYOUT, {})
        mock_parent.populate_layout_menu.assert_called_once_with()
Example #25
0
    def test_setup_facilities_with_valid_combination(self, mock_ConfigService):
        self.assertEqual(0, mock_ConfigService.mock_instrument.name.call_count)
        presenter = GeneralSettings(None)
        self.assertEqual(0, mock_ConfigService.setFacility.call_count)
        self.assertEqual(2, mock_ConfigService.getFacility.call_count)
        self.assertEqual(2, mock_ConfigService.mock_facility.name.call_count)
        self.assert_connected_once(presenter.view.facility, presenter.view.facility.currentTextChanged)

        mock_ConfigService.getInstrument.assert_called_once_with()
        self.assertEqual(1, mock_ConfigService.mock_instrument.name.call_count)
        self.assert_connected_once(presenter.view.instrument, presenter.view.instrument.currentTextChanged)
Example #26
0
    def __init__(self, parent, view=None, general_settings=None):
        self.view = view if view else SettingsView(parent, self)
        self.general_settings = general_settings if general_settings else GeneralSettings(parent)
        self.parent = parent

        self.current = self.general_settings.view
        self.view.container.addWidget(self.general_settings.view)

        self.view.save_settings_button.clicked.connect(self.action_save_settings_button)

        self.ask_before_close = False
Example #27
0
    def test_load_current_setting_values(self, mock_ConfigService, mock_CONF):
        # load current setting is called automatically in the constructor
        GeneralSettings(None)

        # calls().__int__() are the calls to int() on the retrieved value from ConfigService.getString
        mock_CONF.get.assert_has_calls([call(GeneralSettings.PROMPT_SAVE_ON_CLOSE),
                                        call().__int__(),
                                        call(GeneralSettings.PROMPT_SAVE_EDITOR_MODIFIED),
                                        call().__int__()])

        mock_ConfigService.getString.assert_has_calls([call(GeneralSettings.PR_RECOVERY_ENABLED),
                                                       call(GeneralSettings.PR_TIME_BETWEEN_RECOVERY),
                                                       call(GeneralSettings.PR_NUMBER_OF_CHECKPOINTS)])
    def test_setup_facilities(self, mock_ConfigService):
        presenter = GeneralSettings(None)
        mock_ConfigService.setFacility.assert_called_once_with(
            MockFacility.MOCK_NAME)
        self.assertEqual(2, mock_ConfigService.getFacility.call_count)
        mock_ConfigService.mock_facility.name.assert_called_once_with()
        self.assert_connected_once(presenter.view.facility,
                                   presenter.view.facility.currentTextChanged)

        mock_ConfigService.getInstrument.assert_called_once_with()
        mock_ConfigService.mock_instrument.name.assert_called_once_with()
        self.assert_connected_once(
            presenter.view.instrument,
            presenter.view.instrument.currentTextChanged)
Example #29
0
    def test_load_current_setting_values(self, mock_ConfigService, mock_CONF):
        # load current setting is called automatically in the constructor
        GeneralSettings(None)

        # 'any_order' is used to avoid having to assert call().__index__ is called due to 'get' returning a mock object
        mock_CONF.get.assert_has_calls([call(GeneralProperties.PROMPT_SAVE_ON_CLOSE.value, type=bool),
                                        call(GeneralProperties.PROMPT_SAVE_EDITOR_MODIFIED.value, type=bool),
                                        call(GeneralProperties.PROMPT_ON_DELETING_WORKSPACE.value, type=bool),
                                        call(GeneralProperties.COMPLETION_ENABLED.value, type=bool)], any_order=True)

        mock_ConfigService.getString.assert_has_calls([call(GeneralProperties.PR_RECOVERY_ENABLED.value),
                                                       call(GeneralProperties.PR_TIME_BETWEEN_RECOVERY.value),
                                                       call(GeneralProperties.PR_NUMBER_OF_CHECKPOINTS.value),
                                                       call(GeneralProperties.USE_NOTIFICATIONS.value),
                                                       call(GeneralProperties.CRYSTALLOGRAPY_CONV.value),
                                                       call(GeneralProperties.OPENGL.value)])
Example #30
0
    def test_action_window_behaviour_changed(self, mock_conf):
        presenter = GeneralSettings(None)
        values = presenter.WINDOW_BEHAVIOUR
        presenter.action_window_behaviour_changed(values[0])

        mock_conf.set.assert_called_once_with(GeneralProperties.WINDOW_BEHAVIOUR.value, values[0])
        mock_conf.set.reset_mock()

        presenter.action_window_behaviour_changed(values[1])

        mock_conf.set.assert_called_once_with(GeneralProperties.WINDOW_BEHAVIOUR.value, values[1])
Example #31
0
    def test_action_completion_enabled_modified(self, mock_CONF):
        presenter = GeneralSettings(None)
        # reset any effects from the constructor
        mock_CONF.setString.reset_mock()

        presenter.action_completion_enabled_modified(True)
        mock_CONF.set.assert_called_once_with(GeneralProperties.COMPLETION_ENABLED.value, True)
        mock_CONF.set.reset_mock()

        presenter.action_completion_enabled_modified(False)
        mock_CONF.set.assert_called_once_with(GeneralProperties.COMPLETION_ENABLED.value, False)
Example #32
0
    def test_action_prompt_save_on_close(self, mock_conf):
        presenter = GeneralSettings(None)

        presenter.action_prompt_save_on_close(True)

        mock_conf.set.assert_called_once_with(GeneralProperties.PROMPT_SAVE_ON_CLOSE.value, True)
        mock_conf.set.reset_mock()

        presenter.action_prompt_save_on_close(False)

        mock_conf.set.assert_called_once_with(GeneralProperties.PROMPT_SAVE_ON_CLOSE.value, False)
Example #33
0
    def test_action_prompt_save_editor_modified(self, mock_CONF):
        presenter = GeneralSettings(None)

        presenter.action_prompt_save_editor_modified(True)

        mock_CONF.set.assert_called_once_with(GeneralProperties.PROMPT_SAVE_EDITOR_MODIFIED.value, True)
        mock_CONF.set.reset_mock()

        presenter.action_prompt_save_editor_modified(False)

        mock_CONF.set.assert_called_once_with(GeneralProperties.PROMPT_SAVE_EDITOR_MODIFIED.value, False)
Example #34
0
    def test_action_prompt_deleting_workspace(self, mock_CONF):
        presenter = GeneralSettings(None)
        presenter.settings_presenter = MagicMock()

        presenter.action_prompt_deleting_workspace(True)

        mock_CONF.set.assert_called_once_with(GeneralProperties.PROMPT_ON_DELETING_WORKSPACE.value, True)
        presenter.settings_presenter.register_change_needs_restart.assert_called_once()
        mock_CONF.set.reset_mock()
        presenter.settings_presenter.reset_mock()

        presenter.action_prompt_deleting_workspace(False)

        mock_CONF.set.assert_called_once_with(GeneralProperties.PROMPT_ON_DELETING_WORKSPACE.value, False)
        presenter.settings_presenter.register_change_needs_restart.assert_called_once()
Example #35
0
    def test_action_use_open_gl(self, mock_ConfigService):
        presenter = GeneralSettings(None, view=Mock())
        # reset any effects from the constructor
        mock_ConfigService.setString.reset_mock()

        presenter.action_use_open_gl(Qt.Checked)
        mock_ConfigService.setString.assert_called_once_with(GeneralProperties.OPENGL.value, "On")

        mock_ConfigService.setString.reset_mock()

        presenter.action_use_open_gl(Qt.Unchecked)
        mock_ConfigService.setString.assert_called_once_with(GeneralProperties.OPENGL.value, "Off")
Example #36
0
    def test_action_show_invisible_workspaces(self, mock_ConfigService):
        presenter = GeneralSettings(None)
        # reset any effects from the constructor
        mock_ConfigService.setString.reset_mock()

        presenter.action_show_invisible_workspaces(True)
        mock_ConfigService.setString.assert_called_once_with(GeneralProperties.SHOW_INVISIBLE_WORKSPACES.value, "True")

        mock_ConfigService.setString.reset_mock()

        presenter.action_show_invisible_workspaces(False)
        mock_ConfigService.setString.assert_called_once_with(GeneralProperties.SHOW_INVISIBLE_WORKSPACES.value, "False")
Example #37
0
    def test_action_use_notifications_modified(self, mock_ConfigService):
        presenter = GeneralSettings(None)
        mock_ConfigService.setString.reset_mock()

        presenter.action_use_notifications_modified(Qt.Checked)

        mock_ConfigService.setString.assert_called_once_with(GeneralProperties.USE_NOTIFICATIONS.value, "On")
        mock_ConfigService.setString.reset_mock()

        presenter.action_use_notifications_modified(Qt.Unchecked)

        mock_ConfigService.setString.assert_called_once_with(GeneralProperties.USE_NOTIFICATIONS.value, "Off")
Example #38
0
    def test_action_project_recovery_enabled(self, mock_ConfigService):
        presenter = GeneralSettings(None)
        # reset any effects from the constructor
        mock_ConfigService.setString.reset_mock()

        presenter.action_project_recovery_enabled(True)
        mock_ConfigService.setString.assert_called_once_with(GeneralProperties.PR_RECOVERY_ENABLED.value, "True")

        mock_ConfigService.setString.reset_mock()

        presenter.action_project_recovery_enabled(False)
        mock_ConfigService.setString.assert_called_once_with(GeneralProperties.PR_RECOVERY_ENABLED.value, "False")