def test_upgrade_setting_value(self, mocked_remove, mocked_setValue, mocked_value, mocked_contains): """Test that the upgrade mechanism for settings correctly uses the new value when it's not a function""" # GIVEN: A settings object with an upgrade step to take (99, so that we don't interfere with real ones) local_settings = Settings() local_settings.__setting_upgrade_99__ = [ ('values/old value', 'values/new value', [(True, 1)]) ] settings.__version__ = 99 mocked_value.side_effect = [98, 1] mocked_contains.return_value = True # WHEN: upgrade_settings() is called local_settings.upgrade_settings() # THEN: The correct calls should have been made with the correct values assert mocked_value.call_count == 2, 'Settings().value() should have been called twice' assert mocked_value.call_args_list == [ call('settings/version', 0), call('values/old value') ] assert mocked_setValue.call_count == 2, 'Settings().setValue() should have been called twice' assert mocked_setValue.call_args_list == [ call('values/new value', True), call('settings/version', 99) ] mocked_contains.assert_called_once_with('values/old value') mocked_remove.assert_called_once_with('values/old value')
def test_upgrade_multiple_one_invalid(self, mocked_remove, mocked_setValue, mocked_value, mocked_contains): """Test that the upgrade mechanism for settings works correctly for multiple values where one is invalid""" # GIVEN: A settings object with an upgrade step to take local_settings = Settings() local_settings.__setting_upgrade_99__ = [ (['multiple/value 1', 'multiple/value 2'], 'single/new value', []) ] settings.__version__ = 99 mocked_value.side_effect = [98, 10] mocked_contains.side_effect = [True, False] # WHEN: upgrade_settings() is called local_settings.upgrade_settings() # THEN: The correct calls should have been made with the correct values mocked_value.assert_called_once_with('settings/version', 0) mocked_setValue.assert_called_once_with('settings/version', 99) assert mocked_contains.call_args_list == [call('multiple/value 1'), call('multiple/value 2')]
def main(args=None): """ The main function which parses command line options and then runs :param args: Some args """ args = parse_options(args) qt_args = [] if args and args.loglevel.lower() in ['d', 'debug']: log.setLevel(logging.DEBUG) elif args and args.loglevel.lower() in ['w', 'warning']: log.setLevel(logging.WARNING) else: log.setLevel(logging.INFO) # Throw the rest of the arguments at Qt, just in case. qt_args.extend(args.rargs) # Bug #1018855: Set the WM_CLASS property in X11 if not is_win() and not is_macosx(): qt_args.append('OpenLP') # Initialise the resources qInitResources() # Now create and actually run the application. application = OpenLP(qt_args) application.setOrganizationName('OpenLP') application.setOrganizationDomain('openlp.org') application.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps, True) application.setAttribute(QtCore.Qt.AA_DontCreateNativeWidgetSiblings, True) if args.portable: application.setApplicationName('OpenLPPortable') Settings.setDefaultFormat(Settings.IniFormat) # Get location OpenLPPortable.ini portable_path = (AppLocation.get_directory(AppLocation.AppDir) / '..' / '..').resolve() data_path = portable_path / 'Data' set_up_logging(portable_path / 'Other') log.info('Running portable') portable_settings_path = data_path / 'OpenLP.ini' # Make this our settings file log.info('INI file: {name}'.format(name=portable_settings_path)) Settings.set_filename(str(portable_settings_path)) portable_settings = Settings() # Set our data path log.info('Data path: {name}'.format(name=data_path)) # Point to our data path portable_settings.setValue('advanced/data path', data_path) portable_settings.setValue('advanced/is portable', True) portable_settings.sync() else: application.setApplicationName('OpenLP') set_up_logging(AppLocation.get_directory(AppLocation.CacheDir)) Registry.create() Registry().register('application', application) Registry().set_flag('no_web_server', args.no_web_server) application.setApplicationVersion(get_version()['version']) # Check if an instance of OpenLP is already running. Quit if there is a running instance and the user only wants one server = Server() if server.is_another_instance_running(): application.is_already_running() server.post_to_server(qt_args) sys.exit() else: server.start_server() application.server = server # If the custom data path is missing and the user wants to restore the data path, quit OpenLP. if application.is_data_path_missing(): server.close_server() sys.exit() # Upgrade settings. settings = Settings() if settings.can_upgrade(): now = datetime.now() # Only back up if OpenLP has previously run. if settings.value('core/has run wizard'): back_up_path = AppLocation.get_data_path() / ( now.strftime('%Y-%m-%d %H-%M') + '.conf') log.info( 'Settings about to be upgraded. Existing settings are being backed up to {back_up_path}' .format(back_up_path=back_up_path)) QtWidgets.QMessageBox.information( None, translate('OpenLP', 'Settings Upgrade'), translate( 'OpenLP', 'Your settings are about to be upgraded. A backup will be created at ' '{back_up_path}').format(back_up_path=back_up_path)) settings.export(back_up_path) settings.upgrade_settings() # First time checks in settings if not Settings().value('core/has run wizard'): if not FirstTimeLanguageForm().exec(): # if cancel then stop processing server.close_server() sys.exit() # i18n Set Language language = LanguageManager.get_language() translators = LanguageManager.get_translators(language) for translator in translators: if not translator.isEmpty(): application.installTranslator(translator) if not translators: log.debug('Could not find translators.') if args and not args.no_error_form: sys.excepthook = application.hook_exception sys.exit(application.run(qt_args))