def test_add_vocable(self, vocable_not_in_list): length_of_vocables_before = len(VocableManager.vocables) VocableManager.add_vocable(vocable_not_in_list) length_of_vocables_after = len(VocableManager.vocables) assert vocable_not_in_list in VocableManager.vocables, \ 'The vocable was not added.' assert length_of_vocables_before + 1 == length_of_vocables_after, \ 'Not exactly one vocable was added to the list of vocables.' number_of_vocables = len(VocableManager.vocables) random_indices = [] existing_vocables = [] for index in range(100): # get an index, which we've not yet selected random_index = randint(0, number_of_vocables-1) while random_index in random_indices: random_index = randint(0, number_of_vocables-1) random_indices.append(random_index) existing_vocables.append(VocableManager.vocables[random_index]) for existing_vocable in existing_vocables: try: VocableManager.add_vocable(existing_vocable) assert False, \ 'could add existing vocable again' except DuplicateVocableException as dvexception: pass
def test_add_vocable(self, vocable_not_in_list): length_of_vocables_before = len(VocableManager.vocables) VocableManager.add_vocable(vocable_not_in_list) length_of_vocables_after = len(VocableManager.vocables) assert vocable_not_in_list in VocableManager.vocables, \ 'The vocable was not added.' assert length_of_vocables_before + 1 == length_of_vocables_after, \ 'Not exactly one vocable was added to the list of vocables.' number_of_vocables = len(VocableManager.vocables) random_indices = [] existing_vocables = [] for index in range(100): # get an index, which we've not yet selected random_index = randint(0, number_of_vocables - 1) while random_index in random_indices: random_index = randint(0, number_of_vocables - 1) random_indices.append(random_index) existing_vocables.append(VocableManager.vocables[random_index]) for existing_vocable in existing_vocables: try: VocableManager.add_vocable(existing_vocable) assert False, \ 'could add existing vocable again' except DuplicateVocableException as dvexception: pass
def test_remove_vocable_by_index(self): number_of_vocables = len(VocableManager.vocables) random_indices = [] selected_vocables = [] for index in range(100): # get an index, which we've not yet selected random_index = randint(0, number_of_vocables-1) while random_index in random_indices: random_index = randint(0, number_of_vocables-1) random_indices.append(random_index) assert CollectionsHelper.all_unique(random_indices), \ 'Trying to remove vocable of one and the same index twice during test.' deleted_vocables = [] random_indices.sort(reverse=True) for vocable_index in random_indices: deleted_vocables.append(VocableManager.vocables[vocable_index]) VocableManager.remove_vocable_by_index(vocable_index) assert deleted_vocables[-1] is not None, \ 'There is no handle on the deleted vocable anymore.' assert deleted_vocables[-1] not in VocableManager.vocables, \ 'Vocable was not deleted from vocables.' for vocable in deleted_vocables: print(vocable) for vocable in deleted_vocables: assert vocable not in VocableManager.vocables, \ 'Vocable was not deleted from vocables.'
def run_application(self): AppSettings.load_settings() VocableManager.load_vocables() self.xld_main_window = XLDMainWindow() Gtk.main()
def test_remove_vocable_by_index(self): number_of_vocables = len(VocableManager.vocables) random_indices = [] selected_vocables = [] for index in range(100): # get an index, which we've not yet selected random_index = randint(0, number_of_vocables - 1) while random_index in random_indices: random_index = randint(0, number_of_vocables - 1) random_indices.append(random_index) assert CollectionsHelper.all_unique(random_indices), \ 'Trying to remove vocable of one and the same index twice during test.' deleted_vocables = [] random_indices.sort(reverse=True) for vocable_index in random_indices: deleted_vocables.append(VocableManager.vocables[vocable_index]) VocableManager.remove_vocable_by_index(vocable_index) assert deleted_vocables[-1] is not None, \ 'There is no handle on the deleted vocable anymore.' assert deleted_vocables[-1] not in VocableManager.vocables, \ 'Vocable was not deleted from vocables.' for vocable in deleted_vocables: print(vocable) for vocable in deleted_vocables: assert vocable not in VocableManager.vocables, \ 'Vocable was not deleted from vocables.'
def test_remove_vocable_throws_exception(self, vocable_not_in_list): try: VocableManager.remove_vocable(vocable_not_in_list) assert False, 'could remove a not existing vocable' except UnknownVocableException as uvexception: pass try: VocableManager.remove_vocable(VocableManager.vocables[randint(0, len(VocableManager.vocables))]) except UnknownVocableException as uvexception: assert False, 'could not remove existing vocable'
def test_remove_vocable_throws_exception(self, vocable_not_in_list): try: VocableManager.remove_vocable(vocable_not_in_list) assert False, 'could remove a not existing vocable' except UnknownVocableException as uvexception: pass try: VocableManager.remove_vocable(VocableManager.vocables[randint( 0, len(VocableManager.vocables))]) except UnknownVocableException as uvexception: assert False, 'could not remove existing vocable'
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 get_vocable_from_tree_selection(self, tree_selection): vocable_index = -1 (model, pathlist) = tree_selection.get_selected_rows() # print(tree_selection.get_selected()) # not for SELECTION_MULTIPLE print('pathlist:', pathlist) if pathlist is not None and len(pathlist) == 1: vocable_index = int(str(pathlist[0])) # for path in pathlist: # print('path:', int(str(path))) # print('type of path:', type(path)) # print('row object:', model[path]) # print('row object iter:', model[path].iter) # print('row object iter DIR:', dir(model[path].iter)) # print('row objecct iter repr:', repr(model[path].iter)) # print('row index:', model[path][0]) # [column_number_that_you_want] # print('row list', list(model[path])) # for path in pathlist : # print('Path:', path) # # tree_iter = model.get_iter(path) # print('Tree Iter:', tree_iter) # # value = model.get_value(tree_iter) # print(value) return VocableManager.get_search_result_vocable(vocable_index)
def test_remove_vocable(self): # copied_vocables = [] # for index, vocable in enumerate(VocableManager.vocables): # current_vocable = VocableManager.vocables[index] # copied_vocables.append(current_vocable.clone()) # # assert len(copied_vocables) == len(VocableManager.vocables), \ # 'Not all vocables were copied.' # # for index, vocable in enumerate(copied_vocables): # if vocable not in VocableManager.vocables: # print(vocable) number_of_vocables = len(VocableManager.vocables) random_indices = [] selected_vocables = [] for index in range(1000): # get an index, which we've not yet selected random_index = randint(0, number_of_vocables-1) while random_index in random_indices: random_index = randint(0, number_of_vocables-1) random_indices.append(random_index) selected_vocables.append(VocableManager.vocables[random_index]) assert CollectionsHelper.all_unique(random_indices), \ 'Trying to remove vocable of one and the same index twice during test.' for selected_vocable in selected_vocables: VocableManager.remove_vocable(selected_vocable) # VocableManager.vocables.remove(selected_vocable) assert selected_vocable not in VocableManager.vocables, \ 'Vocable was not deleted from vocables. ' + \ str(VocableManager.test_call_counter) + \ ' calls for deletion.' + \ ' The vocable which was not deleted is ' + str(selected_vocable) print('Vocable deleted: ' + str(selected_vocable))
def test_remove_vocable(self): # copied_vocables = [] # for index, vocable in enumerate(VocableManager.vocables): # current_vocable = VocableManager.vocables[index] # copied_vocables.append(current_vocable.clone()) # # assert len(copied_vocables) == len(VocableManager.vocables), \ # 'Not all vocables were copied.' # # for index, vocable in enumerate(copied_vocables): # if vocable not in VocableManager.vocables: # print(vocable) number_of_vocables = len(VocableManager.vocables) random_indices = [] selected_vocables = [] for index in range(1000): # get an index, which we've not yet selected random_index = randint(0, number_of_vocables - 1) while random_index in random_indices: random_index = randint(0, number_of_vocables - 1) random_indices.append(random_index) selected_vocables.append(VocableManager.vocables[random_index]) assert CollectionsHelper.all_unique(random_indices), \ 'Trying to remove vocable of one and the same index twice during test.' for selected_vocable in selected_vocables: VocableManager.remove_vocable(selected_vocable) # VocableManager.vocables.remove(selected_vocable) assert selected_vocable not in VocableManager.vocables, \ 'Vocable was not deleted from vocables. ' + \ str(VocableManager.test_call_counter) + \ ' calls for deletion.' + \ ' The vocable which was not deleted is ' + str(selected_vocable) print('Vocable deleted: ' + str(selected_vocable))
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 test_vocable_list_invariance(self): # get vocables vocables = VocableManager.vocables # save vocables VocableManager.save_vocables(vocables) # check if the vocables are still the same VocableManager.load_vocables() new_vocables = VocableManager.vocables # test object inequality, to assure further testing this way is useful assert vocables[0] is not new_vocables[0], \ 'The compared vocable objects are identical.' # for all vocables for index in range(len(vocables)): # for all first language translations for attribute_index in range( len(vocables[index].first_language_translations)): first_language_transaltion_1 = vocables[ index].first_language_translations[attribute_index] first_language_transaltion_2 = new_vocables[ index].first_language_translations[attribute_index] assert first_language_transaltion_1 == first_language_transaltion_2, \ 'There are differences in a vocable\'s first_language_translations attribute.' # for all first language phonetic scripts for attribute_index in range( len(vocables[index].first_language_phonetic_scripts)): first_language_phonetic_script_1 = vocables[ index].first_language_phonetic_scripts[attribute_index] first_language_phonetic_script_2 = new_vocables[ index].first_language_phonetic_scripts[attribute_index] assert first_language_phonetic_script_1 == first_language_phonetic_script_2, \ 'There are differences in a vocable\'s first_language_phonetic_scripts attribute.' # for all second language translations for attribute_index in range( len(vocables[index].second_language_translations)): second_language_transaltion_1 = vocables[ index].second_language_translations[attribute_index] second_language_transaltion_2 = new_vocables[ index].second_language_translations[attribute_index] assert second_language_transaltion_1 == second_language_transaltion_2, \ 'There are differences in a vocable\'s second_language_translations attribute.' # for all second language phonetic scripts for attribute_index in range( len(vocables[index].second_language_phonetic_scripts)): second_language_phonetic_script_1 = vocables[ index].second_language_phonetic_scripts[attribute_index] second_language_phonetic_script_2 = new_vocables[ index].second_language_phonetic_scripts[attribute_index] assert second_language_phonetic_script_1 == second_language_phonetic_script_2, \ 'There are differences in a vocable\'s second_language_phonetic_scripts attribute.' # for all topics scripts for attribute_index in range(len(vocables[index].topics)): topic_1 = vocables[index].topics[attribute_index] topic_2 = new_vocables[index].topics[attribute_index] assert topic_1 == topic_2, \ 'There are differences in a vocable\'s topics attribute.' # for all chapters scripts for attribute_index in range(len(vocables[index].chapters)): chapter_1 = vocables[index].chapters[attribute_index] chapter_2 = new_vocables[index].chapters[attribute_index] assert chapter_1 == chapter_2, \ 'There are differences in a vocable\'s chapters attribute.' assert vocables[index].learn_level == new_vocables[index].learn_level, \ 'There are differences in a vocable\'s learn_level attribute.' assert vocables[index].relevance_level == new_vocables[index].relevance_level, \ 'There are differences in a vocable\'s relevance_level attribute.' assert vocables[index].description == new_vocables[index].description, \ 'There are differences in a vocable\'s description attribute.'
def load_vocables(self, load_app_settings): VocableManager.load_vocables() # TODO: use test vocables
def test_vocable_list_invariance(self): # get vocables vocables = VocableManager.vocables # save vocables VocableManager.save_vocables(vocables) # check if the vocables are still the same VocableManager.load_vocables() new_vocables = VocableManager.vocables # test object inequality, to assure further testing this way is useful assert vocables[0] is not new_vocables[0], \ 'The compared vocable objects are identical.' # for all vocables for index in range(len(vocables)): # for all first language translations for attribute_index in range(len(vocables[index].first_language_translations)): first_language_transaltion_1 = vocables[index].first_language_translations[attribute_index] first_language_transaltion_2 = new_vocables[index].first_language_translations[attribute_index] assert first_language_transaltion_1 == first_language_transaltion_2, \ 'There are differences in a vocable\'s first_language_translations attribute.' # for all first language phonetic scripts for attribute_index in range(len(vocables[index].first_language_phonetic_scripts)): first_language_phonetic_script_1 = vocables[index].first_language_phonetic_scripts[attribute_index] first_language_phonetic_script_2 = new_vocables[index].first_language_phonetic_scripts[attribute_index] assert first_language_phonetic_script_1 == first_language_phonetic_script_2, \ 'There are differences in a vocable\'s first_language_phonetic_scripts attribute.' # for all second language translations for attribute_index in range(len(vocables[index].second_language_translations)): second_language_transaltion_1 = vocables[index].second_language_translations[attribute_index] second_language_transaltion_2 = new_vocables[index].second_language_translations[attribute_index] assert second_language_transaltion_1 == second_language_transaltion_2, \ 'There are differences in a vocable\'s second_language_translations attribute.' # for all second language phonetic scripts for attribute_index in range(len(vocables[index].second_language_phonetic_scripts)): second_language_phonetic_script_1 = vocables[index].second_language_phonetic_scripts[attribute_index] second_language_phonetic_script_2 = new_vocables[index].second_language_phonetic_scripts[attribute_index] assert second_language_phonetic_script_1 == second_language_phonetic_script_2, \ 'There are differences in a vocable\'s second_language_phonetic_scripts attribute.' # for all topics scripts for attribute_index in range(len(vocables[index].topics)): topic_1 = vocables[index].topics[attribute_index] topic_2 = new_vocables[index].topics[attribute_index] assert topic_1 == topic_2, \ 'There are differences in a vocable\'s topics attribute.' # for all chapters scripts for attribute_index in range(len(vocables[index].chapters)): chapter_1 = vocables[index].chapters[attribute_index] chapter_2 = new_vocables[index].chapters[attribute_index] assert chapter_1 == chapter_2, \ 'There are differences in a vocable\'s chapters attribute.' assert vocables[index].learn_level == new_vocables[index].learn_level, \ 'There are differences in a vocable\'s learn_level attribute.' assert vocables[index].relevance_level == new_vocables[index].relevance_level, \ 'There are differences in a vocable\'s relevance_level attribute.' assert vocables[index].description == new_vocables[index].description, \ 'There are differences in a vocable\'s description attribute.'
def create_xld_main_window(self): AppSettings.load_settings() # TODO: use test settings VocableManager.load_vocables() # TODO: use text vocables self.xld_main_window = XLDMainWindow() self.xld_main_window.show_all() GTKGUITestHelper.refresh_gui()