def test_that_about_presenter_is_instantiated_without_error_when_getFacility_causes_exception(self, MockConfigService): MockConfigService.getFacility.side_effect = RuntimeError(Mock(status=101), "No facility") presenter = AboutPresenter(None) self.assertEqual(3, MockConfigService.getFacility.call_count) self.assertEqual(presenter._get_current_facility(), None)
def test_should_show_on_startup_invalid_facility(self, MockConfigService): MockConfigService.getFacility.side_effect = RuntimeError("Invalid Facility name") self.assertTrue(AboutPresenter.should_show_on_startup(), "If the facilty is invalid then should_show_on_startup should always be true") MockConfigService.getString.assert_has_calls([call(AboutPresenter.FACILITY), call(AboutPresenter.INSTRUMENT)]) MockConfigService.getFacility.assert_has_calls([call("FACILITY1")])
def test_setup_facilities_with_valid_combination(self, mock_ConfigService): self.assertEqual(0, mock_ConfigService.mock_instrument.name.call_count) presenter = AboutPresenter(None) self.assertEqual(0, mock_ConfigService.setFacility.call_count) self.assertEqual(3, mock_ConfigService.getFacility.call_count) self.assertEqual(3, mock_ConfigService.mock_facility.name.call_count) self.assert_connected_once(presenter.view.about_widget.cb_facility, presenter.view.about_widget.cb_facility.currentTextChanged)
def test_should_show_on_startup_no_facility(self, MockConfigService): MockConfigService.getString.return_value = "" self.assertTrue( AboutPresenter.should_show_on_startup(), "If the facilty is not set then should_show_on_startup should always be true" ) MockConfigService.getString.assert_has_calls( [call(AboutPresenter.FACILITY), call(AboutPresenter.INSTRUMENT)])
def test_setup_checkbox_signals(self): presenter = AboutPresenter(None) about_widget = presenter.view.about_widget self.assert_connected_once(about_widget.chk_do_not_show_until_next_release, presenter.view.about_widget.chk_do_not_show_until_next_release.stateChanged) self.assert_connected_once(about_widget.chk_allow_usage_data, about_widget.chk_allow_usage_data.stateChanged)
def test_setup_checkbox_signals(self): presenter = AboutPresenter(None) self.assert_connected_once( presenter.view.chkDoNotShowUntilNextRelease, presenter.view.chkDoNotShowUntilNextRelease.stateChanged) self.assert_connected_once( presenter.view.chkAllowUsageData, presenter.view.chkAllowUsageData.stateChanged)
def test_should_show_on_startup_do_not_show_same_version(self, MockConfigService): version_str = "the same every time" with patch(self.QSETTINGS_CLASSPATH, return_value=FakeQSettings(version_str)): with patch(self.RELEASE_NOTES_URL_CLASSPATH, return_value=version_str): self.assertFalse(AboutPresenter.should_show_on_startup(), "If do not show is in Qsettings then should_show_on_startup should always be False" + "for the same version") MockConfigService.getString.assert_has_calls([call(AboutPresenter.FACILITY), call(AboutPresenter.INSTRUMENT)]) MockConfigService.getFacility.assert_has_calls([call("FACILITY1")]) MockConfigService.getInstrument.assert_has_calls([call("FACILITY1")])
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 = AboutPresenter(None) self.assertEqual(mock_ConfigService.mock_instrument.name(), presenter.view.cbInstrument.currentText()) self.assert_connected_once( presenter.view.cbFacility, presenter.view.cbFacility.currentTextChanged) self.assert_connected_once( presenter.view.cbInstrument, presenter.view.cbInstrument.currentTextChanged)
def test_setup_button_signals(self): presenter = AboutPresenter(None) about_widget = presenter.view.about_widget self.assert_connected_once(about_widget.clb_release_notes, about_widget.clb_release_notes.clicked) self.assert_connected_once(about_widget.clb_sample_datasets, about_widget.clb_sample_datasets.clicked) self.assert_connected_once(about_widget.clb_mantid_introduction, about_widget.clb_mantid_introduction.clicked) self.assert_connected_once(about_widget.clb_python_introduction, about_widget.clb_python_introduction.clicked) self.assert_connected_once(about_widget.clb_python_in_mantid, about_widget.clb_python_in_mantid.clicked) self.assert_connected_once(about_widget.clb_extending_mantid, about_widget.clb_extending_mantid.clicked) self.assert_connected_once(about_widget.pb_manage_user_directories, about_widget.pb_manage_user_directories.clicked) self.assert_connected_once(about_widget.lbl_privacy_policy, about_widget.lbl_privacy_policy.linkActivated)
def test_setup_button_signals(self): presenter = AboutPresenter(None) self.assert_connected_once(presenter.view.clbReleaseNotes, presenter.view.clbReleaseNotes.clicked) self.assert_connected_once(presenter.view.clbSampleDatasets, presenter.view.clbSampleDatasets.clicked) self.assert_connected_once( presenter.view.clbMantidIntroduction, presenter.view.clbMantidIntroduction.clicked) self.assert_connected_once( presenter.view.clbPythonIntroduction, presenter.view.clbPythonIntroduction.clicked) self.assert_connected_once(presenter.view.clbPythonInMantid, presenter.view.clbPythonInMantid.clicked) self.assert_connected_once(presenter.view.clbExtendingMantid, presenter.view.clbExtendingMantid.clicked) self.assert_connected_once(presenter.view.pbMUD, presenter.view.pbMUD.clicked) self.assert_connected_once( presenter.view.lblPrivacyPolicy, presenter.view.lblPrivacyPolicy.linkActivated)
def start_workbench(app, command_line_options): """Given an application instance create the MainWindow, show it and start the main event loop """ # The ordering here is very delicate. Test thoroughly when # changing anything! main_window = MainWindow() # Set the mainwindow as the parent for additional QMainWindow instances from workbench.config import set_additional_windows_parent set_additional_windows_parent(main_window) # decorates the excepthook callback with the reference to the main window # this is used in case the user wants to terminate the workbench from the error window shown sys.excepthook = partial(exception_logger, main_window) # Load matplotlib as early as possible and set our defaults # Setup our custom backend and monkey patch in custom current figure manager main_window.set_splash('Preloading matplotlib') from workbench.plotting.config import initialize_matplotlib # noqa initialize_matplotlib() # Setup widget layouts etc. mantid.simple cannot be used before this # or the log messages don't get through to the widget main_window.setup() # start mantid main_window.set_splash('Initializing mantid framework') FrameworkManagerImpl.Instance() main_window.post_mantid_init() if main_window.splash: main_window.splash.hide() if command_line_options.script is not None: main_window.editor.open_file_in_new_tab(command_line_options.script) editor_task = None if command_line_options.execute: # if the quit flag is not specified, this task reference will be # GC'ed, and the task will be finished alongside the GUI startup editor_task = main_window.editor.execute_current_async() if command_line_options.quit: # wait for the code interpreter thread to finish executing the script editor_task.join() main_window.close() # for task exit code descriptions see the classes AsyncTask and TaskExitCode return int(editor_task.exit_code) if editor_task else 0 main_window.show() main_window.setWindowIcon(QIcon(':/images/MantidIcon.ico')) # Project Recovery on startup main_window.project_recovery.repair_checkpoints() if main_window.project_recovery.check_for_recover_checkpoint(): main_window.project_recovery.attempt_recovery() else: main_window.project_recovery.start_recovery_thread() if not (command_line_options.execute or command_line_options.quit): if AboutPresenter.should_show_on_startup(): AboutPresenter(main_window).show() # lift-off! return app.exec_()
def open_about(self): about = AboutPresenter(self) about.show()
def create_and_launch_workbench(app, command_line_options): """Given an application instance create the MainWindow, show it and start the main event loop """ exit_value = 0 try: # MainWindow needs to be imported locally to ensure the matplotlib # backend is not imported too early. from workbench.app.mainwindow import MainWindow # The ordering here is very delicate. Test thoroughly when # changing anything! main_window = MainWindow() # Set the mainwindow as the parent for additional QMainWindow instances from workbench.config import set_additional_windows_parent set_additional_windows_parent(main_window) # decorates the excepthook callback with the reference to the main window # this is used in case the user wants to terminate the workbench from the error window shown sys.excepthook = partial(exception_logger, main_window) # Load matplotlib as early as possible and set our defaults # Setup our custom backend and monkey patch in custom current figure manager main_window.set_splash('Preloading matplotlib') from workbench.plotting.config import initialize_matplotlib # noqa initialize_matplotlib() # Setup widget layouts etc. mantid.simple cannot be used before this # or the log messages don't get through to the widget main_window.setup() # start mantid main_window.set_splash('Initializing mantid framework') FrameworkManagerImpl.Instance() main_window.post_mantid_init() if main_window.splash: main_window.splash.hide() if command_line_options.script is not None: main_window.editor.open_file_in_new_tab( command_line_options.script) editor_task = None if command_line_options.execute: # if the quit flag is not specified, this task reference will be # GC'ed, and the task will be finished alongside the GUI startup editor_task = main_window.editor.execute_current_async() if command_line_options.quit: # wait for the code interpreter thread to finish executing the script editor_task.join() main_window.close() # for task exit code descriptions see the classes AsyncTask and TaskExitCode return int(editor_task.exit_code) if editor_task else 0 main_window.show() main_window.setWindowIcon(QIcon(':/images/MantidIcon.ico')) # Project Recovery on startup main_window.project_recovery.repair_checkpoints() if main_window.project_recovery.check_for_recover_checkpoint(): main_window.project_recovery.attempt_recovery() else: main_window.project_recovery.start_recovery_thread() if not (command_line_options.execute or command_line_options.quit): if AboutPresenter.should_show_on_startup(): AboutPresenter(main_window).show() # lift-off! exit_value = app.exec_() except BaseException: # We count this as a crash import traceback # This is type of thing we want to capture and have reports # about. Prints to stderr as we can't really count on anything # else traceback.print_exc(file=ORIGINAL_STDERR) try: print_file_path = os.path.join(ConfigService.getAppDataDirectory(), STACKTRACE_FILE) with open(print_file_path, 'w') as print_file: traceback.print_exc(file=print_file) except OSError: pass exit_value = -1 finally: ORIGINAL_SYS_EXIT(exit_value)
def test_setup_link_signals(self): presenter = AboutPresenter(None) about_widget = presenter.view.about_widget self.assert_connected_once(about_widget.clb_release_notes, about_widget.clb_release_notes.clicked)
def test_setup_link_signals(self): presenter = AboutPresenter(None) self.assert_connected_once(presenter.view.clbReleaseNotes, presenter.view.clbReleaseNotes.clicked)