def test_xml_settings_file_invariance(self): xml_settings_file_path = get_full_path('res/settings', 'settings.xml') settings_file_content_1 = None with open(xml_settings_file_path, 'rb') as settings_file: settings_file_content_1 = settings_file.read() AppSettings.load_settings() settings_1 = AppSettings.settings AppSettings.save_settings() settings_file_content_2 = None with open(xml_settings_file_path, 'rb') as settings_file: settings_file_content_2 = settings_file.read() AppSettings.load_settings() settings_2 = AppSettings.settings # equality does not work, since dictionaries do not have an invariant order of access, # but something weaker might work # assert settings_file_content_1 == settings_file_content_2, \ # 'Loading and saving the settings causes changes in the XML settings file, ' \ # 'although the settings didn\'t change. These changes might be whitespace character differences.' assert len(settings_file_content_1) == len(settings_file_content_2), \ 'The settings file contents differ in length.' for character in settings_file_content_1: assert character in settings_file_content_2, \ 'There is content in one settings file, which is not in the other.' for character in settings_file_content_2: assert character in settings_file_content_1, \ 'There is content in one settings file, which is not in the other.' characters_1 = {} for character in settings_file_content_1: if character in characters_1: characters_1[character] += 1 else: characters_1[character] = 1 characters_2 = {} for character in settings_file_content_2: if character in characters_2: characters_2[character] += 1 else: characters_2[character] = 1 assert characters_1 == characters_2, \ 'The settings files do not contain the same characters.' assert settings_1 == settings_2, \ 'Loading and saving the settings causes changes in the settings, ' \ 'although were not intentionally changed.'
def exit_application(self, widget, event): strtrue = str(True) save_vocables = AppSettings.get_setting_by_name( AppSettings.SAVE_VOCABLES_ON_EXIT_SETTING_NAME) == strtrue show_dialog = AppSettings.get_setting_by_name( AppSettings.DIALOG_SHOW_SAVE_VOCABLES_CONFIRMATION_SETTING_NAME ) == strtrue if show_dialog and VocableManager.vocables_changed: save_vocables_confirmation_dialog = SaveVocablesBeforeExitConfirmationDialog( self) save_vocables = save_vocables_confirmation_dialog.run( ) == Gtk.ResponseType.YES AppSettings.change_setting_by_name( AppSettings.SAVE_VOCABLES_ON_EXIT_SETTING_NAME, save_vocables) save_vocables_confirmation_dialog.destroy() if save_vocables: VocableManager.save_vocables(VocableManager.vocables) exit_on_exit_confirmation = AppSettings.get_setting_by_name( AppSettings.EXIT_ON_EXIT_SETTING_NAME) == strtrue show_exit_confirmation = AppSettings.get_setting_by_name( AppSettings.DIALOG_SHOW_EXIT_CONFIRMATION_SETTING_NAME) if show_exit_confirmation == strtrue: ExitConfirmationDialog.__init__ = timefunction( ExitConfirmationDialog.__init__) # decoration exit_confirmation_dialog = ExitConfirmationDialog(self) exit_confirmation_dialog.run = timefunction( exit_confirmation_dialog.run) # decoration exit_on_exit_confirmation = exit_confirmation_dialog.run( ) == Gtk.ResponseType.YES AppSettings.change_setting_by_name( AppSettings.EXIT_ON_EXIT_SETTING_NAME, exit_on_exit_confirmation) exit_confirmation_dialog.destroy() if exit_on_exit_confirmation: # print("Clicked YES") AppSettings.save_settings() Gtk.main_quit() sys.exit() else: # print("Clicked NO") pass return GTKSignal.DO_NOT_PROPAGATE
def exit_application(self, widget, event): strtrue = str(True) save_vocables = AppSettings.get_setting_by_name(AppSettings.SAVE_VOCABLES_ON_EXIT_SETTING_NAME) == strtrue show_dialog = AppSettings.get_setting_by_name( AppSettings.DIALOG_SHOW_SAVE_VOCABLES_CONFIRMATION_SETTING_NAME ) == strtrue if show_dialog and VocableManager.vocables_changed: save_vocables_confirmation_dialog = SaveVocablesBeforeExitConfirmationDialog(self) save_vocables = save_vocables_confirmation_dialog.run() == Gtk.ResponseType.YES AppSettings.change_setting_by_name(AppSettings.SAVE_VOCABLES_ON_EXIT_SETTING_NAME, save_vocables) save_vocables_confirmation_dialog.destroy() if save_vocables: VocableManager.save_vocables(VocableManager.vocables) exit_on_exit_confirmation = AppSettings.get_setting_by_name(AppSettings.EXIT_ON_EXIT_SETTING_NAME) == strtrue show_exit_confirmation = AppSettings.get_setting_by_name(AppSettings.DIALOG_SHOW_EXIT_CONFIRMATION_SETTING_NAME) if show_exit_confirmation == strtrue: ExitConfirmationDialog.__init__ = timefunction(ExitConfirmationDialog.__init__) # decoration exit_confirmation_dialog = ExitConfirmationDialog(self) exit_confirmation_dialog.run = timefunction(exit_confirmation_dialog.run) # decoration exit_on_exit_confirmation = exit_confirmation_dialog.run() == Gtk.ResponseType.YES AppSettings.change_setting_by_name(AppSettings.EXIT_ON_EXIT_SETTING_NAME, exit_on_exit_confirmation) exit_confirmation_dialog.destroy() if exit_on_exit_confirmation: # print("Clicked YES") AppSettings.save_settings() Gtk.main_quit() sys.exit() else: # print("Clicked NO") pass return GTKSignal.DO_NOT_PROPAGATE