From 589eb06474b74b2c306d35f63baf780bbe4227b8 Mon Sep 17 00:00:00 2001 From: prculley Date: Tue, 27 Sep 2016 09:36:50 -0500 Subject: [PATCH] Pylint on Check and Repair, Test Case Generator tools --- gramps/plugins/test/test_tools.py | 12 +- gramps/plugins/tool/check.py | 1069 ++++++------- gramps/plugins/tool/testcasegenerator.py | 1825 +++++++++++----------- 3 files changed, 1499 insertions(+), 1407 deletions(-) diff --git a/gramps/plugins/test/test_tools.py b/gramps/plugins/test/test_tools.py index 7fea5d362..0d38c1785 100644 --- a/gramps/plugins/test/test_tools.py +++ b/gramps/plugins/test/test_tools.py @@ -124,10 +124,10 @@ class ToolControl(unittest.TestCase): self.assertEqual(out, "") out, err = call("-O", TREE_NAME, "-y", "-q", "-a", "tool", "-p", - "name=testcasegenerator,bugs=1,persons=0," - "add_linebreak=0,add_serial=0," - "long_names=0,lowlevel=0,person_count=20," - "specialchars=0") + "name=testcasegenerator,bugs=1,persons=1," + "add_linebreak=1,add_serial=1," + "long_names=1,lowlevel=0,person_count=50," + "specialchars=1") expect = ["Opened successfully!", "Performing action: tool.", "Using options string: name=testcasegenerator,bugs=1", @@ -146,8 +146,8 @@ class ToolControl(unittest.TestCase): "1 invalid birth event name was fixed", "1 invalid death event name was fixed", "2 places were referenced, but not found", - "13 citations were referenced, but not found", - "16 sources were referenced, but not found", + "11 citations were referenced, but not found", + "14 sources were referenced, but not found", "7 empty objects removed", "1 person objects", "1 family objects", diff --git a/gramps/plugins/tool/check.py b/gramps/plugins/tool/check.py index d1ac4f827..27976cb83 100644 --- a/gramps/plugins/tool/check.py +++ b/gramps/plugins/tool/check.py @@ -23,39 +23,41 @@ # """Tools/Database Repair/Check and Repair Database""" - -#------------------------------------------------------------------------- +# pylint: disable=too-many-statements,too-many-locals,too-many-branches +# pylint: disable=wrong-import-position,too-many-public-methods,no-self-use +# pylint: disable=too-many-arguments +# ------------------------------------------------------------------------- # # python modules # -#------------------------------------------------------------------------- +# ------------------------------------------------------------------------- import os from io import StringIO -import time from collections import defaultdict +import time -#------------------------------------------------------------------------ +# ------------------------------------------------------------------------ # # Set up logging # -#------------------------------------------------------------------------ +# ------------------------------------------------------------------------ import logging -#------------------------------------------------------------------------- +# ------------------------------------------------------------------------- # # gtk modules # -#------------------------------------------------------------------------- +# ------------------------------------------------------------------------- from gi.repository import Gtk -#------------------------------------------------------------------------- +# ------------------------------------------------------------------------- # # Gramps modules # -#------------------------------------------------------------------------- +# ------------------------------------------------------------------------- from gramps.gen.const import GRAMPS_LOCALE as glocale _ = glocale.translation.gettext -ngettext = glocale.translation.ngettext # else "nearby" comments are ignored +ngettext = glocale.translation.ngettext # else "nearby" comments are ignored from gramps.gen.lib import (Citation, Event, EventType, Family, Media, Name, Note, Person, Place, Repository, Source, StyledText, Tag) @@ -75,19 +77,29 @@ from gramps.gen.errors import HandleError # table for handling control chars in notes. # All except 09, 0A, 0D are replaced with space. -strip_dict = dict.fromkeys(list(range(9))+list(range(11,13))+list(range(14, 32)), " ") +strip_dict = dict.fromkeys(list(range(9)) + list(range(11, 13)) + + list(range(14, 32)), " ") + class ProgressMeter: - def __init__(self, *args, **kwargs): pass - def set_pass(self, *args): pass - def step(self): pass - def close(self): pass + def __init__(self, *args, **kwargs): + pass -#------------------------------------------------------------------------- + def set_pass(self, *args): + pass + + def step(self): + pass + + def close(self): + pass + + +# ------------------------------------------------------------------------- # # Low Level repair # -#------------------------------------------------------------------------- +# ------------------------------------------------------------------------- def cross_table_duplicates(db, uistate): """ Function to find the presence of identical handles that occur in different @@ -110,8 +122,8 @@ def cross_table_duplicates(db, uistate): total_nr_handles = 0 all_handles = set([]) for the_map in [db.person_map, db.family_map, db.event_map, db.place_map, - db.source_map, db.citation_map, db.media_map, db.repository_map, - db.note_map]: + db.source_map, db.citation_map, db.media_map, + db.repository_map, db.note_map]: handle_list = list(the_map.keys()) total_nr_handles += len(handle_list) all_handles.update(handle_list) @@ -121,15 +133,16 @@ def cross_table_duplicates(db, uistate): if num_errors == 0: logging.info(' OK: No cross table duplicates') else: - logging.warning(' FAIL: Found %d cross table duplicates' % - num_errors) + logging.warning(' FAIL: Found %d cross table duplicates', + num_errors) return total_nr_handles > len(all_handles) -#------------------------------------------------------------------------- + +# ------------------------------------------------------------------------- # # runTool # -#------------------------------------------------------------------------- +# ------------------------------------------------------------------------- class Check(tool.BatchTool): def __init__(self, dbstate, user, options_class, name, callback=None): uistate = user.uistate @@ -155,10 +168,13 @@ class Check(tool.BatchTool): if self.db.__class__.__name__ == 'DbBsddb': if cross_table_duplicates(self.db, uistate): Report(uistate, _( - "Your Family Tree contains cross table duplicate handles.\n " + "Your Family Tree contains cross table duplicate handles." + "\n " "This is bad and can be fixed by making a backup of your\n" - "Family Tree and importing that backup in an empty family\n" - "tree. The rest of the checking is skipped, the Check and\n" + "Family Tree and importing that backup in an empty family" + "\n" + "tree. The rest of the checking is skipped, the Check and" + "\n" "Repair tool should be run anew on this new Family Tree."), cli) return @@ -208,11 +224,12 @@ class Check(tool.BatchTool): if errs: Report(uistate, checker.text.getvalue(), cli) -#------------------------------------------------------------------------- + +# ------------------------------------------------------------------------- # # # -#------------------------------------------------------------------------- +# ------------------------------------------------------------------------- class CheckIntegrity: def __init__(self, dbstate, uistate, trans): @@ -248,21 +265,22 @@ class CheckIntegrity: self.empty_objects = defaultdict(list) self.replaced_sourceref = [] self.place_errors = 0 + self.text = StringIO() self.last_img_dir = config.get('behavior.addmedia-image-dir') self.progress = ProgressMeter(_('Checking Database'), '', parent=self.parent_window) - self.explanation = Note(_('Objects referenced by this note ' - 'were referenced but missing so that is why they have been created ' + self.explanation = Note(_( + 'Objects referenced by this note were referenced but ' + 'missing so that is why they have been created ' 'when you ran Check and Repair on %s.') % - time.strftime('%x %X', time.localtime())) + time.strftime('%x %X', time.localtime())) self.explanation.set_handle(create_id()) def family_errors(self): return (len(self.broken_parent_links) + - len(self.broken_links) + - len(self.empty_family) + - len(self.duplicate_links) - ) + len(self.broken_links) + + len(self.empty_family) + + len(self.duplicate_links)) def cleanup_deleted_name_formats(self): """ @@ -270,14 +288,15 @@ class CheckIntegrity: When user deletes custom name format those are not removed only marked as "inactive". This method does the cleanup of the name format table, - as well as fixes the display_as, sort_as values for each Name in the db. + as well as fixes the display_as, sort_as values for each Name in the + db. """ self.progress.set_pass(_('Looking for invalid name format references'), self.db.get_number_of_people()) logging.info('Looking for invalid name format references') - deleted_name_formats = [number for (number, name, fmt_str,act) + deleted_name_formats = [number for (number, name, dummy, act) in self.db.name_formats if not act] # remove the invalid references from all Name objects @@ -318,7 +337,7 @@ class CheckIntegrity: for number in deleted_name_formats: _nd.del_name_format(number) self.db.name_formats = _nd.get_name_format(only_custom=True, - only_active=False) + only_active=False) if len(self.removed_name_format) == 0: logging.info(' OK: no invalid name formats found found') @@ -333,16 +352,16 @@ class CheckIntegrity: for bhandle in self.db.person_map.keys(): handle = bhandle.decode('utf-8') value = self.db.person_map[bhandle] - p = Person(value) - splist = p.get_family_handle_list() + pers = Person(value) + splist = pers.get_family_handle_list() if len(splist) != len(set(splist)): new_list = [] for value in splist: if value not in new_list: new_list.append(value) self.duplicate_links.append((handle, value)) - p.set_family_handle_list(new_list) - self.db.commit_person(p, self.trans) + pers.set_family_handle_list(new_list) + self.db.commit_person(pers, self.trans) self.progress.step() if previous_errors == len(self.duplicate_links): @@ -361,13 +380,13 @@ class CheckIntegrity: if not isinstance(data[2], str): obj.path = obj.path.decode('utf-8') logging.warning(' FAIL: encoding error on media object ' - '"%(gid)s" path "%(path)s"' % - {'gid' : obj.gramps_id, 'path' : obj.path}) + '"%(gid)s" path "%(path)s"', + {'gid': obj.gramps_id, 'path': obj.path}) if not isinstance(data[4], str): obj.desc = obj.desc.decode('utf-8') logging.warning(' FAIL: encoding error on media object ' - '"%(gid)s" description "%(desc)s"' % - {'gid' : obj.gramps_id, 'desc' : obj.desc}) + '"%(gid)s" description "%(desc)s"', + {'gid': obj.gramps_id, 'desc': obj.desc}) self.db.commit_media(obj, self.trans) error_count += 1 # Once we are here, fix the mime string if not str @@ -382,8 +401,8 @@ class CheckIntegrity: obj.mime = "" self.db.commit_media(obj, self.trans) logging.warning(' FAIL: encoding error on media object ' - '"%(desc)s" mime "%(mime)s"' % - {'desc' : obj.desc, 'mime' : obj.mime}) + '"%(desc)s" mime "%(mime)s"', + {'desc': obj.desc, 'mime': obj.mime}) error_count += 1 self.progress.step() if error_count == 0: @@ -401,8 +420,8 @@ class CheckIntegrity: old_text = str(stext) new_text = old_text.translate(strip_dict) if old_text != new_text: - logging.warning(' FAIL: control characters found in note "%s"' % - self.db.note_map[bhandle][1]) + logging.warning(' FAIL: control characters found in note' + ' "%s"', self.db.note_map[bhandle][1]) error_count += 1 # Commit only if ctrl char found. note.set_styledtext(StyledText(text=new_text, @@ -469,11 +488,12 @@ class CheckIntegrity: # "Broken6" family.set_father_handle(None) self.db.commit_family(family, self.trans) - self.broken_parent_links.append((father_handle, family_handle)) + self.broken_parent_links.append((father_handle, + family_handle)) logging.warning(" FAIL: family '%(fam_gid)s' " - "father handle '%(hand)s' does not exist" % - {'fam_gid' : family.gramps_id, - 'hand' : father_handle}) + "father handle '%(hand)s' does not exist", + {'fam_gid': family.gramps_id, + 'hand': father_handle}) father_handle = None if mother_handle: try: @@ -485,11 +505,12 @@ class CheckIntegrity: # "Broken7" family.set_mother_handle(None) self.db.commit_family(family, self.trans) - self.broken_parent_links.append((mother_handle, family_handle)) + self.broken_parent_links.append((mother_handle, + family_handle)) logging.warning(" FAIL: family '%(fam_gid)s' " - "mother handle '%(hand)s' does not exist" % - {'fam_gid' : family.gramps_id, - 'hand' : mother_handle}) + "mother handle '%(hand)s' does not exist", + {'fam_gid': family.gramps_id, + 'hand': mother_handle}) mother_handle = None if father_handle and father and \ @@ -501,9 +522,9 @@ class CheckIntegrity: father.add_family_handle(family_handle) self.db.commit_person(father, self.trans) logging.warning(" FAIL: family '%(fam_gid)s' father " - "'%(hand)s' does not refer back to the family" % - {'fam_gid' : family.gramps_id, - 'hand' : father_handle}) + "'%(hand)s' does not refer back to the family", + {'fam_gid': family.gramps_id, + 'hand': father_handle}) if mother_handle and mother and \ family_handle not in mother.get_family_handle_list(): @@ -514,9 +535,9 @@ class CheckIntegrity: mother.add_family_handle(family_handle) self.db.commit_person(mother, self.trans) logging.warning(" FAIL: family '%(fam_gid)s' mother " - "'%(hand)s' does not refer back to the family" % - {'fam_gid' : family.gramps_id, - 'hand' : mother_handle}) + "'%(hand)s' does not refer back to the family", + {'fam_gid': family.gramps_id, + 'hand': mother_handle}) for child_ref in family.get_child_ref_list(): child_handle = child_ref.ref @@ -528,9 +549,10 @@ class CheckIntegrity: # This is tested by TestcaseGenerator where the father # is "Broken20" logging.warning(" FAIL: family '%(fam_gid)s' child " - "'%(hand)s' does not exist in the database" % - {'fam_gid' : family.gramps_id, - 'hand' : child_handle}) + "'%(hand)s' does not exist in the " + "database", + {'fam_gid': family.gramps_id, + 'hand': child_handle}) family.remove_child_ref(child_ref) self.db.commit_family(family, self.trans) self.broken_links.append((child_handle, family_handle)) @@ -542,9 +564,9 @@ class CheckIntegrity: # is "Broken19" logging.warning(" FAIL: family '%(fam_gid)s' " "child '%(child_gid)s' is one of the " - "parents" % - {'fam_gid' : family.gramps_id, - 'child_gid' : child.gramps_id}) + "parents", + {'fam_gid': family.gramps_id, + 'child_gid': child.gramps_id}) family.remove_child_ref(child_ref) self.db.commit_family(family, self.trans) self.broken_links.append((child_handle, family_handle)) @@ -552,15 +574,16 @@ class CheckIntegrity: if family_handle == child.get_main_parents_family_handle(): continue if family_handle not in \ - child.get_parent_family_handle_list(): + child.get_parent_family_handle_list(): # The referenced child has no reference to the family # This is tested by TestcaseGenerator where the father # is "Broken8" - logging.warning(" FAIL: family '%(fam_gid)s' " - "child '%(child_gid)s' has no reference" - " to the family. Reference added" % - {'fam_gid' : family.gramps_id, - 'child_gid' : child.gramps_id}) + logging.warning( + " FAIL: family '%(fam_gid)s' " + "child '%(child_gid)s' has no reference" + " to the family. Reference added", + {'fam_gid': family.gramps_id, + 'child_gid': child.gramps_id}) child.add_parent_family_handle(family_handle) self.db.commit_person(child, self.trans) @@ -609,9 +632,9 @@ class CheckIntegrity: # is "Broken9" logging.warning(" FAIL: family '%(fam_gid)s' person " "'%(pers_gid)s' is not a child in the " - "referenced parent family" % - {'fam_gid' : family.gramps_id, - 'pers_gid' :person.gramps_id}) + "referenced parent family", + {'fam_gid': family.gramps_id, + 'pers_gid': person.gramps_id}) person.remove_parent_family_handle(par_family_handle) self.db.commit_person(person, self.trans) self.broken_links.append((person_handle, family_handle)) @@ -622,11 +645,11 @@ class CheckIntegrity: # The referenced family does not exist in database # This is tested by TestcaseGenerator where the father # is "Broken20" - logging.warning(" FAIL: person '%(pers_gid)s' refers to " - "family '%(hand)s' which is not in the " - "database" % - {'pers_gid' : person.gramps_id, - 'hand' : family_handle}) + logging.warning(" FAIL: person '%(pers_gid)s' refers " + "to family '%(hand)s' which is not in the " + "database", + {'pers_gid': person.gramps_id, + 'hand': family_handle}) person.remove_family_handle(family_handle) self.db.commit_person(person, self.trans) self.broken_links.append((person_handle, family_handle)) @@ -641,99 +664,103 @@ class CheckIntegrity: # where the mother is "Broken3" and the family misses the link # to the mother logging.warning(" FAIL: family '%(fam_gid)s' person " - "'%(pers_gid)s' is not member of the referenced" - " family" % - {'fam_gid' : family.gramps_id, - 'pers_gid' : person.gramps_id}) + "'%(pers_gid)s' is not member of the " + "referenced family", + {'fam_gid': family.gramps_id, + 'pers_gid': person.gramps_id}) person.remove_family_handle(family_handle) self.db.commit_person(person, self.trans) self.broken_links.append((person_handle, family_handle)) self.progress.step() - if previous_errors == len(self.broken_parent_links + self.broken_links): + if previous_errors == len(self.broken_parent_links + + self.broken_links): logging.info(' OK: no broken family links found') - def cleanup_missing_photos(self, cl=0): + def cleanup_missing_photos(self, cli=0): self.progress.set_pass(_('Looking for unused objects'), len(self.db.get_media_handles())) logging.info('Looking for missing photos') missmedia_action = 0 - #------------------------------------------------------------------------- + + # --------------------------------------------------------------------- def remove_clicked(): # File is lost => remove all references and the object itself for handle in self.db.get_person_handles(sort_handles=False): person = self.db.get_person_from_handle(handle) - if person.has_media_reference(ObjectId): - person.remove_media_references([ObjectId]) + if person.has_media_reference(objectid): + person.remove_media_references([objectid]) self.db.commit_person(person, self.trans) for handle in self.db.get_family_handles(): family = self.db.get_family_from_handle(handle) - if family.has_media_reference(ObjectId): - family.remove_media_references([ObjectId]) + if family.has_media_reference(objectid): + family.remove_media_references([objectid]) self.db.commit_family(family, self.trans) for handle in self.db.get_event_handles(): event = self.db.get_event_from_handle(handle) - if event.has_media_reference(ObjectId): - event.remove_media_references([ObjectId]) + if event.has_media_reference(objectid): + event.remove_media_references([objectid]) self.db.commit_event(event, self.trans) for handle in self.db.get_source_handles(): source = self.db.get_source_from_handle(handle) - if source.has_media_reference(ObjectId): - source.remove_media_references([ObjectId]) + if source.has_media_reference(objectid): + source.remove_media_references([objectid]) self.db.commit_source(source, self.trans) for handle in self.db.get_citation_handles(): citation = self.db.get_citation_from_handle(handle) - if citation.has_media_reference(ObjectId): - citation.remove_media_references([ObjectId]) + if citation.has_media_reference(objectid): + citation.remove_media_references([objectid]) self.db.commit_citation(citation, self.trans) for handle in self.db.get_place_handles(): place = self.db.get_place_from_handle(handle) - if place.has_media_reference(ObjectId): - place.remove_media_references([ObjectId]) + if place.has_media_reference(objectid): + place.remove_media_references([objectid]) self.db.commit_place(place, self.trans) - self.removed_photo.append(ObjectId) - self.db.remove_media(ObjectId,self.trans) + self.removed_photo.append(objectid) + self.db.remove_media(objectid, self.trans) logging.warning(' FAIL: media object and all references to ' 'it removed') def leave_clicked(): - self.bad_photo.append(ObjectId) + self.bad_photo.append(objectid) logging.warning(' FAIL: references to missing file kept') def select_clicked(): # File is lost => select a file to replace the lost one - def fs_close_window(obj): - self.bad_photo.append(ObjectId) - logging.warning(' FAIL: references to missing file kept') + def fs_close_window(dummy): + self.bad_photo.append(objectid) + logging.warning(' FAIL: references to missing file ' + 'kept') def fs_ok_clicked(obj): name = fs_top.get_filename() if os.path.isfile(name): - obj = self.db.get_media_from_handle(ObjectId) + obj = self.db.get_media_from_handle(objectid) obj.set_path(name) self.db.commit_media(obj, self.trans) - self.replaced_photo.append(ObjectId) + self.replaced_photo.append(objectid) self.last_img_dir = os.path.dirname(name) logging.warning(' FAIL: media object reselected to ' - '"%s"' % name) + '"%s"', name) else: - self.bad_photo.append(ObjectId) - logging.warning(' FAIL: references to missing file kept') + self.bad_photo.append(objectid) + logging.warning(' FAIL: references to missing file ' + 'kept') - fs_top = Gtk.FileChooserDialog("%s - Gramps" % _("Select file"), - parent=self.parent_window, - buttons=(_('_Cancel'), Gtk.ResponseType.CANCEL, - _('_OK'), Gtk.ResponseType.OK) - ) + fs_top = Gtk.FileChooserDialog( + "%s - Gramps" % _("Select file"), + parent=self.parent_window, + buttons=(_('_Cancel'), Gtk.ResponseType.CANCEL, + _('_OK'), Gtk.ResponseType.OK)) fs_top.set_current_folder(self.last_img_dir) response = fs_top.run() if response == Gtk.ResponseType.OK: @@ -742,25 +769,26 @@ class CheckIntegrity: fs_close_window(fs_top) fs_top.destroy() - #------------------------------------------------------------------------- + # -------------------------------------------------------------------- - for bObjectId in self.db.get_media_handles(): - ObjectId = bObjectId.decode('utf-8') - obj = self.db.get_media_from_handle(ObjectId) + for bobjectid in self.db.get_media_handles(): + objectid = bobjectid.decode('utf-8') + obj = self.db.get_media_from_handle(objectid) photo_name = media_path_full(self.db, obj.get_path()) photo_desc = obj.get_description() - if photo_name is not None and photo_name != "" and not find_file(photo_name): - if cl: - logging.warning(" FAIL: media file %s was not found." % + if photo_name is not None and photo_name != "" \ + and not find_file(photo_name): + if cli: + logging.warning(" FAIL: media file %s was not found.", photo_name) - self.bad_photo.append(ObjectId) + self.bad_photo.append(objectid) else: if missmedia_action == 0: logging.warning(' FAIL: media object "%(desc)s" ' 'reference to missing file "%(name)s" ' - 'found' % - {'desc' : photo_desc, - 'name' : photo_name}) + 'found', + {'desc': photo_desc, + 'name': photo_name}) mmd = MissingMediaDialog( _("Media object could not be found"), _("The file:\n%(file_name)s\nis referenced in " @@ -770,47 +798,47 @@ class CheckIntegrity: "You may choose to either remove the " "reference from the database,\n" "keep the reference to the missing file, " - "or select a new file." - ) % {'file_name' : '%s' % photo_name}, + "or select a new file.") + % {'file_name': '%s' % photo_name}, remove_clicked, leave_clicked, select_clicked, parent=self.uistate.window) missmedia_action = mmd.default_action elif missmedia_action == 1: logging.warning(' FAIL: media object "%(desc)s" ' 'reference to missing file "%(name)s" ' - 'found' % - {'desc' : photo_desc, - 'name' : photo_name}) + 'found', + {'desc': photo_desc, + 'name': photo_name}) remove_clicked() elif missmedia_action == 2: logging.warning(' FAIL: media object "%(desc)s" ' 'reference to missing file "%(name)s" ' - 'found' % - {'desc' : photo_desc, - 'name' : photo_name}) + 'found', + {'desc': photo_desc, + 'name': photo_name}) leave_clicked() elif missmedia_action == 3: logging.warning(' FAIL: media object "%(desc)s" ' 'reference to missing file "%(name)s" ' - 'found' % - {'desc' : photo_desc, - 'name' : photo_name}) + 'found', + {'desc': photo_desc, + 'name': photo_name}) select_clicked() self.progress.step() if len(self.bad_photo + self.removed_photo) == 0: logging.info(' OK: no missing photos found') def cleanup_empty_objects(self): - #the position of the change column in the primary objects + # the position of the change column in the primary objects CHANGE_PERSON = 17 CHANGE_FAMILY = 12 - CHANGE_EVENT = 10 + CHANGE_EVENT = 10 CHANGE_SOURCE = 8 CHANGE_CITATION = 9 - CHANGE_PLACE = 11 - CHANGE_MEDIA = 8 - CHANGE_REPOS = 7 - CHANGE_NOTE = 5 + CHANGE_PLACE = 11 + CHANGE_MEDIA = 8 + CHANGE_REPOS = 7 + CHANGE_NOTE = 5 empty_person_data = Person().serialize() empty_family_data = Family().serialize() @@ -823,11 +851,12 @@ class CheckIntegrity: empty_note_data = Note().serialize() _db = self.db + def _empty(empty, flag): ''' Closure for dispatch table, below ''' - def _f(value): + def _fx(value): return self._check_empty(value, empty, flag) - return _f + return _fx table = ( @@ -842,82 +871,73 @@ class CheckIntegrity: # 6. function to remove the object, if empty ('persons', - _db.get_person_from_handle, - _db.get_person_cursor, - _db.get_number_of_people, - _('Looking for empty people records'), - _empty(empty_person_data, CHANGE_PERSON), - _db.remove_person, - ), + _db.get_person_from_handle, + _db.get_person_cursor, + _db.get_number_of_people, + _('Looking for empty people records'), + _empty(empty_person_data, CHANGE_PERSON), + _db.remove_person), ('families', - _db.get_family_from_handle, - _db.get_family_cursor, - _db.get_number_of_families, - _('Looking for empty family records'), - _empty(empty_family_data, CHANGE_FAMILY), - _db.remove_family, - ), + _db.get_family_from_handle, + _db.get_family_cursor, + _db.get_number_of_families, + _('Looking for empty family records'), + _empty(empty_family_data, CHANGE_FAMILY), + _db.remove_family), ('events', - _db.get_event_from_handle, - _db.get_event_cursor, - _db.get_number_of_events, - _('Looking for empty event records'), - _empty(empty_event_data, CHANGE_EVENT), - _db.remove_event, - ), + _db.get_event_from_handle, + _db.get_event_cursor, + _db.get_number_of_events, + _('Looking for empty event records'), + _empty(empty_event_data, CHANGE_EVENT), + _db.remove_event), ('sources', - _db.get_source_from_handle, - _db.get_source_cursor, - _db.get_number_of_sources, - _('Looking for empty source records'), - _empty(empty_source_data, CHANGE_SOURCE), - _db.remove_source, - ), + _db.get_source_from_handle, + _db.get_source_cursor, + _db.get_number_of_sources, + _('Looking for empty source records'), + _empty(empty_source_data, CHANGE_SOURCE), + _db.remove_source), ('citations', - _db.get_citation_from_handle, - _db.get_citation_cursor, - _db.get_number_of_citations, - _('Looking for empty citation records'), - _empty(empty_citation_data, CHANGE_CITATION), - _db.remove_citation, - ), + _db.get_citation_from_handle, + _db.get_citation_cursor, + _db.get_number_of_citations, + _('Looking for empty citation records'), + _empty(empty_citation_data, CHANGE_CITATION), + _db.remove_citation), ('places', - _db.get_place_from_handle, - _db.get_place_cursor, - _db.get_number_of_places, - _('Looking for empty place records'), - _empty(empty_place_data, CHANGE_PLACE), - _db.remove_place, - ), + _db.get_place_from_handle, + _db.get_place_cursor, + _db.get_number_of_places, + _('Looking for empty place records'), + _empty(empty_place_data, CHANGE_PLACE), + _db.remove_place), ('media', - _db.get_media_from_handle, - _db.get_media_cursor, - _db.get_number_of_media, - _('Looking for empty media records'), - _empty(empty_media_data, CHANGE_MEDIA), - _db.remove_media, - ), + _db.get_media_from_handle, + _db.get_media_cursor, + _db.get_number_of_media, + _('Looking for empty media records'), + _empty(empty_media_data, CHANGE_MEDIA), + _db.remove_media), ('repos', - _db.get_repository_from_handle, - _db.get_repository_cursor, - _db.get_number_of_repositories, - _('Looking for empty repository records'), - _empty(empty_repos_data, CHANGE_REPOS), - _db.remove_repository, - ), + _db.get_repository_from_handle, + _db.get_repository_cursor, + _db.get_number_of_repositories, + _('Looking for empty repository records'), + _empty(empty_repos_data, CHANGE_REPOS), + _db.remove_repository), ('notes', - _db.get_note_from_handle, - _db.get_note_cursor, - _db.get_number_of_notes, - _('Looking for empty note records'), - _empty(empty_note_data, CHANGE_NOTE), - _db.remove_note, - ), + _db.get_note_from_handle, + _db.get_note_cursor, + _db.get_number_of_notes, + _('Looking for empty note records'), + _empty(empty_note_data, CHANGE_NOTE), + _db.remove_note), ) # Now, iterate over the table, dispatching the functions - for (the_type, get_func, cursor_func, total_func, + for (the_type, dummy, cursor_func, total_func, text, check_func, remove_func) in table: with cursor_func() as cursor: @@ -931,27 +951,26 @@ class CheckIntegrity: # we cannot remove here as that would destroy cursor # so save the handles for later removal logging.warning(' FAIL: empty %(type)s record with ' - 'handle "%(hand)s" was found' % - {'type' : the_type, 'hand' : handle}) + 'handle "%(hand)s" was found', + {'type': the_type, 'hand': handle}) self.empty_objects[the_type].append(handle) - #now remove + # now remove for handle in self.empty_objects[the_type]: remove_func(handle, self.trans) if len(self.empty_objects[the_type]) == 0: - logging.info(' OK: no empty %s found' % the_type) + logging.info(' OK: no empty %s found', the_type) def _check_empty(self, data, empty_data, changepos): """compare the data with the data of an empty object change, handle and gramps_id are not compared """ if changepos is not None: return (data[2:changepos] == empty_data[2:changepos] and - data[changepos+1:] == empty_data[changepos+1:] - ) - else : + data[changepos + 1:] == empty_data[changepos + 1:]) + else: return data[2:] == empty_data[2:] - def cleanup_empty_families(self, automatic): + def cleanup_empty_families(self, dummy): fhandle_list = self.db.get_family_handles() @@ -969,7 +988,7 @@ class CheckIntegrity: mother_handle = family.get_mother_handle() if not father_handle and not mother_handle and \ - len(family.get_child_ref_list()) == 0: + len(family.get_child_ref_list()) == 0: self.empty_family.append(family_id) self.delete_empty_family(family_handle) @@ -1003,23 +1022,24 @@ class CheckIntegrity: father_handle = family.get_father_handle() if father_handle: - fgender = self.db.get_person_from_handle(father_handle - ).get_gender() + fgender = self.db.get_person_from_handle( + father_handle).get_gender() else: fgender = None mother_handle = family.get_mother_handle() if mother_handle: - mgender = self.db.get_person_from_handle(mother_handle - ).get_gender() + mgender = self.db.get_person_from_handle( + mother_handle).get_gender() else: mgender = None - if (fgender == Person.FEMALE - or mgender == Person.MALE) and fgender != mgender: + if (fgender == Person.FEMALE or + mgender == Person.MALE) and fgender != mgender: # swap. note: (at most) one handle may be None - logging.warning(' FAIL: the family "%s" has a father=female or ' - ' mother=male in a different sex family' % family.gramps_id) + logging.warning(' FAIL: the family "%s" has a father=female' + ' or mother=male in a different sex family', + family.gramps_id) family.set_father_handle(mother_handle) family.set_mother_handle(father_handle) self.db.commit_family(family, self.trans) @@ -1029,9 +1049,10 @@ class CheckIntegrity: logging.info(' OK: no broken parent relationships found') def check_events(self): + '''Looking for event problems''' self.progress.set_pass(_('Looking for event problems'), - self.db.get_number_of_people() - +self.db.get_number_of_families()) + self.db.get_number_of_people() + + self.db.get_number_of_families()) logging.info('Looking for event problems') for bkey in self.db.get_person_handles(sort_handles=False): @@ -1054,23 +1075,23 @@ class CheckIntegrity: # does not exist in the database # This is tested by TestcaseGenerator person "Broken11" make_unknown(birth_handle, self.explanation.handle, - self.class_event, self.commit_event, self.trans, - type=EventType.BIRTH) + self.class_event, self.commit_event, + self.trans, type=EventType.BIRTH) logging.warning(' FAIL: the person "%(gid)s" refers to ' 'a birth event "%(hand)s" which does not ' - 'exist in the database' % - {'gid' : person.gramps_id, - 'hand' : birth_handle}) + 'exist in the database', + {'gid': person.gramps_id, + 'hand': birth_handle}) self.invalid_events.add(key) else: if int(birth.get_type()) != EventType.BIRTH: # Birth event was not of the type "Birth" # This is tested by TestcaseGenerator person "Broken14" - logging.warning(' FAIL: the person "%(gid)s" refers ' - 'to a birth event which is of type ' - '"%(type)s" instead of Birth' % - {'gid' : person.gramps_id, - 'type' : int(birth.get_type())}) + logging.warning(' FAIL: the person "%(gid)s" refers' + ' to a birth event which is of type ' + '"%(type)s" instead of Birth', + {'gid': person.gramps_id, + 'type': int(birth.get_type())}) birth.set_type(EventType(EventType.BIRTH)) self.db.commit_event(birth, self.trans) self.invalid_birth_events.add(key) @@ -1094,22 +1115,23 @@ class CheckIntegrity: # This is tested by TestcaseGenerator person "Broken12" logging.warning(' FAIL: the person "%(gid)s" refers to ' 'a death event "%(hand)s" which does not ' - 'exist in the database' % - {'gid' : person.gramps_id, - 'hand' : death_handle}) + 'exist in the database', + {'gid': person.gramps_id, + 'hand': death_handle}) make_unknown(death_handle, self.explanation.handle, - self.class_event, self.commit_event, self.trans, - type=EventType.DEATH) + self.class_event, self.commit_event, + self.trans, type=EventType.DEATH) self.invalid_events.add(key) else: if int(death.get_type()) != EventType.DEATH: # Death event was not of the type "Death" # This is tested by TestcaseGenerator person "Broken15" - logging.warning(' FAIL: the person "%(gid)s" refers ' - 'to a death event which is of type ' - '"%(type)s" instead of Death' % - {'gid' : person.gramps_id, - 'type' : int(death.get_type())}) + logging.warning( + ' FAIL: the person "%(gid)s" refers to a death ' + 'event which is of type "%(type)s" instead of ' + 'Death', + {'gid': person.gramps_id, + 'type': int(death.get_type())}) death.set_type(EventType(EventType.DEATH)) self.db.commit_event(death, self.trans) self.invalid_death_events.add(key) @@ -1127,30 +1149,30 @@ class CheckIntegrity: event_ref.ref = create_id() event_handle = event_ref.ref try: - event = self.db.get_event_from_handle(event_handle) + self.db.get_event_from_handle(event_handle) except HandleError: # The event referenced by the person # does not exist in the database - #TODO: There is no better way? + # TODO: There is no better way? # This is tested by TestcaseGenerator person "Broken11" # This is tested by TestcaseGenerator person "Broken12" # This is tested by TestcaseGenerator person "Broken13" - logging.warning(' FAIL: the person "%(gid)s" refers ' - 'to an event "%(hand)s" which does not ' - 'exist in the database' % - { 'gid' : person.gramps_id, - 'hand' : event_handle}) - make_unknown(event_handle, - self.explanation.handle, self.class_event, - self.commit_event, self.trans) + logging.warning( + ' FAIL: the person "%(gid)s" refers to an event' + ' "%(hand)s" which does not exist in the database', + {'gid': person.gramps_id, + 'hand': event_handle}) + make_unknown(event_handle, self.explanation.handle, + self.class_event, + self.commit_event, self.trans) self.invalid_events.add(key) if none_handle: person.set_event_ref_list(newlist) self.db.commit_person(person, self.trans) elif not isinstance(person.get_event_ref_list(), list): # event_list is None or other garbage - logging.warning(' FAIL: the person "%s" has an event ref list' - ' which is invalid' % (person.gramps_id)) + logging.warning(' FAIL: the person "%s" has an event ref ' + 'list which is invalid', (person.gramps_id)) person.set_event_ref_list([]) self.db.commit_person(person, self.trans) self.invalid_events.add(key) @@ -1169,34 +1191,36 @@ class CheckIntegrity: event_ref.ref = create_id() event_handle = event_ref.ref try: - event = self.db.get_event_from_handle(event_handle) + self.db.get_event_from_handle(event_handle) except HandleError: # The event referenced by the family # does not exist in the database - logging.warning(' FAIL: the family "%(gid)s" refers ' - 'to an event "%(hand)s" which does not ' - 'exist in the database' % - {'gid' : family.gramps_id, - 'hand' : event_handle}) + logging.warning(' FAIL: the family "%(gid)s" refers' + ' to an event "%(hand)s" which does ' + 'not exist in the database', + {'gid': family.gramps_id, + 'hand': event_handle}) make_unknown(event_handle, self.explanation.handle, - self.class_event, self.commit_event, self.trans) + self.class_event, self.commit_event, + self.trans) self.invalid_events.add(key) if none_handle: family.set_event_ref_list(newlist) self.db.commit_family(family, self.trans) elif not isinstance(family.get_event_ref_list(), list): # event_list is None or other garbage - logging.warning(' FAIL: the family "%s" has an event ref list' - ' which is invalid' % (family.gramps_id)) + logging.warning(' FAIL: the family "%s" has an event ref ' + 'list which is invalid', (family.gramps_id)) family.set_event_ref_list([]) self.db.commit_family(family, self.trans) self.invalid_events.add(key) - if len (self.invalid_birth_events) + len(self.invalid_death_events) +\ + if len(self.invalid_birth_events) + len(self.invalid_death_events) + \ len(self.invalid_events) == 0: logging.info(' OK: no event problems found') def check_person_references(self): + '''Looking for person reference problems''' plist = self.db.get_person_handles() self.progress.set_pass(_('Looking for person reference problems'), @@ -1215,20 +1239,22 @@ class CheckIntegrity: none_handle = True pref.ref = create_id() try: - p = self.db.get_person_from_handle( pref.ref) + self.db.get_person_from_handle(pref.ref) except HandleError: # The referenced person does not exist in the database make_unknown(pref.ref, self.explanation.handle, - self.class_person, self.commit_person, self.trans) + self.class_person, self.commit_person, + self.trans) self.invalid_person_references.add(key) if none_handle: person.set_person_ref_list(newlist) self.db.commit_person(person, self.trans) - if len (self.invalid_person_references) == 0: + if len(self.invalid_person_references) == 0: logging.info(' OK: no event problems found') def check_family_references(self): + '''Looking for family reference problems''' plist = self.db.get_person_handles() self.progress.set_pass(_('Looking for family reference problems'), @@ -1243,18 +1269,19 @@ class CheckIntegrity: family_handle = ordinance.get_family_handle() if family_handle: try: - family = self.db.get_family_from_handle(family_handle) + self.db.get_family_from_handle(family_handle) except HandleError: # The referenced family does not exist in the database - make_unknown(family_handle, - self.explanation.handle, self.class_family, - self.commit_family, self.trans, db=self.db) + make_unknown(family_handle, self.explanation.handle, + self.class_family, self.commit_family, + self.trans, db=self.db) self.invalid_family_references.add(key) - if len (self.invalid_family_references) == 0: + if len(self.invalid_family_references) == 0: logging.info(' OK: no event problems found') def check_repo_references(self): + '''Looking for repository reference problems''' slist = self.db.get_source_handles() self.progress.set_pass(_('Looking for repository reference problems'), @@ -1273,26 +1300,28 @@ class CheckIntegrity: none_handle = True reporef.ref = create_id() try: - r = self.db.get_repository_from_handle(reporef.ref) + self.db.get_repository_from_handle(reporef.ref) except HandleError: # The referenced repository does not exist in the database make_unknown(reporef.ref, self.explanation.handle, - self.class_repo, self.commit_repo, self.trans) + self.class_repo, self.commit_repo, self.trans) self.invalid_repo_references.add(key) if none_handle: - source.set_reporef_list(newlist); + source.set_reporef_list(newlist) self.db.commit_source(source, self.trans) - if len (self.invalid_repo_references) == 0: + if len(self.invalid_repo_references) == 0: logging.info(' OK: no repository reference problems found') def check_place_references(self): + '''Looking for place reference problems''' plist = self.db.get_person_handles() flist = self.db.get_family_handles() elist = self.db.get_event_handles() llist = self.db.get_place_handles() - self.progress.set_pass(_('Looking for place reference problems'), - len(elist)+len(plist)+len(flist)+len(llist)) + self.progress.set_pass( + _('Looking for place reference problems'), + len(elist) + len(plist) + len(flist) + len(llist)) logging.info('Looking for place reference problems') for bkey in llist: @@ -1307,20 +1336,20 @@ class CheckIntegrity: none_handle = True placeref.ref = create_id() try: - parent_place = self.db.get_place_from_handle(placeref.ref) + self.db.get_place_from_handle(placeref.ref) except HandleError: # The referenced place does not exist in the database - make_unknown(placeref.ref, - self.explanation.handle, self.class_place, - self.commit_place, self.trans) + make_unknown(placeref.ref, self.explanation.handle, + self.class_place, self.commit_place, + self.trans) logging.warning(' FAIL: the place "%(gid)s" refers ' 'to a parent place "%(hand)s" which ' - 'does not exist in the database' % - {'gid' : place.gramps_id, - 'hand' : placeref.ref}) + 'does not exist in the database', + {'gid': place.gramps_id, + 'hand': placeref.ref}) self.invalid_place_references.add(key) if none_handle: - place.set_placeref_list(newlist); + place.set_placeref_list(newlist) self.db.commit_place(place, self.trans) # check persons -> the LdsOrd references a place @@ -1337,14 +1366,14 @@ class CheckIntegrity: # The referenced place does not exist in the database # This is tested by TestcaseGenerator person "Broken17" # This is tested by TestcaseGenerator person "Broken18" - make_unknown(place_handle, - self.explanation.handle, self.class_place, - self.commit_place, self.trans) - logging.warning(' FAIL: the person "%(gid)s" refers ' - 'to an LdsOrd place "%(hand)s" which ' - 'does not exist in the database' % - {'gid' : person.gramps_id, - 'hand' : place_handle}) + make_unknown(place_handle, self.explanation.handle, + self.class_place, self.commit_place, + self.trans) + logging.warning(' FAIL: the person "%(gid)s" refers' + ' to an LdsOrd place "%(hand)s" which ' + 'does not exist in the database', + {'gid': person.gramps_id, + 'hand': place_handle}) self.invalid_place_references.add(key) # check families -> the LdsOrd references a place for bkey in flist: @@ -1358,14 +1387,14 @@ class CheckIntegrity: place = self.db.get_place_from_handle(place_handle) except HandleError: # The referenced place does not exist in the database - make_unknown(place_handle, - self.explanation.handle, self.class_place, - self.commit_place, self.trans) - logging.warning(' FAIL: the family "%(gid)s" refers ' - 'to an LdsOrd place "%(hand)s" which ' - 'does not exist in the database' % - {'gid' : family.gramps_id, - 'hand' : place_handle}) + make_unknown(place_handle, self.explanation.handle, + self.class_place, self.commit_place, + self.trans) + logging.warning(' FAIL: the family "%(gid)s" refers' + ' to an LdsOrd place "%(hand)s" which ' + 'does not exist in the database', + {'gid': family.gramps_id, + 'hand': place_handle}) self.invalid_place_references.add(key) # check events for bkey in elist: @@ -1378,40 +1407,40 @@ class CheckIntegrity: place = self.db.get_place_from_handle(place_handle) except HandleError: # The referenced place does not exist in the database - make_unknown(place_handle, - self.explanation.handle, self.class_place, - self.commit_place, self.trans) + make_unknown(place_handle, self.explanation.handle, + self.class_place, self.commit_place, + self.trans) logging.warning(' FAIL: the event "%(gid)s" refers ' 'to an LdsOrd place "%(hand)s" which ' - 'does not exist in the database' % - {'gid' : event.gramps_id, - 'hand' : place_handle}) + 'does not exist in the database', + {'gid': event.gramps_id, + 'hand': place_handle}) self.invalid_place_references.add(key) - if len (self.invalid_place_references) == 0: + if len(self.invalid_place_references) == 0: logging.info(' OK: no place reference problems found') def check_citation_references(self): + '''Looking for citation reference problems''' known_handles = [key.decode('utf-8') for key in - self.db.get_citation_handles()] + self.db.get_citation_handles()] total = ( - self.db.get_number_of_people() + - self.db.get_number_of_families() + - self.db.get_number_of_events() + - self.db.get_number_of_places() + - self.db.get_number_of_citations() + - self.db.get_number_of_sources() + - self.db.get_number_of_media() + - self.db.get_number_of_repositories() - ) + self.db.get_number_of_people() + + self.db.get_number_of_families() + + self.db.get_number_of_events() + + self.db.get_number_of_places() + + self.db.get_number_of_citations() + + self.db.get_number_of_sources() + + self.db.get_number_of_media() + + self.db.get_number_of_repositories() + ) self.progress.set_pass(_('Looking for citation reference problems'), total) logging.info('Looking for citation reference problems') for bhandle in self.db.person_map.keys(): - handle = bhandle.decode('utf-8') self.progress.step() info = self.db.person_map[bhandle] person = Person() @@ -1428,7 +1457,6 @@ class CheckIntegrity: self.invalid_citation_references.add(item[1]) for bhandle in self.db.family_map.keys(): - handle = bhandle.decode('utf-8') self.progress.step() info = self.db.family_map[bhandle] family = Family() @@ -1445,7 +1473,6 @@ class CheckIntegrity: self.invalid_citation_references.add(item[1]) for bhandle in self.db.place_map.keys(): - handle = bhandle.decode('utf-8') self.progress.step() info = self.db.place_map[bhandle] place = Place() @@ -1462,7 +1489,6 @@ class CheckIntegrity: self.invalid_citation_references.add(item[1]) for bhandle in self.db.citation_map.keys(): - handle = bhandle.decode('utf-8') self.progress.step() info = self.db.citation_map[bhandle] citation = Citation() @@ -1479,7 +1505,6 @@ class CheckIntegrity: self.invalid_citation_references.add(item[1]) for bhandle in self.db.repository_map.keys(): - handle = bhandle.decode('utf-8') self.progress.step() info = self.db.repository_map[bhandle] repository = Repository() @@ -1489,14 +1514,14 @@ class CheckIntegrity: if item[0] == 'Citation': if item[1] is None: new_handle = create_id() - repository.replace_citation_references(None, new_handle) + repository.replace_citation_references(None, + new_handle) self.db.commit_repository(repository, self.trans) self.invalid_citation_references.add(new_handle) elif item[1] not in known_handles: self.invalid_citation_references.add(item[1]) for bhandle in self.db.media_map.keys(): - handle = bhandle.decode('utf-8') self.progress.step() info = self.db.media_map[bhandle] obj = Media() @@ -1513,7 +1538,6 @@ class CheckIntegrity: self.invalid_citation_references.add(item[1]) for bhandle in self.db.event_map.keys(): - handle = bhandle.decode('utf-8') self.progress.step() info = self.db.event_map[bhandle] event = Event() @@ -1531,16 +1555,18 @@ class CheckIntegrity: for bad_handle in self.invalid_citation_references: created = make_unknown(bad_handle, self.explanation.handle, - self.class_citation, self.commit_citation, self.trans, - source_class_func=self.class_source, - source_commit_func=self.commit_source, - source_class_arg=create_id()) + self.class_citation, self.commit_citation, + self.trans, + source_class_func=self.class_source, + source_commit_func=self.commit_source, + source_class_arg=create_id()) self.invalid_source_references.add(created[0].handle) if len(self.invalid_citation_references) == 0: logging.info(' OK: no citation reference problems found') def check_source_references(self): + '''Looking for source reference problems''' clist = self.db.get_citation_handles() self.progress.set_pass(_('Looking for source reference problems'), len(clist)) @@ -1557,39 +1583,40 @@ class CheckIntegrity: self.db.commit_citation(citation, self.trans) if source_handle: try: - source = self.db.get_source_from_handle(source_handle) + self.db.get_source_from_handle(source_handle) except HandleError: # The referenced source does not exist in the database make_unknown(source_handle, self.explanation.handle, - self.class_source, self.commit_source, self.trans) + self.class_source, self.commit_source, + self.trans) logging.warning(' FAIL: the citation "%(gid)s" refers ' - 'to source "%(hand)s" which does not exist ' - 'in the database' % - {'gid' : citation.gramps_id, - 'hand' : source_handle}) + 'to source "%(hand)s" which does not exist' + ' in the database', + {'gid': citation.gramps_id, + 'hand': source_handle}) self.invalid_source_references.add(key) if len(self.invalid_source_references) == 0: logging.info(' OK: no source reference problems found') def check_media_references(self): + '''Looking for media object reference problems''' known_handles = [key.decode('utf-8') for key in - self.db.get_media_handles(False)] + self.db.get_media_handles(False)] total = ( - self.db.get_number_of_people() + - self.db.get_number_of_families() + - self.db.get_number_of_events() + - self.db.get_number_of_places() + - self.db.get_number_of_citations() + - self.db.get_number_of_sources() - ) + self.db.get_number_of_people() + + self.db.get_number_of_families() + + self.db.get_number_of_events() + + self.db.get_number_of_places() + + self.db.get_number_of_citations() + + self.db.get_number_of_sources() + ) - self.progress.set_pass(_('Looking for media object reference problems'), - total) + self.progress.set_pass(_('Looking for media object reference ' + 'problems'), total) logging.info('Looking for media object reference problems') for bhandle in self.db.person_map.keys(): - handle = bhandle.decode('utf-8') self.progress.step() info = self.db.person_map[bhandle] person = Person() @@ -1606,7 +1633,6 @@ class CheckIntegrity: self.invalid_media_references.add(item[1]) for bhandle in self.db.family_map.keys(): - handle = bhandle.decode('utf-8') self.progress.step() info = self.db.family_map[bhandle] family = Family() @@ -1623,7 +1649,6 @@ class CheckIntegrity: self.invalid_media_references.add(item[1]) for bhandle in self.db.place_map.keys(): - handle = bhandle.decode('utf-8') self.progress.step() info = self.db.place_map[bhandle] place = Place() @@ -1640,7 +1665,6 @@ class CheckIntegrity: self.invalid_media_references.add(item[1]) for bhandle in self.db.event_map.keys(): - handle = bhandle.decode('utf-8') self.progress.step() info = self.db.event_map[bhandle] event = Event() @@ -1657,7 +1681,6 @@ class CheckIntegrity: self.invalid_media_references.add(item[1]) for bhandle in self.db.citation_map.keys(): - handle = bhandle.decode('utf-8') self.progress.step() info = self.db.citation_map[bhandle] citation = Citation() @@ -1674,7 +1697,6 @@ class CheckIntegrity: self.invalid_media_references.add(item[1]) for bhandle in self.db.source_map.keys(): - handle = bhandle.decode('utf-8') self.progress.step() info = self.db.source_map[bhandle] source = Source() @@ -1691,48 +1713,45 @@ class CheckIntegrity: self.invalid_media_references.add(item[1]) for bad_handle in self.invalid_media_references: - make_unknown(bad_handle, self.explanation.handle, - self.class_media, self.commit_media, self.trans) + make_unknown(bad_handle, self.explanation.handle, self.class_media, + self.commit_media, self.trans) - if len (self.invalid_media_references) == 0: + if len(self.invalid_media_references) == 0: logging.info(' OK: no media reference problems found') def check_note_references(self): + '''Looking for note reference problems''' # Here I assume check note_references runs after all the next checks. missing_references = (len(self.invalid_person_references) + - len(self.invalid_family_references) + - len(self.invalid_birth_events) + - len(self.invalid_death_events) + - len(self.invalid_events) + - len(self.invalid_place_references) + - len(self.invalid_citation_references) + - len(self.invalid_source_references) + - len(self.invalid_repo_references) + - len(self.invalid_media_references)) + len(self.invalid_family_references) + + len(self.invalid_birth_events) + + len(self.invalid_death_events) + + len(self.invalid_events) + + len(self.invalid_place_references) + + len(self.invalid_citation_references) + + len(self.invalid_source_references) + + len(self.invalid_repo_references) + + len(self.invalid_media_references)) if missing_references: self.db.add_note(self.explanation, self.trans, set_gid=True) known_handles = [key.decode('utf-8') for key in - self.db.get_note_handles()] - bad_handles = [] + self.db.get_note_handles()] - total = ( - self.db.get_number_of_people() + - self.db.get_number_of_families() + - self.db.get_number_of_events() + - self.db.get_number_of_places() + - self.db.get_number_of_media() + - self.db.get_number_of_citations() + - self.db.get_number_of_sources() + - self.db.get_number_of_repositories() - ) + total = (self.db.get_number_of_people() + + self.db.get_number_of_families() + + self.db.get_number_of_events() + + self.db.get_number_of_places() + + self.db.get_number_of_media() + + self.db.get_number_of_citations() + + self.db.get_number_of_sources() + + self.db.get_number_of_repositories()) self.progress.set_pass(_('Looking for note reference problems'), total) logging.info('Looking for note reference problems') for bhandle in self.db.person_map.keys(): - handle = bhandle.decode('utf-8') self.progress.step() info = self.db.person_map[bhandle] person = Person() @@ -1749,7 +1768,6 @@ class CheckIntegrity: self.invalid_note_references.add(item[1]) for bhandle in self.db.family_map.keys(): - handle = bhandle.decode('utf-8') self.progress.step() info = self.db.family_map[bhandle] family = Family() @@ -1766,7 +1784,6 @@ class CheckIntegrity: self.invalid_note_references.add(item[1]) for bhandle in self.db.place_map.keys(): - handle = bhandle.decode('utf-8') self.progress.step() info = self.db.place_map[bhandle] place = Place() @@ -1783,7 +1800,6 @@ class CheckIntegrity: self.invalid_note_references.add(item[1]) for bhandle in self.db.citation_map.keys(): - handle = bhandle.decode('utf-8') self.progress.step() info = self.db.citation_map[bhandle] citation = Citation() @@ -1800,7 +1816,6 @@ class CheckIntegrity: self.invalid_note_references.add(item[1]) for bhandle in self.db.source_map.keys(): - handle = bhandle.decode('utf-8') self.progress.step() info = self.db.source_map[bhandle] source = Source() @@ -1817,7 +1832,6 @@ class CheckIntegrity: self.invalid_note_references.add(item[1]) for bhandle in self.db.media_map.keys(): - handle = bhandle.decode('utf-8') self.progress.step() info = self.db.media_map[bhandle] obj = Media() @@ -1834,7 +1848,6 @@ class CheckIntegrity: self.invalid_note_references.add(item[1]) for bhandle in self.db.event_map.keys(): - handle = bhandle.decode('utf-8') self.progress.step() info = self.db.event_map[bhandle] event = Event() @@ -1851,7 +1864,6 @@ class CheckIntegrity: self.invalid_note_references.add(item[1]) for bhandle in self.db.repository_map.keys(): - handle = bhandle.decode('utf-8') self.progress.step() info = self.db.repository_map[bhandle] repo = Repository() @@ -1869,21 +1881,22 @@ class CheckIntegrity: for bad_handle in self.invalid_note_references: make_unknown(bad_handle, self.explanation.handle, - self.class_note, self.commit_note, self.trans) + self.class_note, self.commit_note, self.trans) - if len (self.invalid_note_references) == 0: + if len(self.invalid_note_references) == 0: logging.info(' OK: no note reference problems found') else: if not missing_references: self.db.add_note(self.explanation, self.trans, set_gid=True) def check_checksum(self): + ''' fix media checksums ''' self.progress.set_pass(_('Updating checksums on media'), len(self.db.get_media_handles())) - for bObjectId in self.db.get_media_handles(): + for bobjectid in self.db.get_media_handles(): self.progress.step() - ObjectId = bObjectId.decode('utf-8') - obj = self.db.get_media_from_handle(ObjectId) + objectid = bobjectid.decode('utf-8') + obj = self.db.get_media_from_handle(objectid) full_path = media_path_full(self.db, obj.get_path()) new_checksum = create_checksum(full_path) if new_checksum != obj.checksum: @@ -1892,22 +1905,20 @@ class CheckIntegrity: self.db.commit_media(obj, self.trans) def check_tag_references(self): + '''Looking for tag reference problems''' known_handles = [key.decode('utf-8') for key in - self.db.get_tag_handles()] + self.db.get_tag_handles()] - total = ( - self.db.get_number_of_people() + - self.db.get_number_of_families() + - self.db.get_number_of_media() + - self.db.get_number_of_notes() - ) + total = (self.db.get_number_of_people() + + self.db.get_number_of_families() + + self.db.get_number_of_media() + + self.db.get_number_of_notes()) self.progress.set_pass(_('Looking for tag reference problems'), total) logging.info('Looking for tag reference problems') for bhandle in self.db.person_map.keys(): - handle = bhandle.decode('utf-8') self.progress.step() info = self.db.person_map[bhandle] person = Person() @@ -1924,7 +1935,6 @@ class CheckIntegrity: self.invalid_tag_references.add(item[1]) for bhandle in self.db.family_map.keys(): - handle = bhandle.decode('utf-8') self.progress.step() info = self.db.family_map[bhandle] family = Family() @@ -1941,7 +1951,6 @@ class CheckIntegrity: self.invalid_tag_references.add(item[1]) for bhandle in self.db.media_map.keys(): - handle = bhandle.decode('utf-8') self.progress.step() info = self.db.media_map[bhandle] obj = Media() @@ -1958,7 +1967,6 @@ class CheckIntegrity: self.invalid_tag_references.add(item[1]) for bhandle in self.db.note_map.keys(): - handle = bhandle.decode('utf-8') self.progress.step() info = self.db.note_map[bhandle] note = Note() @@ -1976,7 +1984,7 @@ class CheckIntegrity: for bad_handle in self.invalid_tag_references: make_unknown(bad_handle, None, self.class_tag, - self.commit_tag, self.trans) + self.commit_tag, self.trans) if len(self.invalid_tag_references) == 0: logging.info(' OK: no tag reference problems found') @@ -1987,12 +1995,10 @@ class CheckIntegrity: version 15 to 16. Mediarefs on source primary objects can contain sourcerefs, and these were not converted to citations. """ - total = ( - self.db.get_number_of_sources() - ) + total = (self.db.get_number_of_sources()) - self.progress.set_pass(_('Looking for media source reference problems'), - total) + self.progress.set_pass(_('Looking for media source reference ' + 'problems'), total) logging.info('Looking for media source reference problems') for handle in self.db.source_map.keys(): @@ -2023,9 +2029,9 @@ class CheckIntegrity: citation_handle = create_id() new_citation.set_handle(citation_handle) self.replaced_sourceref.append(handle) - logging.warning(' FAIL: the source "%s" has a media ' - 'reference with a source citation ' - 'which is invalid' % (source.gramps_id)) + logging.warning(' FAIL: the source "%s" has a media' + ' reference with a source citation ' + 'which is invalid', (source.gramps_id)) self.db.add_citation(new_citation, self.trans) new_citation_list.append(citation_handle) @@ -2037,14 +2043,15 @@ class CheckIntegrity: self.db.commit_source(source, self.trans) if len(self.replaced_sourceref) > 0: - logging.info(' OK: no broken source citations on mediarefs found') + logging.info(' OK: no broken source citations on mediarefs ' + 'found') def class_person(self, handle): person = Person() person.set_handle(handle) return person - def commit_person(self, person, trans, change): + def commit_person(self, person, trans, dummy): self.db.add_person(person, trans, set_gid=True) def class_family(self, handle): @@ -2052,7 +2059,7 @@ class CheckIntegrity: family.set_handle(handle) return family - def commit_family(self, family, trans, change): + def commit_family(self, family, trans, dummy): self.db.add_family(family, trans, set_gid=True) def class_event(self, handle): @@ -2060,7 +2067,7 @@ class CheckIntegrity: event.set_handle(handle) return event - def commit_event(self, event, trans, change): + def commit_event(self, event, trans, dummy): self.db.add_event(event, trans, set_gid=True) def class_place(self, handle): @@ -2068,7 +2075,7 @@ class CheckIntegrity: place.set_handle(handle) return place - def commit_place(self, place, trans, change): + def commit_place(self, place, trans, dummy): self.db.add_place(place, trans, set_gid=True) def class_source(self, handle): @@ -2076,7 +2083,7 @@ class CheckIntegrity: source.set_handle(handle) return source - def commit_source(self, source, trans, change): + def commit_source(self, source, trans, dummy): self.db.add_source(source, trans, set_gid=True) def class_citation(self, handle): @@ -2084,7 +2091,7 @@ class CheckIntegrity: citation.set_handle(handle) return citation - def commit_citation(self, citation, trans, change): + def commit_citation(self, citation, trans, dummy): self.db.add_citation(citation, trans, set_gid=True) def class_repo(self, handle): @@ -2092,23 +2099,23 @@ class CheckIntegrity: repo.set_handle(handle) return repo - def commit_repo(self, repo, trans, change): + def commit_repo(self, repo, trans, dummy): self.db.add_repository(repo, trans, set_gid=True) def class_media(self, handle): - object = Media() - object.set_handle(handle) - return object + obj = Media() + obj.set_handle(handle) + return obj - def commit_media(self, object, trans, change): - self.db.add_media(object, trans, set_gid=True) + def commit_media(self, obj, trans, dummy): + self.db.add_media(obj, trans, set_gid=True) def class_note(self, handle): note = Note() note.set_handle(handle) return note - def commit_note(self, note, trans, change): + def commit_note(self, note, trans, dummy): self.db.add_note(note, trans, set_gid=True) def class_tag(self, handle): @@ -2116,10 +2123,11 @@ class CheckIntegrity: tag.set_handle(handle) return tag - def commit_tag(self, tag, trans, change): + def commit_tag(self, tag, trans, dummy): self.db.add_tag(tag, trans) def build_report(self, uistate=None): + ''' build the report from various counters''' self.progress.close() bad_photos = len(self.bad_photo) replaced_photos = len(self.replaced_photo) @@ -2150,11 +2158,10 @@ class CheckIntegrity: errors = (photos + efam + blink + plink + slink + rel + event_invalid + person + self.place_errors + - person_references + family_references + place_references + - citation_references + repo_references + media_references + + person_references + family_references + place_references + + citation_references + repo_references + media_references + note_references + tag_references + name_format + empty_objs + - invalid_dates + source_references - ) + invalid_dates + source_references) if errors == 0: if uistate: @@ -2162,10 +2169,10 @@ class CheckIntegrity: _('The database has passed internal checks'), parent=uistate.window) else: - print(_("No errors were found: the database has passed internal checks.")) + print(_("No errors were found: the database has passed " + "internal checks.")) return 0 - self.text = StringIO() if blink > 0: self.text.write( # translators: leave all/any {...} untranslated @@ -2177,19 +2184,19 @@ class CheckIntegrity: try: person = self.db.get_person_from_handle(person_handle) except HandleError: - cn = _("Non existing child") + cname = _("Non existing child") else: - cn = person.get_primary_name().get_name() + cname = person.get_primary_name().get_name() try: family = self.db.get_family_from_handle(family_handle) except HandleError: - pn = _("Unknown") + pname = _("Unknown") else: - pn = family_name(family, self.db) + pname = family_name(family, self.db) self.text.write('\t') self.text.write( _("%(person)s was removed from the family of %(family)s\n") - % {'person': cn, 'family': pn} + % {'person': cname, 'family': pname} ) if plink > 0: @@ -2203,56 +2210,56 @@ class CheckIntegrity: try: person = self.db.get_person_from_handle(person_handle) except HandleError: - cn = _("Non existing person") + cname = _("Non existing person") else: - cn = person.get_primary_name().get_name() + cname = person.get_primary_name().get_name() try: family = self.db.get_family_from_handle(family_handle) except HandleError: - pn = _("Unknown") + pname = _("Unknown") else: - pn = family_name(family, self.db) + pname = family_name(family, self.db) self.text.write('\t') self.text.write( _("%(person)s was restored to the family of %(family)s\n") - % {'person': cn, 'family': pn} + % {'person': cname, 'family': pname} ) if slink > 0: self.text.write( # translators: leave all/any {...} untranslated ngettext("{quantity} duplicate " - "spouse/family link was found\n", + "spouse/family link was found\n", "{quantity} duplicate " - "spouse/family links were found\n", + "spouse/family links were found\n", slink).format(quantity=slink) ) for (person_handle, family_handle) in self.broken_parent_links: try: person = self.db.get_person_from_handle(person_handle) except HandleError: - cn = _("Non existing person") + cname = _("Non existing person") else: - cn = person.get_primary_name().get_name() + cname = person.get_primary_name().get_name() try: family = self.db.get_family_from_handle(family_handle) except HandleError: - pn = _("None") + pname = _("None") else: - pn = family_name(family, self.db) + pname = family_name(family, self.db) self.text.write('\t') self.text.write( _("%(person)s was restored to the family of %(family)s\n") - % {'person': cn, 'family': pn} + % {'person': cname, 'family': pname} ) if efam: self.text.write( # translators: leave all/any {...} untranslated ngettext("{quantity} family " - "with no parents or children found, removed.\n", + "with no parents or children found, removed.\n", "{quantity} families " - "with no parents or children found, removed.\n", + "with no parents or children found, removed.\n", efam).format(quantity=efam) ) if efam == 1: @@ -2287,9 +2294,9 @@ class CheckIntegrity: self.text.write( # translators: leave all/any {...} untranslated ngettext("{quantity} family was " - "referenced but not found\n", + "referenced but not found\n", "{quantity} families were " - "referenced, but not found\n", + "referenced, but not found\n", family_references).format(quantity=family_references) ) @@ -2306,9 +2313,9 @@ class CheckIntegrity: # translators: leave all/any {...} untranslated ngettext( "{quantity} repository was " - "referenced but not found\n", + "referenced but not found\n", "{quantity} repositories were " - "referenced, but not found\n", + "referenced, but not found\n", repo_references).format(quantity=repo_references) ) @@ -2316,9 +2323,9 @@ class CheckIntegrity: self.text.write( # translators: leave all/any {...} untranslated ngettext("{quantity} media object was " - "referenced but not found\n", + "referenced but not found\n", "{quantity} media objects were " - "referenced, but not found\n", + "referenced, but not found\n", photos).format(quantity=photos) ) @@ -2382,41 +2389,39 @@ class CheckIntegrity: if citation_references: self.text.write( # translators: leave all/any {...} untranslated - ngettext("{quantity} citation was " - "referenced but not found\n", - "{quantity} citations were " - "referenced, but not found\n", - citation_references - ).format(quantity=citation_references) + ngettext( + "{quantity} citation was referenced but not found\n", + "{quantity} citations were referenced, but not found\n", + citation_references + ).format(quantity=citation_references) ) if source_references: self.text.write( # translators: leave all/any {...} untranslated - ngettext("{quantity} source was " - "referenced but not found\n", - "{quantity} sources were " - "referenced, but not found\n", - source_references).format(quantity=source_references) + ngettext( + "{quantity} source was referenced but not found\n", + "{quantity} sources were referenced, but not found\n", + source_references).format(quantity=source_references) ) if media_references: self.text.write( # translators: leave all/any {...} untranslated - ngettext("{quantity} media object was " - "referenced but not found\n", - "{quantity} media objects were " - "referenced, but not found\n", - media_references).format(quantity=media_references) + ngettext( + "{quantity} media object was referenced but not found\n", + "{quantity} media objects were referenced," + " but not found\n", + media_references).format(quantity=media_references) ) if note_references: self.text.write( # translators: leave all/any {...} untranslated ngettext("{quantity} note object was " - "referenced but not found\n", + "referenced but not found\n", "{quantity} note objects were " - "referenced, but not found\n", + "referenced, but not found\n", note_references).format(quantity=note_references) ) @@ -2424,9 +2429,9 @@ class CheckIntegrity: self.text.write( # translators: leave all/any {...} untranslated ngettext("{quantity} tag object was " - "referenced but not found\n", + "referenced but not found\n", "{quantity} tag objects were " - "referenced, but not found\n", + "referenced, but not found\n", tag_references).format(quantity=tag_references) ) @@ -2434,9 +2439,9 @@ class CheckIntegrity: self.text.write( # translators: leave all/any {...} untranslated ngettext("{quantity} tag object was " - "referenced but not found\n", + "referenced but not found\n", "{quantity} tag objects were " - "referenced, but not found\n", + "referenced, but not found\n", tag_references).format(quantity=tag_references) ) @@ -2444,68 +2449,71 @@ class CheckIntegrity: self.text.write( # translators: leave all/any {...} untranslated ngettext("{quantity} invalid name format " - "reference was removed\n", + "reference was removed\n", "{quantity} invalid name format " - "references were removed\n", + "references were removed\n", name_format).format(quantity=name_format) ) if replaced_sourcerefs: self.text.write( # translators: leave all/any {...} untranslated - ngettext("{quantity} invalid source citation was fixed\n", - "{quantity} invalid source citations were fixed\n", - replaced_sourcerefs - ).format(quantity=replaced_sourcerefs) + ngettext( + "{quantity} invalid source citation was fixed\n", + "{quantity} invalid source citations were fixed\n", + replaced_sourcerefs + ).format(quantity=replaced_sourcerefs) ) - if empty_objs > 0 : - self.text.write(_("%(empty_obj)d empty objects removed:\n" - " %(person)d person objects\n" - " %(family)d family objects\n" - " %(event)d event objects\n" - " %(source)d source objects\n" - " %(media)d media objects\n" - " %(place)d place objects\n" - " %(repo)d repository objects\n" - " %(note)d note objects\n") % { - 'empty_obj' : empty_objs, - 'person' : len(self.empty_objects['persons']), - 'family' : len(self.empty_objects['families']), - 'event' : len(self.empty_objects['events']), - 'source' : len(self.empty_objects['sources']), - 'media' : len(self.empty_objects['media']), - 'place' : len(self.empty_objects['places']), - 'repo' : len(self.empty_objects['repos']), - 'note' : len(self.empty_objects['notes']) - } - ) + if empty_objs > 0: + self.text.write(_( + "%(empty_obj)d empty objects removed:\n" + " %(person)d person objects\n" + " %(family)d family objects\n" + " %(event)d event objects\n" + " %(source)d source objects\n" + " %(media)d media objects\n" + " %(place)d place objects\n" + " %(repo)d repository objects\n" + " %(note)d note objects\n") % { + 'empty_obj': empty_objs, + 'person': len(self.empty_objects['persons']), + 'family': len(self.empty_objects['families']), + 'event': len(self.empty_objects['events']), + 'source': len(self.empty_objects['sources']), + 'media': len(self.empty_objects['media']), + 'place': len(self.empty_objects['places']), + 'repo': len(self.empty_objects['repos']), + 'note': len(self.empty_objects['notes']) + } + ) return errors -#------------------------------------------------------------------------- + +# ------------------------------------------------------------------------- # # Display the results # -#------------------------------------------------------------------------- +# ------------------------------------------------------------------------- class Report(ManagedWindow): - - def __init__(self, uistate, text, cl=0): - if cl: - print (text) + """ Report out the results """ + def __init__(self, uistate, text, cli=0): + if cli: + print(text) if uistate: ManagedWindow.__init__(self, uistate, [], self) - topDialog = Glade() - topDialog.get_object("close").connect('clicked', self.close) - window = topDialog.toplevel - textwindow = topDialog.get_object("textwindow") + topdialog = Glade() + topdialog.get_object("close").connect('clicked', self.close) + window = topdialog.toplevel + textwindow = topdialog.get_object("textwindow") textwindow.get_buffer().set_text(text) self.set_window(window, - #topDialog.get_widget("title"), - topDialog.get_object("title"), + # topdialog.get_widget("title"), + topdialog.get_object("title"), _("Integrity Check Results")) self.show() @@ -2513,11 +2521,12 @@ class Report(ManagedWindow): def build_menu_names(self, obj): return (_('Check and Repair'), None) -#------------------------------------------------------------------------ + +# ------------------------------------------------------------------------ # # # -#------------------------------------------------------------------------ +# ------------------------------------------------------------------------ class CheckOptions(tool.ToolOptions): """ Defines options and provides handling interface. diff --git a/gramps/plugins/tool/testcasegenerator.py b/gramps/plugins/tool/testcasegenerator.py index 72ee17856..69c20f9b1 100644 --- a/gramps/plugins/tool/testcasegenerator.py +++ b/gramps/plugins/tool/testcasegenerator.py @@ -23,37 +23,40 @@ # """Tools/Debug/Generate Testcases for Persons and Families""" - -#------------------------------------------------------------------------- +# pylint: disable=too-many-statements,too-many-locals,too-many-branches +# pylint: disable=wrong-import-position,too-many-public-methods,no-self-use +# pylint: disable=too-many-arguments +# ------------------------------------------------------------------------ # # standard python modules # -#------------------------------------------------------------------------- +# ------------------------------------------------------------------------ import sys import os import random from gramps.gen.const import GRAMPS_LOCALE as glocale _ = glocale.translation.gettext -#------------------------------------------------------------------------- +# ------------------------------------------------------------------------ # # GNOME libraries # -#------------------------------------------------------------------------- +# ------------------------------------------------------------------------ from gi.repository import Gtk -#------------------------------------------------------------------------- +# ------------------------------------------------------------------------ # # Gramps modules # -#------------------------------------------------------------------------- -from gramps.gen.lib import (Address, Attribute, AttributeType, ChildRef, - ChildRefType, Citation, Date, Event, EventRef, EventRoleType, - EventType, Family, FamilyRelType, GrampsType, LdsOrd, Location, - Media, MediaRef, Name, NameOriginType, NameType, Note, - NoteType, Person, PersonRef, Place, PlaceType, PlaceRef, PlaceName, - RepoRef, Repository, RepositoryType, Source, SourceMediaType, - SrcAttribute, SrcAttributeType, Surname, Tag, Url, UrlType) +# ------------------------------------------------------------------------ +from gramps.gen.lib import ( + Address, Attribute, AttributeType, ChildRef, + ChildRefType, Citation, Date, Event, EventRef, EventRoleType, + EventType, Family, FamilyRelType, GrampsType, LdsOrd, Location, + Media, MediaRef, Name, NameOriginType, NameType, Note, + NoteType, Person, PersonRef, Place, PlaceType, PlaceRef, PlaceName, + RepoRef, Repository, RepositoryType, Source, SourceMediaType, + SrcAttribute, SrcAttributeType, Surname, Tag, Url, UrlType) from gramps.gen.lib.addressbase import AddressBase from gramps.gen.lib.attrbase import AttributeBase from gramps.gen.lib.primaryobj import BasicPrimaryObject @@ -79,11 +82,11 @@ from gramps.gen.const import ICON, LOGO, SPLASH from gramps.gui.display import display_help from gramps.gen.const import URL_MANUAL_PAGE -#------------------------------------------------------------------------- +# ------------------------------------------------------------------------ # # Constants # -#------------------------------------------------------------------------- +# ------------------------------------------------------------------------ WIKI_HELP_PAGE = '%s_-_Tools' % URL_MANUAL_PAGE WIKI_HELP_SEC = _('Generate_Testcases_for_Persons_and_Families') @@ -103,52 +106,53 @@ _randint = myrand.randint LDS_ORD_BAPT_STATUS = ( - LdsOrd.STATUS_NONE, - LdsOrd.STATUS_CHILD, LdsOrd.STATUS_CLEARED, - LdsOrd.STATUS_COMPLETED, LdsOrd.STATUS_INFANT, - LdsOrd.STATUS_PRE_1970, LdsOrd.STATUS_QUALIFIED, - LdsOrd.STATUS_STILLBORN, LdsOrd.STATUS_SUBMITTED, - LdsOrd.STATUS_UNCLEARED) + LdsOrd.STATUS_NONE, + LdsOrd.STATUS_CHILD, LdsOrd.STATUS_CLEARED, + LdsOrd.STATUS_COMPLETED, LdsOrd.STATUS_INFANT, + LdsOrd.STATUS_PRE_1970, LdsOrd.STATUS_QUALIFIED, + LdsOrd.STATUS_STILLBORN, LdsOrd.STATUS_SUBMITTED, + LdsOrd.STATUS_UNCLEARED) LDS_ORD_CHILD_SEALING_STATUS = ( - LdsOrd.STATUS_NONE, - LdsOrd.STATUS_BIC, LdsOrd.STATUS_CLEARED, - LdsOrd.STATUS_COMPLETED,LdsOrd.STATUS_DNS, - LdsOrd.STATUS_PRE_1970, LdsOrd.STATUS_QUALIFIED, - LdsOrd.STATUS_STILLBORN, LdsOrd.STATUS_SUBMITTED, - LdsOrd.STATUS_UNCLEARED) + LdsOrd.STATUS_NONE, + LdsOrd.STATUS_BIC, LdsOrd.STATUS_CLEARED, + LdsOrd.STATUS_COMPLETED, LdsOrd.STATUS_DNS, + LdsOrd.STATUS_PRE_1970, LdsOrd.STATUS_QUALIFIED, + LdsOrd.STATUS_STILLBORN, LdsOrd.STATUS_SUBMITTED, + LdsOrd.STATUS_UNCLEARED) LDS_ENDOWMENT_DATE_STATUS = ( - LdsOrd.STATUS_NONE, - LdsOrd.STATUS_CHILD, LdsOrd.STATUS_CLEARED, - LdsOrd.STATUS_COMPLETED, LdsOrd.STATUS_INFANT, - LdsOrd.STATUS_PRE_1970, LdsOrd.STATUS_QUALIFIED, - LdsOrd.STATUS_STILLBORN, LdsOrd.STATUS_SUBMITTED, - LdsOrd.STATUS_UNCLEARED) + LdsOrd.STATUS_NONE, + LdsOrd.STATUS_CHILD, LdsOrd.STATUS_CLEARED, + LdsOrd.STATUS_COMPLETED, LdsOrd.STATUS_INFANT, + LdsOrd.STATUS_PRE_1970, LdsOrd.STATUS_QUALIFIED, + LdsOrd.STATUS_STILLBORN, LdsOrd.STATUS_SUBMITTED, + LdsOrd.STATUS_UNCLEARED) LDS_SPOUSE_SEALING_DATE_STATUS = ( - LdsOrd.STATUS_NONE, - LdsOrd.STATUS_CANCELED, LdsOrd.STATUS_CLEARED, - LdsOrd.STATUS_COMPLETED, LdsOrd.STATUS_DNS, - LdsOrd.STATUS_DNS_CAN, LdsOrd.STATUS_PRE_1970, - LdsOrd.STATUS_QUALIFIED, LdsOrd.STATUS_SUBMITTED, - LdsOrd.STATUS_UNCLEARED) + LdsOrd.STATUS_NONE, + LdsOrd.STATUS_CANCELED, LdsOrd.STATUS_CLEARED, + LdsOrd.STATUS_COMPLETED, LdsOrd.STATUS_DNS, + LdsOrd.STATUS_DNS_CAN, LdsOrd.STATUS_PRE_1970, + LdsOrd.STATUS_QUALIFIED, LdsOrd.STATUS_SUBMITTED, + LdsOrd.STATUS_UNCLEARED) LDS_INDIVIDUAL_ORD = [(LdsOrd.BAPTISM, LDS_ORD_BAPT_STATUS), (LdsOrd.CONFIRMATION, LDS_ORD_BAPT_STATUS), (LdsOrd.ENDOWMENT, LDS_ENDOWMENT_DATE_STATUS), - (LdsOrd.SEAL_TO_PARENTS, - LDS_ORD_CHILD_SEALING_STATUS)] + (LdsOrd.SEAL_TO_PARENTS, LDS_ORD_CHILD_SEALING_STATUS)] LDS_SPOUSE_SEALING = [(LdsOrd.SEAL_TO_SPOUSE, - LDS_SPOUSE_SEALING_DATE_STATUS)] + LDS_SPOUSE_SEALING_DATE_STATUS)] + + +# ------------------------------------------------------------------------ -#------------------------------------------------------------------------- -# -# -# -#------------------------------------------------------------------------- class TestcaseGenerator(tool.BatchTool): + ''' + This tool generates various test cases for problems that have occured. + The issues it generates can be corrected via the 'Check and Repair' tool. + ''' NUMERIC = 0 FIRSTNAME = 1 FIRSTNAME_FEMALE = 2 @@ -178,17 +182,17 @@ class TestcaseGenerator(tool.BatchTool): # ] FAMILY_EVENTS = set([ - EventType.ANNULMENT, - EventType.CENSUS, - EventType.DIVORCE, - EventType.DIV_FILING, - EventType.ENGAGEMENT, - EventType.MARRIAGE, - EventType.MARR_BANNS, - EventType.MARR_CONTR, - EventType.MARR_LIC, - EventType.MARR_SETTL, - EventType.CUSTOM ]) + EventType.ANNULMENT, + EventType.CENSUS, + EventType.DIVORCE, + EventType.DIV_FILING, + EventType.ENGAGEMENT, + EventType.MARRIAGE, + EventType.MARR_BANNS, + EventType.MARR_CONTR, + EventType.MARR_LIC, + EventType.MARR_SETTL, + EventType.CUSTOM]) def __init__(self, dbstate, user, options_class, name, callback=None): uistate = user.uistate @@ -197,7 +201,10 @@ class TestcaseGenerator(tool.BatchTool): else: parent_window = None self.progress = user.progress + +# ******** This ensures that a chunk of code below never executes!!!! self.person = None + if dbstate.db.readonly: return @@ -207,7 +214,9 @@ class TestcaseGenerator(tool.BatchTool): if self.fail: return + self.options_dict = self.options.handler.options_dict self.person_count = 0 + self.max_person_count = self.options_dict['person_count'] self.persons_todo = [] self.parents_todo = [] self.person_dates = {} @@ -221,26 +230,28 @@ class TestcaseGenerator(tool.BatchTool): self.generated_notes = [] self.generated_tags = [] self.text_serial_number = 1 + self.trans = None self.parent_places = {} for type_num in range(1, 8): self.parent_places[type_num] = [] - # If an active persons exists the generated tree is connected to that person + # If an active persons exists the generated tree is connected to that + # person if self.person: # try to get birth and death year try: - bh = self.person.get_birth_handle() - b = self.db.get_event_from_handle( bh) - do = b.get_date_object() - birth = do.get_year() + birth_h = self.person.get_birth_handle() + birth_e = self.db.get_event_from_handle(birth_h) + dat_o = birth_e.get_date_object() + birth = dat_o.get_year() except AttributeError: birth = None try: - dh = self.person.get_death_handle() - b = self.db.get_event_from_handle( dh) - do = b.get_date_object() - death = do.get_year() + death_h = self.person.get_death_handle() + death_e = self.db.get_event_from_handle(death_h) + dat_o = death_e.get_date_object() + death = dat_o.get_year() except AttributeError: death = None if not birth and not death: @@ -249,7 +260,7 @@ class TestcaseGenerator(tool.BatchTool): death = birth + _randint(20, 90) if death and not birth: birth = death - _randint(20, 90) - self.person_dates[self.person.get_handle()] = (birth,death) + self.person_dates[self.person.get_handle()] = (birth, death) self.persons_todo.append(self.person.get_handle()) self.parents_todo.append(self.person.get_handle()) @@ -259,56 +270,59 @@ class TestcaseGenerator(tool.BatchTool): else: self.run_tool(cli=True) - def init_gui(self,uistate): + def init_gui(self, uistate): title = "%s - Gramps" % _("Generate testcases") self.top = Gtk.Dialog(title, parent=uistate.window) self.window = uistate.window - self.top.set_default_size(400,150) + self.top.set_default_size(400, 150) self.top.vbox.set_spacing(5) - label = Gtk.Label(label='%s' % _("Generate testcases")) + label = Gtk.Label(label='%s' + % _("Generate testcases")) label.set_use_markup(True) - self.top.vbox.pack_start(label,0,0,5) + self.top.vbox.pack_start(label, 0, 0, 5) - self.check_lowlevel = Gtk.CheckButton(label=_("Generate low level database " - "errors\nCorrection needs database reload")) - self.check_lowlevel.set_active( self.options.handler.options_dict['lowlevel']) - self.top.vbox.pack_start(self.check_lowlevel,0,0,5) + self.check_lowlevel = Gtk.CheckButton(label=_( + "Generate low level database " + "errors\nCorrection needs database reload")) + self.check_lowlevel.set_active(self.options_dict['lowlevel']) + self.top.vbox.pack_start(self.check_lowlevel, 0, 0, 5) self.check_bugs = Gtk.CheckButton(label=_("Generate database errors")) - self.check_bugs.set_active( self.options.handler.options_dict['bugs']) - self.top.vbox.pack_start(self.check_bugs,0,0,5) + self.check_bugs.set_active(self.options_dict['bugs']) + self.top.vbox.pack_start(self.check_bugs, 0, 0, 5) self.check_persons = Gtk.CheckButton(label=_("Generate dummy data")) - self.check_persons.set_active( self.options.handler.options_dict['persons']) + self.check_persons.set_active(self.options_dict['persons']) self.check_persons.connect('clicked', self.on_dummy_data_clicked) - self.top.vbox.pack_start(self.check_persons,0,0,5) + self.top.vbox.pack_start(self.check_persons, 0, 0, 5) self.check_longnames = Gtk.CheckButton(label=_("Generate long names")) - self.check_longnames.set_active( self.options.handler.options_dict['long_names']) - self.top.vbox.pack_start(self.check_longnames,0,0,5) + self.check_longnames.set_active(self.options_dict['long_names']) + self.top.vbox.pack_start(self.check_longnames, 0, 0, 5) - self.check_specialchars = Gtk.CheckButton(label=_("Add special characters")) - self.check_specialchars.set_active( self.options.handler.options_dict['specialchars']) - self.top.vbox.pack_start(self.check_specialchars,0,0,5) + self.check_specialchars = Gtk.CheckButton(label=_( + "Add special characters")) + self.check_specialchars.set_active(self.options_dict['specialchars']) + self.top.vbox.pack_start(self.check_specialchars, 0, 0, 5) self.check_serial = Gtk.CheckButton(label=_("Add serial number")) - self.check_serial.set_active( self.options.handler.options_dict['add_serial']) - self.top.vbox.pack_start(self.check_serial,0,0,5) + self.check_serial.set_active(self.options_dict['add_serial']) + self.top.vbox.pack_start(self.check_serial, 0, 0, 5) self.check_linebreak = Gtk.CheckButton(label=_("Add line break")) - self.check_linebreak.set_active( self.options.handler.options_dict['add_linebreak']) - self.top.vbox.pack_start(self.check_linebreak,0,0,5) + self.check_linebreak.set_active(self.options_dict['add_linebreak']) + self.top.vbox.pack_start(self.check_linebreak, 0, 0, 5) - self.label = Gtk.Label(label=_("Number of people to generate\n" - "(Number is approximate because families " - "are generated)")) + self.label = Gtk.Label(label=_( + "Number of people to generate\n" + "(Number is approximate because families are generated)")) self.label.set_halign(Gtk.Align.START) - self.top.vbox.pack_start(self.label,0,0,5) + self.top.vbox.pack_start(self.label, 0, 0, 5) self.entry_count = Gtk.Entry() - self.entry_count.set_text(str( self.options.handler.options_dict['person_count'])) + self.entry_count.set_text(str(self.max_person_count)) self.on_dummy_data_clicked(self.check_persons) - self.top.vbox.pack_start(self.entry_count,0,0,5) + self.top.vbox.pack_start(self.entry_count, 0, 0, 5) self.top.add_button(_('_Cancel'), Gtk.ResponseType.CANCEL) self.top.add_button(_('_OK'), Gtk.ResponseType.OK) @@ -316,30 +330,30 @@ class TestcaseGenerator(tool.BatchTool): self.top.show_all() response = self.top.run() - self.options.handler.options_dict['lowlevel'] = int( + self.options_dict['lowlevel'] = int( self.check_lowlevel.get_active()) - self.options.handler.options_dict['bugs'] = int( + self.options_dict['bugs'] = int( self.check_bugs.get_active()) - self.options.handler.options_dict['persons'] = int( + self.options_dict['persons'] = int( self.check_persons.get_active()) - self.options.handler.options_dict['long_names'] = int( + self.options_dict['long_names'] = int( self.check_longnames.get_active()) - self.options.handler.options_dict['specialchars'] = int( + self.options_dict['specialchars'] = int( self.check_specialchars.get_active()) - self.options.handler.options_dict['add_serial'] = int( + self.options_dict['add_serial'] = int( self.check_serial.get_active()) - self.options.handler.options_dict['add_linebreak'] = int( + self.options_dict['add_linebreak'] = int( self.check_linebreak.get_active()) - self.options.handler.options_dict['person_count'] = int( + self.options_dict['person_count'] = int( self.entry_count.get_text()) self.top.destroy() if response == Gtk.ResponseType.HELP: display_help(webpage=WIKI_HELP_PAGE, - section=WIKI_HELP_SEC) + section=WIKI_HELP_SEC) else: if response == Gtk.ResponseType.OK: - self.run_tool( cli=False) + self.run_tool(cli=False) # Save options self.options.handler.save_options() @@ -349,57 +363,56 @@ class TestcaseGenerator(tool.BatchTool): def run_tool(self, cli=False): self.cli = cli - if (not cli): + if not cli: while Gtk.events_pending(): Gtk.main_iteration() else: self.window = None - self.transaction_count = 0; + self.transaction_count = 0 - if self.options.handler.options_dict['lowlevel']: + if self.options_dict['lowlevel']: with self.progress(_('Generating testcases'), _('Generating low level database errors'), 1) as step: self.test_low_level() step() - if self.options.handler.options_dict['bugs'] or \ - self.options.handler.options_dict['persons']: + if self.options_dict['bugs'] or self.options_dict['persons']: self.generate_tags() - if self.options.handler.options_dict['bugs']: + if self.options_dict['bugs']: with self.progress(_('Generating testcases'), _('Generating database errors'), 19) as step: self.generate_data_errors(step) - if self.options.handler.options_dict['persons']: + if self.options_dict['persons']: with self.progress(_('Generating testcases'), _('Generating families'), - self.options.handler.options_dict['person_count']) \ + self.max_person_count) \ as self.progress_step: self.person_count = 0 while True: if not self.persons_todo: - ph = self.generate_person(0) - self.persons_todo.append( ph) - self.parents_todo.append( ph) + pers_h = self.generate_person(0) + self.persons_todo.append(pers_h) + self.parents_todo.append(pers_h) person_h = self.persons_todo.pop(0) self.generate_family(person_h) if _randint(0, 3) == 0: self.generate_family(person_h) if _randint(0, 7) == 0: self.generate_family(person_h) - if self.person_count > self.options.handler.options_dict['person_count']: + if self.person_count > self.max_person_count: break for child_h in self.parents_todo: self.generate_parents(child_h) - if self.person_count > self.options.handler.options_dict['person_count']: + if self.person_count > self.max_person_count: break - if( not cli): + if not cli: self.top.destroy() def generate_data_errors(self, step): @@ -407,121 +420,143 @@ class TestcaseGenerator(tool.BatchTool): The module names correspond to the checking methods in src/plugins/tool/Check.CheckIntegrity """ # The progress meter is normally stepped every time a person is - # generated by generate_person. However in this case, generate_person is - # called by some of the constituent functions, but we only want the + # generated by generate_person. However in this case, generate_person + # is called by some of the constituent functions, but we only want the # meter to be stepped every time a test function has been completed. self.progress_step = lambda: None - self.test_fix_encoding(); step() - self.test_fix_ctrlchars_in_notes(); step() - self.test_fix_alt_place_names(); step() - self.test_cleanup_deleted_name_formats(); step() - self.test_cleanup_empty_objects(); step() - self.test_check_for_broken_family_links(); step() - self.test_check_parent_relationships(); step() - self.test_cleanup_empty_families(); step() - self.test_cleanup_duplicate_spouses(); step() - self.test_check_events(); step() - self.test_check_person_references(); step() - self.test_check_family_references(); step() - self.test_check_place_references(); step() - self.test_check_source_references(); step() - self.test_check_citation_references(); step() - self.test_check_media_references(); step() - self.test_check_repo_references(); step() - self.test_check_note_references(); step() + self.test_fix_encoding() + step() + self.test_fix_ctrlchars_in_notes() + step() + self.test_fix_alt_place_names() + step() + self.test_clean_deleted_name_format() + step() + self.test_cleanup_empty_objects() + step() + self.test_chk_for_broke_family_link() + step() + self.test_check_parent_relationships() + step() + self.test_cleanup_empty_families() + step() + self.test_cleanup_duplicate_spouses() + step() + self.test_check_events() + step() + self.test_check_person_references() + step() + self.test_check_family_references() + step() + self.test_check_place_references() + step() + self.test_check_source_references() + step() + self.test_check_citation_references() + step() + self.test_check_media_references() + step() + self.test_check_repo_references() + step() + self.test_check_note_references() + step() def test_low_level(self): with DbTxn(_("Testcase generator step %d") % self.transaction_count, self.db) as self.trans: self.transaction_count += 1 - o = Note() - o.set("dup 1" + self.rand_text(self.NOTE)) - o.set_format(_choice((Note.FLOWED, Note.FORMATTED))) - o.set_type( self.rand_type(NoteType())) - h = self.db.add_note(o, self.trans) - print("object %s, handle %s, Gramps_Id %s" % (o, o.handle, - o.gramps_id)) + obj = Note() + obj.set("dup 1" + self.rand_text(self.NOTE)) + obj.set_format(_choice((Note.FLOWED, Note.FORMATTED))) + obj.set_type(self.rand_type(NoteType())) + self.db.add_note(obj, self.trans) + print("object %s, handle %s, Gramps_Id %s" % (obj, obj.handle, + obj.gramps_id)) - handle = o.get_handle() + handle = obj.get_handle() - o = Source() - o.set_title("dup 2" + self.rand_text(self.SHORT)) + src = Source() + src.set_title("dup 2" + self.rand_text(self.SHORT)) if _randint(0, 1) == 1: - o.set_author( self.rand_text(self.SHORT)) + src.set_author(self.rand_text(self.SHORT)) if _randint(0, 1) == 1: - o.set_publication_info( self.rand_text(self.LONG)) + src.set_publication_info(self.rand_text(self.LONG)) if _randint(0, 1) == 1: - o.set_abbreviation( self.rand_text(self.SHORT)) + src.set_abbreviation(self.rand_text(self.SHORT)) while _randint(0, 1) == 1: sattr = SrcAttribute() sattr.set_type(self.rand_text(self.SHORT)) sattr.set_value(self.rand_text(self.SHORT)) - o.add_attribute(sattr) - o.set_handle(handle) - self.db.add_source(o, self.trans) - print("object %s, handle %s, Gramps_Id %s" % (o, o.handle, - o.gramps_id)) + src.add_attribute(sattr) + src.set_handle(handle) + self.db.add_source(src, self.trans) + print("object %s, handle %s, Gramps_Id %s" % (src, src.handle, + src.gramps_id)) def test_fix_encoding(self): - # Creates a media object with character encoding errors. This tests - # Check.fix_encoding() and also cleanup_missing_photos + """ Creates a media object with character encoding errors. This tests + Check.fix_encoding() and also cleanup_missing_photos + """ with DbTxn(_("Testcase generator step %d") % self.transaction_count, self.db) as self.trans: self.transaction_count += 1 - m = Media() - self.fill_object(m) - m.set_description("leave this media object invalid description\x9f") - m.set_path("/tmp/click_on_keep_reference.png\x9f") - m.set_mime_type("image/png\x9f") - self.db.add_media(m, self.trans) + med = Media() + self.fill_object(med) + med.set_description("leave this media object invalid description" + "\x9f") + med.set_path("/tmp/click_on_keep_reference.png\x9f") + med.set_mime_type("image/png\x9f") + self.db.add_media(med, self.trans) - m = Media() - self.fill_object(m) - m.set_description("reselect this media object invalid description\x9f") - m.set_path("/tmp/click_on_select_file.png\x9f") - m.set_mime_type("image/png\x9f") - self.db.add_media(m, self.trans) + med = Media() + self.fill_object(med) + med.set_description("reselect this media object invalid " + "description\x9f") + med.set_path("/tmp/click_on_select_file.png\x9f") + med.set_mime_type("image/png\x9f") + self.db.add_media(med, self.trans) # setup media attached to Source and Citation to be removed - m = Media() - self.fill_object(m) - m.set_description('remove this media object') - m.set_path("/tmp/click_on_remove_object.png") - m.set_mime_type("image/png") - self.db.add_media(m, self.trans) + med = Media() + self.fill_object(med) + med.set_description('remove this media object') + med.set_path("/tmp/click_on_remove_object.png") + med.set_mime_type("image/png") + self.db.add_media(med, self.trans) - s = Source() - s.set_title('media should be removed from this source') - r = MediaRef() - r.set_reference_handle(m.handle) - s.add_media_reference(r) - self.db.add_source( s, self.trans) + src = Source() + src.set_title('media should be removed from this source') + ref = MediaRef() + ref.set_reference_handle(med.handle) + src.add_media_reference(ref) + self.db.add_source(src, self.trans) - c = Citation() - self.fill_object(c) - c.set_reference_handle(s.handle) - c.set_page('media should be removed from this citation') - r = MediaRef() - r.set_reference_handle(m.handle) - c.add_media_reference(r) - self.db.add_citation(c, self.trans) + cit = Citation() + self.fill_object(cit) + cit.set_reference_handle(src.handle) + cit.set_page('media should be removed from this citation') + ref = MediaRef() + ref.set_reference_handle(med.handle) + cit.add_media_reference(ref) + self.db.add_citation(cit, self.trans) def test_fix_ctrlchars_in_notes(self): - # Creates a note with control characters. This tests - # Check.fix_ctrlchars_in_notes() + """ Creates a note with control characters. This tests + Check.fix_ctrlchars_in_notes() + """ with DbTxn(_("Testcase generator step %d") % self.transaction_count, self.db) as self.trans: self.transaction_count += 1 - o = Note() - o.set("This is a text note with a \x03 control character") - o.set_format(_choice((Note.FLOWED, Note.FORMATTED))) - o.set_type(self.rand_type(NoteType())) - self.db.add_note(o, self.trans) + obj = Note() + obj.set("This is a text note with a \x03 control character") + obj.set_format(_choice((Note.FLOWED, Note.FORMATTED))) + obj.set_type(self.rand_type(NoteType())) + self.db.add_note(obj, self.trans) def test_fix_alt_place_names(self): """ @@ -554,275 +589,281 @@ class TestcaseGenerator(tool.BatchTool): def test_cleanup_missing_photos(self): pass - def test_cleanup_deleted_name_formats(self): + def test_clean_deleted_name_format(self): pass def test_cleanup_empty_objects(self): - # Generate empty objects to test their deletion + """ Generate empty objects to test their deletion """ with DbTxn(_("Testcase generator step %d") % self.transaction_count, self.db) as self.trans: self.transaction_count += 1 - p = Person() - self.db.add_person( p, self.trans) + pers = Person() + self.db.add_person(pers, self.trans) - f = Family() - self.db.add_family( f, self.trans) + fam = Family() + self.db.add_family(fam, self.trans) - e = Event() - self.db.add_event( e, self.trans) + evt = Event() + self.db.add_event(evt, self.trans) - p = Place() - self.db.add_place( p, self.trans) + place = Place() + self.db.add_place(place, self.trans) - s = Source() - self.db.add_source( s, self.trans) + src = Source() + self.db.add_source(src, self.trans) - c = Citation() - self.db.add_citation( c, self.trans) + cit = Citation() + self.db.add_citation(cit, self.trans) - m = Media() - self.db.add_media( m, self.trans) + med = Media() + self.db.add_media(med, self.trans) - r = Repository() - self.db.add_repository( r, self.trans) + ref = Repository() + self.db.add_repository(ref, self.trans) - n = Note() - self.db.add_note( n, self.trans) + note = Note() + self.db.add_note(note, self.trans) - def test_check_for_broken_family_links(self): + def test_chk_for_broke_family_link(self): + """ Create various family related errors """ # Create a family, that links to father and mother, but father does not # link back with DbTxn(_("Testcase generator step %d") % self.transaction_count, self.db) as self.trans: self.transaction_count += 1 - person1_h = self.generate_person(Person.MALE,"Broken1","Family links to this person, but person does not link back") - person2_h = self.generate_person(Person.FEMALE,"Broken1",None) + person1_h = self.generate_person( + Person.MALE, "Broken1", + "Family links to this person, but person does not link back") + person2_h = self.generate_person(Person.FEMALE, "Broken1", None) fam = Family() fam.set_father_handle(person1_h) fam.set_mother_handle(person2_h) - fam.set_relationship((FamilyRelType.MARRIED,'')) - fam_h = self.db.add_family(fam,self.trans) - #person1 = self.db.get_person_from_handle(person1_h) - #person1.add_family_handle(fam_h) - #self.db.commit_person(person1,self.trans) + fam.set_relationship((FamilyRelType.MARRIED, '')) + fam_h = self.db.add_family(fam, self.trans) + # person1 = self.db.get_person_from_handle(person1_h) + # person1.add_family_handle(fam_h) + # self.db.commit_person(person1, self.trans) person2 = self.db.get_person_from_handle(person2_h) person2.add_family_handle(fam_h) - self.db.commit_person(person2,self.trans) + self.db.commit_person(person2, self.trans) # Create a family, that misses the link to the father with DbTxn(_("Testcase generator step %d") % self.transaction_count, self.db) as self.trans: self.transaction_count += 1 - person1_h = self.generate_person(Person.MALE,"Broken2",None) - person2_h = self.generate_person(Person.FEMALE,"Broken2",None) + person1_h = self.generate_person(Person.MALE, "Broken2", None) + person2_h = self.generate_person(Person.FEMALE, "Broken2", None) fam = Family() - #fam.set_father_handle(person1_h) + # fam.set_father_handle(person1_h) fam.set_mother_handle(person2_h) - fam.set_relationship((FamilyRelType.MARRIED,'')) - fam_h = self.db.add_family(fam,self.trans) + fam.set_relationship((FamilyRelType.MARRIED, '')) + fam_h = self.db.add_family(fam, self.trans) person1 = self.db.get_person_from_handle(person1_h) person1.add_family_handle(fam_h) - self.db.commit_person(person1,self.trans) + self.db.commit_person(person1, self.trans) person2 = self.db.get_person_from_handle(person2_h) person2.add_family_handle(fam_h) - self.db.commit_person(person2,self.trans) + self.db.commit_person(person2, self.trans) # Create a family, that misses the link to the mother with DbTxn(_("Testcase generator step %d") % self.transaction_count, self.db) as self.trans: self.transaction_count += 1 - person1_h = self.generate_person(Person.MALE,"Broken3",None) - person2_h = self.generate_person(Person.FEMALE,"Broken3",None) + person1_h = self.generate_person(Person.MALE, "Broken3", None) + person2_h = self.generate_person(Person.FEMALE, "Broken3", None) fam = Family() fam.set_father_handle(person1_h) - #fam.set_mother_handle(person2_h) - fam.set_relationship((FamilyRelType.MARRIED,'')) - fam_h = self.db.add_family(fam,self.trans) + # fam.set_mother_handle(person2_h) + fam.set_relationship((FamilyRelType.MARRIED, '')) + fam_h = self.db.add_family(fam, self.trans) person1 = self.db.get_person_from_handle(person1_h) person1.add_family_handle(fam_h) - self.db.commit_person(person1,self.trans) + self.db.commit_person(person1, self.trans) person2 = self.db.get_person_from_handle(person2_h) person2.add_family_handle(fam_h) - self.db.commit_person(person2,self.trans) + self.db.commit_person(person2, self.trans) # Create a family, that links to father and mother, but mother does not # link back with DbTxn(_("Testcase generator step %d") % self.transaction_count, self.db) as self.trans: self.transaction_count += 1 - person1_h = self.generate_person(Person.MALE,"Broken4",None) - person2_h = self.generate_person(Person.FEMALE,"Broken4","Family links to this person, but person does not link back") + person1_h = self.generate_person(Person.MALE, "Broken4", None) + person2_h = self.generate_person( + Person.FEMALE, "Broken4", + "Family links to this person, but person does not link back") fam = Family() fam.set_father_handle(person1_h) fam.set_mother_handle(person2_h) - fam.set_relationship((FamilyRelType.MARRIED,'')) - fam_h = self.db.add_family(fam,self.trans) + fam.set_relationship((FamilyRelType.MARRIED, '')) + fam_h = self.db.add_family(fam, self.trans) person1 = self.db.get_person_from_handle(person1_h) person1.add_family_handle(fam_h) - self.db.commit_person(person1,self.trans) - #person2 = self.db.get_person_from_handle(person2_h) - #person2.add_family_handle(fam_h) - #self.db.commit_person(person2,self.trans) + self.db.commit_person(person1, self.trans) + # person2 = self.db.get_person_from_handle(person2_h) + # person2.add_family_handle(fam_h) + # self.db.commit_person(person2, self.trans) # Create two married people of same sex. # This is NOT detected as an error by plugins/tool/Check.py with DbTxn(_("Testcase generator step %d") % self.transaction_count, self.db) as self.trans: self.transaction_count += 1 - person1_h = self.generate_person(Person.MALE,"Broken5",None) - person2_h = self.generate_person(Person.MALE,"Broken5",None) + person1_h = self.generate_person(Person.MALE, "Broken5", None) + person2_h = self.generate_person(Person.MALE, "Broken5", None) fam = Family() fam.set_father_handle(person1_h) fam.set_mother_handle(person2_h) - fam.set_relationship((FamilyRelType.MARRIED,'')) - fam_h = self.db.add_family(fam,self.trans) + fam.set_relationship((FamilyRelType.MARRIED, '')) + fam_h = self.db.add_family(fam, self.trans) person1 = self.db.get_person_from_handle(person1_h) person1.add_family_handle(fam_h) - self.db.commit_person(person1,self.trans) + self.db.commit_person(person1, self.trans) person2 = self.db.get_person_from_handle(person2_h) person2.add_family_handle(fam_h) - self.db.commit_person(person2,self.trans) + self.db.commit_person(person2, self.trans) # Create a family, that contains an invalid handle to for the father with DbTxn(_("Testcase generator step %d") % self.transaction_count, self.db) as self.trans: self.transaction_count += 1 - #person1_h = self.generate_person(Person.MALE,"Broken6",None) - person2_h = self.generate_person(Person.FEMALE,"Broken6",None) + # person1_h = self.generate_person(Person.MALE, "Broken6", None) + person2_h = self.generate_person(Person.FEMALE, "Broken6", None) fam = Family() fam.set_father_handle("InvalidHandle1") fam.set_mother_handle(person2_h) - fam.set_relationship((FamilyRelType.MARRIED,'')) - fam_h = self.db.add_family(fam,self.trans) - #person1 = self.db.get_person_from_handle(person1_h) - #person1.add_family_handle(fam_h) - #self.db.commit_person(person1,self.trans) + fam.set_relationship((FamilyRelType.MARRIED, '')) + fam_h = self.db.add_family(fam, self.trans) + # person1 = self.db.get_person_from_handle(person1_h) + # person1.add_family_handle(fam_h) + # self.db.commit_person(person1, self.trans) person2 = self.db.get_person_from_handle(person2_h) person2.add_family_handle(fam_h) - self.db.commit_person(person2,self.trans) + self.db.commit_person(person2, self.trans) # Create a family, that contains an invalid handle to for the mother with DbTxn(_("Testcase generator step %d") % self.transaction_count, self.db) as self.trans: self.transaction_count += 1 - person1_h = self.generate_person(Person.MALE,"Broken7",None) - #person2_h = self.generate_person(Person.FEMALE,"Broken7",None) + person1_h = self.generate_person(Person.MALE, "Broken7", None) + # person2_h = self.generate_person(Person.FEMALE, "Broken7", None) fam = Family() fam.set_father_handle(person1_h) fam.set_mother_handle("InvalidHandle2") - fam.set_relationship((FamilyRelType.MARRIED,'')) - fam_h = self.db.add_family(fam,self.trans) + fam.set_relationship((FamilyRelType.MARRIED, '')) + fam_h = self.db.add_family(fam, self.trans) person1 = self.db.get_person_from_handle(person1_h) person1.add_family_handle(fam_h) - self.db.commit_person(person1,self.trans) - #person2 = self.db.get_person_from_handle(person2_h) - #person2.add_family_handle(fam_h) - #self.db.commit_person(person2,self.trans) + self.db.commit_person(person1, self.trans) + # person2 = self.db.get_person_from_handle(person2_h) + # person2.add_family_handle(fam_h) + # self.db.commit_person(person2, self.trans) # Creates a family where the child does not link back to the family with DbTxn(_("Testcase generator step %d") % self.transaction_count, self.db) as self.trans: self.transaction_count += 1 - person1_h = self.generate_person(Person.MALE,"Broken8",None) - person2_h = self.generate_person(Person.FEMALE,"Broken8",None) - child_h = self.generate_person(None,"Broken8",None) + person1_h = self.generate_person(Person.MALE, "Broken8", None) + person2_h = self.generate_person(Person.FEMALE, "Broken8", None) + child_h = self.generate_person(None, "Broken8", None) fam = Family() fam.set_father_handle(person1_h) fam.set_mother_handle(person2_h) - fam.set_relationship((FamilyRelType.MARRIED,'')) + fam.set_relationship((FamilyRelType.MARRIED, '')) child_ref = ChildRef() child_ref.set_reference_handle(child_h) self.fill_object(child_ref) fam.add_child_ref(child_ref) - fam_h = self.db.add_family(fam,self.trans) + fam_h = self.db.add_family(fam, self.trans) person1 = self.db.get_person_from_handle(person1_h) person1.add_family_handle(fam_h) - self.db.commit_person(person1,self.trans) + self.db.commit_person(person1, self.trans) person2 = self.db.get_person_from_handle(person2_h) person2.add_family_handle(fam_h) - self.db.commit_person(person2,self.trans) - #child = self.db.get_person_from_handle(child_h) - #person2.add_parent_family_handle(fam_h) - #self.db.commit_person(child,self.trans) + self.db.commit_person(person2, self.trans) + # child = self.db.get_person_from_handle(child_h) + # person2.add_parent_family_handle(fam_h) + # self.db.commit_person(child, self.trans) - # Creates a family where the child is not linked, but the child links to the family + # Creates a family where the child is not linked, but the child links + # to the family with DbTxn(_("Testcase generator step %d") % self.transaction_count, self.db) as self.trans: self.transaction_count += 1 - person1_h = self.generate_person(Person.MALE,"Broken9",None) - person2_h = self.generate_person(Person.FEMALE,"Broken9",None) - child_h = self.generate_person(None,"Broken9",None) + person1_h = self.generate_person(Person.MALE, "Broken9", None) + person2_h = self.generate_person(Person.FEMALE, "Broken9", None) + child_h = self.generate_person(None, "Broken9", None) fam = Family() fam.set_father_handle(person1_h) fam.set_mother_handle(person2_h) - fam.set_relationship((FamilyRelType.MARRIED,'')) + fam.set_relationship((FamilyRelType.MARRIED, '')) # child_ref = ChildRef() # child_ref.set_reference_handle(child_h) # self.fill_object(child_ref) # fam.add_child_ref(child_ref) - fam_h = self.db.add_family(fam,self.trans) + fam_h = self.db.add_family(fam, self.trans) person1 = self.db.get_person_from_handle(person1_h) person1.add_family_handle(fam_h) - self.db.commit_person(person1,self.trans) + self.db.commit_person(person1, self.trans) person2 = self.db.get_person_from_handle(person2_h) person2.add_family_handle(fam_h) - self.db.commit_person(person2,self.trans) + self.db.commit_person(person2, self.trans) child = self.db.get_person_from_handle(child_h) child.add_parent_family_handle(fam_h) - self.db.commit_person(child,self.trans) + self.db.commit_person(child, self.trans) # Creates a family where the child is one of the parents with DbTxn(_("Testcase generator step %d") % self.transaction_count, self.db) as self.trans: self.transaction_count += 1 - person1_h = self.generate_person(Person.MALE,"Broken19",None) - person2_h = self.generate_person(Person.FEMALE,"Broken19",None) + person1_h = self.generate_person(Person.MALE, "Broken19", None) + person2_h = self.generate_person(Person.FEMALE, "Broken19", None) child_h = person2_h fam = Family() fam.set_father_handle(person1_h) fam.set_mother_handle(person2_h) - fam.set_relationship((FamilyRelType.MARRIED,'')) + fam.set_relationship((FamilyRelType.MARRIED, '')) child_ref = ChildRef() child_ref.set_reference_handle(child_h) self.fill_object(child_ref) fam.add_child_ref(child_ref) - fam_h = self.db.add_family(fam,self.trans) + fam_h = self.db.add_family(fam, self.trans) person1 = self.db.get_person_from_handle(person1_h) person1.add_family_handle(fam_h) - self.db.commit_person(person1,self.trans) + self.db.commit_person(person1, self.trans) person2 = self.db.get_person_from_handle(person2_h) person2.add_family_handle(fam_h) - self.db.commit_person(person2,self.trans) + self.db.commit_person(person2, self.trans) child = self.db.get_person_from_handle(child_h) child.add_parent_family_handle(fam_h) - self.db.commit_person(child,self.trans) + self.db.commit_person(child, self.trans) # Creates a couple that refer to a family that does not exist in the # database. with DbTxn(_("Testcase generator step %d") % self.transaction_count, self.db) as self.trans: self.transaction_count += 1 - person1_h = self.generate_person(Person.MALE,"Broken20",None) - person2_h = self.generate_person(Person.FEMALE,"Broken20",None) + person1_h = self.generate_person(Person.MALE, "Broken20", None) + person2_h = self.generate_person(Person.FEMALE, "Broken20", None) # fam = Family() # fam.set_father_handle(person1_h) # fam.set_mother_handle(person2_h) -# fam.set_relationship((FamilyRelType.MARRIED,'')) +# fam.set_relationship((FamilyRelType.MARRIED, '')) # child_ref = ChildRef() # # child_ref.set_reference_handle(child_h) # # self.fill_object(child_ref) # # fam.add_child_ref(child_ref) -# fam_h = self.db.add_family(fam,self.trans) +# fam_h = self.db.add_family(fam, self.trans) person1 = self.db.get_person_from_handle(person1_h) person1.add_family_handle("InvalidHandle3") - self.db.commit_person(person1,self.trans) + self.db.commit_person(person1, self.trans) person2 = self.db.get_person_from_handle(person2_h) person2.add_family_handle("InvalidHandle3") - self.db.commit_person(person2,self.trans) + self.db.commit_person(person2, self.trans) # child = self.db.get_person_from_handle(child_h) # child.add_parent_family_handle(fam_h) -# self.db.commit_person(child,self.trans) +# self.db.commit_person(child, self.trans) def test_check_parent_relationships(self): pass @@ -834,87 +875,88 @@ class TestcaseGenerator(tool.BatchTool): pass def test_check_events(self): + """ Various event related tests """ # Creates a person having a non existing birth event handle set with DbTxn(_("Testcase generator step %d") % self.transaction_count, self.db) as self.trans: self.transaction_count += 1 - person_h = self.generate_person(None,"Broken11",None) + person_h = self.generate_person(None, "Broken11", None) person = self.db.get_person_from_handle(person_h) event_ref = EventRef() event_ref.set_reference_handle("InvalidHandle4") person.set_birth_ref(event_ref) - self.db.commit_person(person,self.trans) + self.db.commit_person(person, self.trans) # Creates a person having a non existing death event handle set with DbTxn(_("Testcase generator step %d") % self.transaction_count, self.db) as self.trans: self.transaction_count += 1 - person_h = self.generate_person(None,"Broken12",None) + person_h = self.generate_person(None, "Broken12", None) person = self.db.get_person_from_handle(person_h) event_ref = EventRef() event_ref.set_reference_handle("InvalidHandle5") person.set_death_ref(event_ref) - self.db.commit_person(person,self.trans) + self.db.commit_person(person, self.trans) # Creates a person having a non existing event handle set with DbTxn(_("Testcase generator step %d") % self.transaction_count, self.db) as self.trans: self.transaction_count += 1 - person_h = self.generate_person(None,"Broken13",None) + person_h = self.generate_person(None, "Broken13", None) person = self.db.get_person_from_handle(person_h) event_ref = EventRef() event_ref.set_reference_handle("InvalidHandle6") person.add_event_ref(event_ref) - self.db.commit_person(person,self.trans) + self.db.commit_person(person, self.trans) # Creates a person with a birth event having an empty type with DbTxn(_("Testcase generator step %d") % self.transaction_count, self.db) as self.trans: self.transaction_count += 1 - person_h = self.generate_person(None,"Broken14",None) + person_h = self.generate_person(None, "Broken14", None) event = Event() # The default type _DEFAULT = BIRTH is set in eventtype event.set_type('') event.set_description("Test for Broken14") - event_h = self.db.add_event(event,self.trans) + event_h = self.db.add_event(event, self.trans) event_ref = EventRef() event_ref.set_reference_handle(event_h) person = self.db.get_person_from_handle(person_h) person.set_birth_ref(event_ref) - self.db.commit_person(person,self.trans) + self.db.commit_person(person, self.trans) # Creates a person with a death event having an empty type with DbTxn(_("Testcase generator step %d") % self.transaction_count, self.db) as self.trans: self.transaction_count += 1 - person_h = self.generate_person(None,"Broken15",None) + person_h = self.generate_person(None, "Broken15", None) event = Event() # The default type _DEFAULT = BIRTH is set in eventtype event.set_type('') event.set_description("Test for Broken15") - event_h = self.db.add_event(event,self.trans) + event_h = self.db.add_event(event, self.trans) event_ref = EventRef() event_ref.set_reference_handle(event_h) person = self.db.get_person_from_handle(person_h) person.set_death_ref(event_ref) - self.db.commit_person(person,self.trans) + self.db.commit_person(person, self.trans) # Creates a person with an event having an empty type # This is NOT detected as an error by plugins/tool/Check.py with DbTxn(_("Testcase generator step %d") % self.transaction_count, self.db) as self.trans: self.transaction_count += 1 - person_h = self.generate_person(None,"Broken16",None) + person_h = self.generate_person(None, "Broken16", None) event = Event() # The default type _DEFAULT = BIRTH is set in eventtype event.set_type('') event.set_description("Test for Broken16") - event_h = self.db.add_event(event,self.trans) + event_h = self.db.add_event(event, self.trans) event_ref = EventRef() event_ref.set_reference_handle(event_h) person = self.db.get_person_from_handle(person_h) person.add_event_ref(event_ref) - self.db.commit_person(person,self.trans) + self.db.commit_person(person, self.trans) def test_check_person_references(self): pass @@ -923,73 +965,74 @@ class TestcaseGenerator(tool.BatchTool): pass def test_check_place_references(self): + """ Tests various place reference errors """ # Creates a person with a birth event pointing to nonexisting place with DbTxn(_("Testcase generator step %d") % self.transaction_count, self.db) as self.trans: self.transaction_count += 1 - person_h = self.generate_person(None,"Broken17",None) + person_h = self.generate_person(None, "Broken17", None) event = Event() event.set_type(EventType.BIRTH) event.set_place_handle("InvalidHandle7") event.set_description("Test for Broken17") - event_h = self.db.add_event(event,self.trans) + event_h = self.db.add_event(event, self.trans) event_ref = EventRef() event_ref.set_reference_handle(event_h) person = self.db.get_person_from_handle(person_h) person.set_birth_ref(event_ref) - self.db.commit_person(person,self.trans) + self.db.commit_person(person, self.trans) # Creates a person with an event pointing to nonexisting place with DbTxn(_("Testcase generator step %d") % self.transaction_count, self.db) as self.trans: self.transaction_count += 1 - person_h = self.generate_person(None,"Broken18",None) + person_h = self.generate_person(None, "Broken18", None) event = Event() event.set_type(EventType.BIRTH) event.set_place_handle("InvalidHandle8") event.set_description("Test for Broken18") - event_h = self.db.add_event(event,self.trans) + event_h = self.db.add_event(event, self.trans) event_ref = EventRef() event_ref.set_reference_handle(event_h) person = self.db.get_person_from_handle(person_h) person.add_event_ref(event_ref) - self.db.commit_person(person,self.trans) + self.db.commit_person(person, self.trans) def test_check_source_references(self): - + """ Tests various source reference errors """ with DbTxn(_("Testcase generator step %d") % self.transaction_count, self.db) as self.trans: self.transaction_count += 1 - c = Citation() - self.fill_object(c) - c.set_reference_handle("unknownsourcehandle") - c.set_page('unreferenced citation with invalid source ref') - self.db.add_citation(c, self.trans) + cit = Citation() + self.fill_object(cit) + cit.set_reference_handle("unknownsourcehandle") + cit.set_page('unreferenced citation with invalid source ref') + self.db.add_citation(cit, self.trans) - c = Citation() - self.fill_object(c) - c.set_reference_handle(None) - c.set_page('unreferenced citation with invalid source ref') - self.db.add_citation(c, self.trans) + cit = Citation() + self.fill_object(cit) + cit.set_reference_handle(None) + cit.set_page('unreferenced citation with invalid source ref') + self.db.add_citation(cit, self.trans) - c = Citation() - self.fill_object(c) - c.set_reference_handle("unknownsourcehandle") - c.set_page('citation and references to it should be removed') - c_h1 = self.db.add_citation(c, self.trans) + cit = Citation() + self.fill_object(cit) + cit.set_reference_handle("unknownsourcehandle") + cit.set_page('citation and references to it should be removed') + c_h1 = self.db.add_citation(cit, self.trans) - c = Citation() - self.fill_object(c) - c.set_reference_handle(None) - c.set_page('citation and references to it should be removed') - c_h2 = self.db.add_citation(c, self.trans) + cit = Citation() + self.fill_object(cit) + cit.set_reference_handle(None) + cit.set_page('citation and references to it should be removed') + c_h2 = self.db.add_citation(cit, self.trans) self.create_all_possible_citations([c_h1, c_h2], "Broken21", 'non-existent source') def test_check_citation_references(self): - # Generate objects that refer to non-existant citations + """ Generate objects that refer to non-existant citations """ with DbTxn(_("Testcase generator step %d") % self.transaction_count, self.db) as self.trans: self.transaction_count += 1 @@ -999,65 +1042,66 @@ class TestcaseGenerator(tool.BatchTool): 'non-existent citation') def create_all_possible_citations(self, c_h_list, name, message): - # Create citations attached to each of the following objects: - # Person - # Name - # Address - # Attribute - # PersonRef - # MediaRef - # Attribute - # LdsOrd - # - # Family - # Attribute - # ChildRef - # MediaRef - # Attribute - # LdsOrd - # - # Event - # Attribute - # MediaRef - # Attribute - # - # Media - # Attribute - # - # Place - # MediaRef - # Attribute - # - # Repository (Repositories themselves do not have SourceRefs) - # Address - m = Media() - m.set_description(message) - m.set_path(os.path.abspath(str(ICON))) - m.set_mime_type(get_type(m.get_path())) - m.add_citation(_choice(c_h_list)) - # Media : Attribute - a = Attribute() - a.set_type(self.rand_type(AttributeType())) - a.set_value(message) - a.add_citation(_choice(c_h_list)) - m.add_attribute(a) - self.db.add_media(m, self.trans) + """ Create citations attached to each of the following objects: + Person + Name + Address + Attribute + PersonRef + MediaRef + Attribute + LdsOrd - person1_h = self.generate_person(Person.MALE,name,None) - person2_h = self.generate_person(Person.FEMALE,name,None) - child_h = self.generate_person(None,name,None) + Family + Attribute + ChildRef + MediaRef + Attribute + LdsOrd + + Event + Attribute + MediaRef + Attribute + + Media + Attribute + + Place + MediaRef + Attribute + + Repository (Repositories themselves do not have SourceRefs) + Address + """ + med = Media() + med.set_description(message) + med.set_path(os.path.abspath(str(ICON))) + med.set_mime_type(get_type(med.get_path())) + med.add_citation(_choice(c_h_list)) + # Media : Attribute + att = Attribute() + att.set_type(self.rand_type(AttributeType())) + att.set_value(message) + att.add_citation(_choice(c_h_list)) + med.add_attribute(att) + self.db.add_media(med, self.trans) + + person1_h = self.generate_person(Person.MALE, name, None) + person2_h = self.generate_person(Person.FEMALE, name, None) + child_h = self.generate_person(None, name, None) fam = Family() fam.set_father_handle(person1_h) fam.set_mother_handle(person2_h) - fam.set_relationship((FamilyRelType.MARRIED,'')) + fam.set_relationship((FamilyRelType.MARRIED, '')) # Family fam.add_citation(_choice(c_h_list)) # Family : Attribute - a = Attribute() - a.set_type(self.rand_type(AttributeType())) - a.set_value(message) - a.add_citation(_choice(c_h_list)) - fam.add_attribute(a) + att = Attribute() + att.set_type(self.rand_type(AttributeType())) + att.set_value(message) + att.add_citation(_choice(c_h_list)) + fam.add_attribute(att) # Family : ChildRef child_ref = ChildRef() child_ref.set_reference_handle(child_h) @@ -1065,44 +1109,45 @@ class TestcaseGenerator(tool.BatchTool): child_ref.add_citation(_choice(c_h_list)) fam.add_child_ref(child_ref) # Family : MediaRef - mr = MediaRef() - mr.set_reference_handle(m.handle) - mr.add_citation(_choice(c_h_list)) + mref = MediaRef() + mref.set_reference_handle(med.handle) + mref.add_citation(_choice(c_h_list)) # Family : MediaRef : Attribute - a = Attribute() - a.set_type(self.rand_type(AttributeType())) - a.set_value(message) - a.add_citation(_choice(c_h_list)) - mr.add_attribute(a) - fam.add_media_reference(mr) + att = Attribute() + att.set_type(self.rand_type(AttributeType())) + att.set_value(message) + att.add_citation(_choice(c_h_list)) + mref.add_attribute(att) + fam.add_media_reference(mref) # Family : LDSORD ldsord = LdsOrd() - self.fill_object( ldsord) + self.fill_object(ldsord) # TODO: adapt type and status to family/person - #if isinstance(o,Person): - #if isinstance(o,Family): + # if isinstance(obj, Person): + # if isinstance(obj, Family): + # pylint: disable=protected-access ldsord.set_type(_choice([item[0] for item in LdsOrd._TYPE_MAP])) - ldsord.set_status(_randint(0, len(LdsOrd._STATUS_MAP)-1)) + ldsord.set_status(_randint(0, len(LdsOrd._STATUS_MAP) - 1)) ldsord.add_citation(_choice(c_h_list)) fam.add_lds_ord(ldsord) # Family : EventRef - e = Event() - e.set_type(EventType.MARRIAGE) - (year, d) = self.rand_date() - e.set_date_object(d) - e.set_description(message) - event_h = self.db.add_event(e, self.trans) - er = EventRef() - er.set_reference_handle(event_h) - er.set_role(self.rand_type(EventRoleType())) + evt = Event() + evt.set_type(EventType.MARRIAGE) + (dummy, date) = self.rand_date() + evt.set_date_object(date) + evt.set_description(message) + event_h = self.db.add_event(evt, self.trans) + eref = EventRef() + eref.set_reference_handle(event_h) + eref.set_role(self.rand_type(EventRoleType())) # Family : EventRef : Attribute - a = Attribute() - a.set_type(self.rand_type(AttributeType())) - a.set_value(message) - a.add_citation(_choice(c_h_list)) - er.add_attribute(a) - fam.add_event_ref(er) - fam_h = self.db.add_family(fam,self.trans) + att = Attribute() + att.set_type(self.rand_type(AttributeType())) + att.set_value(message) + att.add_citation(_choice(c_h_list)) + eref.add_attribute(att) + fam.add_event_ref(eref) + fam_h = self.db.add_family(fam, self.trans) person1 = self.db.get_person_from_handle(person1_h) person1.add_family_handle(fam_h) # Person @@ -1113,16 +1158,16 @@ class TestcaseGenerator(tool.BatchTool): alt_name.add_citation(_choice(c_h_list)) person1.add_alternate_name(alt_name) # Person : Address - a = Address() - a.set_street(message) - a.add_citation(_choice(c_h_list)) - person1.add_address(a) + add = Address() + add.set_street(message) + add.add_citation(_choice(c_h_list)) + person1.add_address(add) # Person : Attribute - a = Attribute() - a.set_type(self.rand_type(AttributeType())) - a.set_value(message) - a.add_citation(_choice(c_h_list)) - person1.add_attribute(a) + att = Attribute() + att.set_type(self.rand_type(AttributeType())) + att.set_value(message) + att.add_citation(_choice(c_h_list)) + person1.add_attribute(att) # Person : PersonRef asso_h = self.generate_person() asso = PersonRef() @@ -1132,98 +1177,98 @@ class TestcaseGenerator(tool.BatchTool): asso.add_citation(_choice(c_h_list)) person1.add_person_ref(asso) # Person : MediaRef - mr = MediaRef() - mr.set_reference_handle(m.handle) - mr.add_citation(_choice(c_h_list)) + mref = MediaRef() + mref.set_reference_handle(med.handle) + mref.add_citation(_choice(c_h_list)) # Person : MediaRef : Attribute - a = Attribute() - a.set_type(self.rand_type(AttributeType())) - a.set_value(self.rand_text(self.SHORT)) - a.add_citation(_choice(c_h_list)) - mr.add_attribute(a) - person1.add_media_reference(mr) + att = Attribute() + att.set_type(self.rand_type(AttributeType())) + att.set_value(self.rand_text(self.SHORT)) + att.add_citation(_choice(c_h_list)) + mref.add_attribute(att) + person1.add_media_reference(mref) # Person : LDSORD ldsord = LdsOrd() - self.fill_object( ldsord) + self.fill_object(ldsord) # TODO: adapt type and status to family/person - #if isinstance(o,Person): - #if isinstance(o,Family): + # if isinstance(obj, Person): + # if isinstance(obj, Family): ldsord.set_type(_choice( - [item[0] for item in LdsOrd._TYPE_MAP] )) - ldsord.set_status(_randint(0, len(LdsOrd._STATUS_MAP)-1)) + [item[0] for item in LdsOrd._TYPE_MAP])) + ldsord.set_status(_randint(0, len(LdsOrd._STATUS_MAP) - 1)) ldsord.add_citation(_choice(c_h_list)) person1.add_lds_ord(ldsord) # Person : EventRef - e = Event() - e.set_type(EventType.ELECTED) - (year, d) = self.rand_date() - e.set_date_object(d) - e.set_description(message) - event_h = self.db.add_event(e, self.trans) - er = EventRef() - er.set_reference_handle(event_h) - er.set_role(self.rand_type(EventRoleType())) + evt = Event() + evt.set_type(EventType.ELECTED) + (dummy, dat) = self.rand_date() + evt.set_date_object(dat) + evt.set_description(message) + event_h = self.db.add_event(evt, self.trans) + eref = EventRef() + eref.set_reference_handle(event_h) + eref.set_role(self.rand_type(EventRoleType())) # Person : EventRef : Attribute - a = Attribute() - a.set_type(self.rand_type(AttributeType())) - a.set_value(message) - a.add_citation(_choice(c_h_list)) - er.add_attribute(a) - person1.add_event_ref(er) - self.db.commit_person(person1,self.trans) + att = Attribute() + att.set_type(self.rand_type(AttributeType())) + att.set_value(message) + att.add_citation(_choice(c_h_list)) + eref.add_attribute(att) + person1.add_event_ref(eref) + self.db.commit_person(person1, self.trans) person2 = self.db.get_person_from_handle(person2_h) person2.add_family_handle(fam_h) - self.db.commit_person(person2,self.trans) + self.db.commit_person(person2, self.trans) - e = Event() - e.set_description(message) - e.set_type(EventType.MARRIAGE) + evt = Event() + evt.set_description(message) + evt.set_type(EventType.MARRIAGE) # Event - e.add_citation(_choice(c_h_list)) + evt.add_citation(_choice(c_h_list)) # Event : Attribute - a = Attribute() - a.set_type(self.rand_type(AttributeType())) - a.set_value(message) - a.add_citation(_choice(c_h_list)) - e.add_attribute(a) + att = Attribute() + att.set_type(self.rand_type(AttributeType())) + att.set_value(message) + att.add_citation(_choice(c_h_list)) + evt.add_attribute(att) # Event : MediaRef - mr = MediaRef() - mr.set_reference_handle(m.handle) - mr.add_citation(_choice(c_h_list)) + mref = MediaRef() + mref.set_reference_handle(med.handle) + mref.add_citation(_choice(c_h_list)) # Event : MediaRef : Attribute - a = Attribute() - a.set_type(self.rand_type(AttributeType())) - a.set_value(self.rand_text(self.SHORT)) - a.add_citation(_choice(c_h_list)) - mr.add_attribute(a) - e.add_media_reference(mr) - self.db.add_event(e, self.trans) + att = Attribute() + att.set_type(self.rand_type(AttributeType())) + att.set_value(self.rand_text(self.SHORT)) + att.add_citation(_choice(c_h_list)) + mref.add_attribute(att) + evt.add_media_reference(mref) + self.db.add_event(evt, self.trans) - p = Place() - p.set_title(message) - p.add_citation(_choice(c_h_list)) + place = Place() + place.set_title(message) + place.add_citation(_choice(c_h_list)) # Place : MediaRef - mr = MediaRef() - mr.set_reference_handle(m.handle) - mr.add_citation(_choice(c_h_list)) + mref = MediaRef() + mref.set_reference_handle(med.handle) + mref.add_citation(_choice(c_h_list)) # Place : MediaRef : Attribute - a = Attribute() - a.set_type(self.rand_type(AttributeType())) - a.set_value(self.rand_text(self.SHORT)) - a.add_citation(_choice(c_h_list)) - mr.add_attribute(a) - p.add_media_reference(mr) - self.db.add_place(p, self.trans) + att = Attribute() + att.set_type(self.rand_type(AttributeType())) + att.set_value(self.rand_text(self.SHORT)) + att.add_citation(_choice(c_h_list)) + mref.add_attribute(att) + place.add_media_reference(mref) + self.db.add_place(place, self.trans) - r = Repository() - r.set_name(message) - r.set_type(RepositoryType.LIBRARY) + ref = Repository() + ref.set_name(message) + ref.set_type(RepositoryType.LIBRARY) # Repository : Address - a = Address() - a.set_street(message) - a.add_citation(_choice(c_h_list)) - r.add_address(a) - self.db.add_repository(r, self.trans) + add = Address() + add.set_street(message) + add.add_citation(_choice(c_h_list)) + ref.add_address(add) + self.db.add_repository(ref, self.trans) def test_check_media_references(self): pass @@ -1234,39 +1279,41 @@ class TestcaseGenerator(tool.BatchTool): def test_check_note_references(self): pass - - def generate_person(self,gender=None,lastname=None, note=None, alive_in_year=None): + def generate_person(self, gender=None, lastname=None, note=None, + alive_in_year=None): + """ This generates a person with lots of attachments """ if not self.cli: if self.person_count % 10 == 0: while Gtk.events_pending(): Gtk.main_iteration() - np = Person() - self.fill_object(np) + pers = Person() + self.fill_object(pers) # Gender if gender is None: gender = _randint(0, 1) if _randint(0, 10) == 1: # Set some persons to unknown gender - np.set_gender(Person.UNKNOWN) + pers.set_gender(Person.UNKNOWN) else: - np.set_gender(gender) + pers.set_gender(gender) # Name name = Name() - (firstname,lastname) = self.rand_name(lastname, gender) + (firstname, lastname) = self.rand_name(lastname, gender) name.set_first_name(firstname) surname = Surname() surname.set_surname(lastname) name.add_surname(surname) - self.fill_object( name) - np.set_primary_name(name) + self.fill_object(name) + pers.set_primary_name(name) # generate some slightly different alternate name - firstname2 = firstname.replace("m", "n").replace("l", "i").replace("b", "d") + firstname2 = \ + firstname.replace("m", "n").replace("l", "i").replace("b", "d") if firstname2 != firstname: alt_name = Name(name) - self.fill_object( alt_name) + self.fill_object(alt_name) if _randint(0, 2) == 1: surname = Surname() surname.set_surname(self.rand_text(self.LASTNAME)) @@ -1276,135 +1323,145 @@ class TestcaseGenerator(tool.BatchTool): surname.set_surname(lastname) alt_name.add_surname(surname) if _randint(0, 1) == 1: - alt_name.set_first_name( firstname2) + alt_name.set_first_name(firstname2) if _randint(0, 1) == 1: - alt_name.set_title( self.rand_text(self.SHORT)) - if _randint(0, 1) == 1: - patronymic = Surname() - patronymic.set_surname( self.rand_text(self.FIRSTNAME_MALE)) - patronymic.set_origintype(NameOriginType.PATRONYMIC) - alt_name.add_surname(patronymic) - if _randint(0, 1) == 1: - alt_name.get_primary_surname().set_prefix( self.rand_text(self.SHORT)) - if _randint(0, 1) == 1: - alt_name.set_suffix( self.rand_text(self.SHORT)) - if _randint(0, 1) == 1: - alt_name.set_call_name( self.rand_text(self.FIRSTNAME)) - np.add_alternate_name( alt_name) - firstname2 = firstname.replace("a", "e").replace("o", "u").replace("r", "p") - if firstname2 != firstname: - alt_name = Name(name) - self.fill_object( alt_name) - if _randint(0, 2) == 1: - surname = Surname() - surname.set_surname(self.rand_text(self.LASTNAME)) - alt_name.add_surname(surname) - elif _randint(0, 2) == 1: - surname = Surname() - surname.set_surname(lastname) - alt_name.add_surname(surname) - if _randint(0, 1) == 1: - alt_name.set_first_name( firstname2) - if _randint(0, 1) == 1: - alt_name.set_title( self.rand_text(self.SHORT)) + alt_name.set_title(self.rand_text(self.SHORT)) if _randint(0, 1) == 1: patronymic = Surname() patronymic.set_surname(self.rand_text(self.FIRSTNAME_MALE)) patronymic.set_origintype(NameOriginType.PATRONYMIC) alt_name.add_surname(patronymic) if _randint(0, 1) == 1: - alt_name.get_primary_surname().set_prefix( self.rand_text(self.SHORT)) + alt_name.get_primary_surname().set_prefix( + self.rand_text(self.SHORT)) if _randint(0, 1) == 1: - alt_name.set_suffix( self.rand_text(self.SHORT)) + alt_name.set_suffix(self.rand_text(self.SHORT)) if _randint(0, 1) == 1: - alt_name.set_call_name( self.rand_text(self.FIRSTNAME)) - np.add_alternate_name( alt_name) + alt_name.set_call_name(self.rand_text(self.FIRSTNAME)) + pers.add_alternate_name(alt_name) + firstname2 = \ + firstname.replace("a", "e").replace("o", "u").replace("r", "p") + if firstname2 != firstname: + alt_name = Name(name) + self.fill_object(alt_name) + if _randint(0, 2) == 1: + surname = Surname() + surname.set_surname(self.rand_text(self.LASTNAME)) + alt_name.add_surname(surname) + elif _randint(0, 2) == 1: + surname = Surname() + surname.set_surname(lastname) + alt_name.add_surname(surname) + if _randint(0, 1) == 1: + alt_name.set_first_name(firstname2) + if _randint(0, 1) == 1: + alt_name.set_title(self.rand_text(self.SHORT)) + if _randint(0, 1) == 1: + patronymic = Surname() + patronymic.set_surname(self.rand_text(self.FIRSTNAME_MALE)) + patronymic.set_origintype(NameOriginType.PATRONYMIC) + alt_name.add_surname(patronymic) + if _randint(0, 1) == 1: + alt_name.get_primary_surname().set_prefix( + self.rand_text(self.SHORT)) + if _randint(0, 1) == 1: + alt_name.set_suffix(self.rand_text(self.SHORT)) + if _randint(0, 1) == 1: + alt_name.set_call_name(self.rand_text(self.FIRSTNAME)) + pers.add_alternate_name(alt_name) if not alive_in_year: alive_in_year = _randint(1700, 2000) - by = alive_in_year - _randint(0, 60) - dy = alive_in_year + _randint(0, 60) + b_y = alive_in_year - _randint(0, 60) + d_y = alive_in_year + _randint(0, 60) # birth if _randint(0, 1) == 1: - (birth_year, eref) = self.rand_personal_event( EventType.BIRTH, by,by) - np.set_birth_ref(eref) + (dummy, eref) = self.rand_personal_event(EventType.BIRTH, b_y, b_y) + pers.set_birth_ref(eref) # baptism if _randint(0, 1) == 1: - (bapt_year, eref) = self.rand_personal_event( - _choice((EventType.BAPTISM, EventType.CHRISTEN)), by, by+2) - np.add_event_ref(eref) + (dummy, eref) = self.rand_personal_event( + _choice((EventType.BAPTISM, EventType.CHRISTEN)), b_y, b_y + 2) + pers.add_event_ref(eref) # death - death_year = None if _randint(0, 1) == 1: - (death_year, eref) = self.rand_personal_event( EventType.DEATH, dy,dy) - np.set_death_ref(eref) + (dummy, eref) = self.rand_personal_event(EventType.DEATH, d_y, d_y) + pers.set_death_ref(eref) # burial if _randint(0, 1) == 1: - (bur_year, eref) = self.rand_personal_event( - _choice((EventType.BURIAL, EventType.CREMATION)), dy, dy+2) - np.add_event_ref(eref) + (dummy, eref) = self.rand_personal_event( + _choice((EventType.BURIAL, EventType.CREMATION)), d_y, d_y + 2) + pers.add_event_ref(eref) # some other events while _randint(0, 5) == 1: - (birth_year, eref) = self.rand_personal_event( None, by,dy) - np.add_event_ref(eref) + (dummy, eref) = self.rand_personal_event(None, b_y, d_y) + pers.add_event_ref(eref) # some shared events if self.generated_events: while _randint(0, 5) == 1: e_h = _choice(self.generated_events) eref = EventRef() - self.fill_object( eref) + self.fill_object(eref) eref.set_reference_handle(e_h) - np.add_event_ref(eref) + pers.add_event_ref(eref) # PersonRef if _randint(0, 3) == 1: - for i in range(0, _randint(1, 2)): - if self.person_count > self.options.handler.options_dict['person_count']: + for dummy in range(0, _randint(1, 2)): + if self.person_count > self.max_person_count: break if alive_in_year: - asso_h = self.generate_person(None, None, alive_in_year = alive_in_year) + asso_h = self.generate_person(None, None, + alive_in_year=alive_in_year) else: asso_h = self.generate_person() asso = PersonRef() asso.set_reference_handle(asso_h) asso.set_relation(self.rand_text(self.SHORT)) self.fill_object(asso) - np.add_person_ref(asso) + pers.add_person_ref(asso) if _randint(0, 2) == 0: self.persons_todo.append(asso_h) - person_handle = self.db.add_person(np,self.trans) + # Note + if note: + pass # Add later? - self.person_count = self.person_count+1 + person_handle = self.db.add_person(pers, self.trans) + + self.person_count = self.person_count + 1 self.progress_step() if self.person_count % 10 == 1: print("person count", self.person_count) - self.person_dates[person_handle] = (by,dy) + self.person_dates[person_handle] = (b_y, d_y) - return( person_handle) + return person_handle - def generate_family(self,person1_h): + def generate_family(self, person1_h): + """ Make up a family """ person1 = self.db.get_person_from_handle(person1_h) if not person1: return alive_in_year = None if person1_h in self.person_dates: (born, died) = self.person_dates[person1_h] - alive_in_year = min(born+_randint(10, 50), died+_randint(-10, 10)) + alive_in_year = min(born + _randint(10, 50), + died + _randint(-10, 10)) if person1.get_gender() == 1: if _randint(0, 7) == 1: person2_h = None else: if alive_in_year: - person2_h = self.generate_person(0, alive_in_year = alive_in_year) + person2_h = \ + self.generate_person(0, alive_in_year=alive_in_year) else: person2_h = self.generate_person(0) else: @@ -1413,7 +1470,8 @@ class TestcaseGenerator(tool.BatchTool): person1_h = None else: if alive_in_year: - person1_h = self.generate_person(1, alive_in_year = alive_in_year) + person1_h = \ + self.generate_person(1, alive_in_year=alive_in_year) else: person1_h = self.generate_person(1) @@ -1437,13 +1495,13 @@ class TestcaseGenerator(tool.BatchTool): # Generate at least one family event with a probability of 75% if _randint(0, 3) > 0: - (birth_year, eref) = self.rand_family_event(None) + (dummy, eref) = self.rand_family_event(None) fam.add_event_ref(eref) event_set.add(eref.get_reference_handle()) # generate some more events with a lower probability while _randint(0, 3) == 1: - (birth_year, eref) = self.rand_family_event(None) + (dummy, eref) = self.rand_family_event(None) if eref.get_reference_handle() in event_set: continue fam.add_event_ref(eref) @@ -1459,64 +1517,68 @@ class TestcaseGenerator(tool.BatchTool): if e_h in event_set: break eref = EventRef() - self.fill_object( eref) + self.fill_object(eref) eref.set_reference_handle(e_h) fam.add_event_ref(eref) event_set.add(e_h) - fam_h = self.db.add_family(fam,self.trans) + fam_h = self.db.add_family(fam, self.trans) self.generated_families.append(fam_h) - fam = self.db.commit_family(fam,self.trans) + fam = self.db.commit_family(fam, self.trans) if person1_h: person1 = self.db.get_person_from_handle(person1_h) person1.add_family_handle(fam_h) - self.db.commit_person(person1,self.trans) + self.db.commit_person(person1, self.trans) if person2_h: person2 = self.db.get_person_from_handle(person2_h) person2.add_family_handle(fam_h) - self.db.commit_person(person2,self.trans) + self.db.commit_person(person2, self.trans) lastname = person1.get_primary_name().get_surname() for i in range(0, _randint(1, 10)): - if self.person_count > self.options.handler.options_dict['person_count']: + if self.person_count > self.max_person_count: break if alive_in_year: - child_h = self.generate_person(None, lastname, - alive_in_year=alive_in_year + _randint(16+2*i, 30+2*i)) + child_h = self.generate_person( + None, lastname, + alive_in_year=alive_in_year + + _randint(16 + 2 * i, 30 + 2 * i)) else: child_h = self.generate_person(None, lastname) - (born,died) = self.person_dates[child_h] + (born, died) = self.person_dates[child_h] alive_in_year = born fam = self.db.get_family_from_handle(fam_h) child_ref = ChildRef() child_ref.set_reference_handle(child_h) self.fill_object(child_ref) fam.add_child_ref(child_ref) - self.db.commit_family(fam,self.trans) + self.db.commit_family(fam, self.trans) child = self.db.get_person_from_handle(child_h) child.add_parent_family_handle(fam_h) - self.db.commit_person(child,self.trans) + self.db.commit_person(child, self.trans) if _randint(0, 3) > 0: self.persons_todo.append(child_h) - def generate_parents(self,child_h): + def generate_parents(self, child_h): + """ Add parents to a person, if not present already""" if not child_h: return child = self.db.get_person_from_handle(child_h) if not child: - print("ERROR: Person handle %s does not exist in database" % child_h) + print("ERROR: Person handle %s does not exist in database" % + child_h) return if child.get_parent_family_handle_list(): return lastname = child.get_primary_name().get_surname() if child_h in self.person_dates: - (born,died) = self.person_dates[child_h] - person1_h = self.generate_person(1,lastname, alive_in_year=born) + (born, dummy) = self.person_dates[child_h] + person1_h = self.generate_person(1, lastname, alive_in_year=born) person2_h = self.generate_person(0, alive_in_year=born) else: - person1_h = self.generate_person(1,lastname) + person1_h = self.generate_person(1, lastname) person2_h = self.generate_person(0) if _randint(0, 2) > 1: @@ -1535,23 +1597,24 @@ class TestcaseGenerator(tool.BatchTool): child_ref.set_reference_handle(child_h) self.fill_object(child_ref) fam.add_child_ref(child_ref) - fam_h = self.db.add_family(fam,self.trans) + fam_h = self.db.add_family(fam, self.trans) self.generated_families.append(fam_h) - fam = self.db.commit_family(fam,self.trans) + fam = self.db.commit_family(fam, self.trans) person1 = self.db.get_person_from_handle(person1_h) person1.add_family_handle(fam_h) - self.db.commit_person(person1,self.trans) + self.db.commit_person(person1, self.trans) person2 = self.db.get_person_from_handle(person2_h) person2.add_family_handle(fam_h) - self.db.commit_person(person2,self.trans) + self.db.commit_person(person2, self.trans) child.add_parent_family_handle(fam_h) - self.db.commit_person(child,self.trans) + self.db.commit_person(child, self.trans) def generate_tags(self): + """ Make up some odd tags """ with DbTxn(_("Testcase generator step %d") % self.transaction_count, self.db) as self.trans: self.transaction_count += 1 - for counter in range(10): + for dummy in range(10): tag = Tag() tag.set_name(self.rand_text(self.TAG)) tag.set_color(self.rand_color()) @@ -1559,21 +1622,22 @@ class TestcaseGenerator(tool.BatchTool): tag_handle = self.db.add_tag(tag, self.trans) self.generated_tags.append(tag_handle) - def add_defaults(self, object): - self.fill_object( object) + def add_defaults(self, obj): + self.fill_object(obj) - def rand_name( self, lastname=None, gender=None): + def rand_name(self, lastname=None, gender=None): + """ Create a name pair (first, last)""" if gender == Person.MALE: - firstname = self.rand_text( self.FIRSTNAME_MALE) + firstname = self.rand_text(self.FIRSTNAME_MALE) elif gender == Person.FEMALE: - firstname = self.rand_text( self.FIRSTNAME_FEMALE) + firstname = self.rand_text(self.FIRSTNAME_FEMALE) else: - firstname = self.rand_text( self.FIRSTNAME) + firstname = self.rand_text(self.FIRSTNAME) if not lastname: - lastname = self.rand_text( self.LASTNAME) - return (firstname,lastname) + lastname = self.rand_text(self.LASTNAME) + return (firstname, lastname) - def rand_date( self, start=None, end=None): + def rand_date(self, start=None, end=None): """ Generates a random date object between the given years start and end """ @@ -1602,12 +1666,12 @@ class TestcaseGenerator(tool.BatchTool): Date.QUAL_CALCULATED)) modifier = _choice((Date.MOD_NONE, Date.MOD_BEFORE, - Date.MOD_AFTER,\ + Date.MOD_AFTER, Date.MOD_ABOUT, Date.MOD_RANGE, Date.MOD_SPAN)) day = _randint(0, 28) - if day > 0: # avoid days without month + if day > 0: # avoid days without month month = _randint(1, 12) else: month = _randint(0, 12) @@ -1619,66 +1683,69 @@ class TestcaseGenerator(tool.BatchTool): else: month2 = _randint(0, 12) year2 = year + _randint(1, 5) - ndate.set(quality,modifier,calendar,(day,month,year,False,day2,month2,year2,False),"") + ndate.set(quality, modifier, calendar, + (day, month, year, False, day2, month2, year2, + False), "") else: - ndate.set(quality,modifier,calendar,(day,month,year,False),"") + ndate.set(quality, modifier, calendar, + (day, month, year, False), "") return (year, ndate) - def fill_object( self, o): + def fill_object(self, obj): + ''' Generic object fill routine ''' - - if issubclass(o.__class__, AddressBase): + if issubclass(obj.__class__, AddressBase): while _randint(0, 1) == 1: - a = Address() - self.fill_object(a) - o.add_address( a) + addr = Address() + self.fill_object(addr) + obj.add_address(addr) - if isinstance(o,Attribute): - o.set_type( self.rand_type(AttributeType())) - o.set_value( self.rand_text(self.SHORT)) + if isinstance(obj, Attribute): + obj.set_type(self.rand_type(AttributeType())) + obj.set_value(self.rand_text(self.SHORT)) - if issubclass(o.__class__, AttributeBase): + if issubclass(obj.__class__, AttributeBase): while _randint(0, 1) == 1: - a = Attribute() - self.fill_object(a) - o.add_attribute( a) + att = Attribute() + self.fill_object(att) + obj.add_attribute(att) - if isinstance(o,ChildRef): + if isinstance(obj, ChildRef): if _randint(0, 3) == 1: - o.set_mother_relation( self.rand_type( ChildRefType())) + obj.set_mother_relation(self.rand_type(ChildRefType())) if _randint(0, 3) == 1: - o.set_father_relation( self.rand_type( ChildRefType())) + obj.set_father_relation(self.rand_type(ChildRefType())) - if issubclass(o.__class__, DateBase): + if issubclass(obj.__class__, DateBase): if _randint(0, 1) == 1: - (y,d) = self.rand_date() - o.set_date_object( d) + (dummy, dat) = self.rand_date() + obj.set_date_object(dat) - if isinstance(o,Event): + if isinstance(obj, Event): if _randint(0, 1) == 1: - o.set_description( self.rand_text(self.LONG)) + obj.set_description(self.rand_text(self.LONG)) - if issubclass(o.__class__, EventRef): - o.set_role( self.rand_type(EventRoleType())) + if issubclass(obj.__class__, EventRef): + obj.set_role(self.rand_type(EventRoleType())) - if isinstance(o,Family): + if isinstance(obj, Family): if _randint(0, 2) == 1: - o.set_relationship( self.rand_type(FamilyRelType())) + obj.set_relationship(self.rand_type(FamilyRelType())) else: - o.set_relationship(FamilyRelType(FamilyRelType.MARRIED)) + obj.set_relationship(FamilyRelType(FamilyRelType.MARRIED)) - if isinstance(o,LdsOrd): + if isinstance(obj, LdsOrd): if _randint(0, 1) == 1: - o.set_temple(_choice(TEMPLES.name_code_data())[1]) + obj.set_temple(_choice(TEMPLES.name_code_data())[1]) - if issubclass(o.__class__, LdsOrdBase): + if issubclass(obj.__class__, LdsOrdBase): while _randint(0, 1) == 1: ldsord = LdsOrd() - self.fill_object( ldsord) - if isinstance(o,Person): + self.fill_object(ldsord) + if isinstance(obj, Person): lds_type = _choice([item for item in LDS_INDIVIDUAL_ORD]) - if isinstance(o,Family): + if isinstance(obj, Family): lds_type = LDS_SPOUSE_SEALING[0] if self.generated_families: ldsord.set_family_handle( @@ -1687,222 +1754,227 @@ class TestcaseGenerator(tool.BatchTool): status = _choice(lds_type[1]) if status != LdsOrd.STATUS_NONE: ldsord.set_status(status) - o.add_lds_ord( ldsord) + obj.add_lds_ord(ldsord) - if isinstance(o,Location): + if isinstance(obj, Location): if _randint(0, 1) == 1: - o.set_parish( self.rand_text(self.SHORT)) + obj.set_parish(self.rand_text(self.SHORT)) - if issubclass(o.__class__, LocationBase): + if issubclass(obj.__class__, LocationBase): if _randint(0, 1) == 1: - o.set_street( self.rand_text(self.SHORT)) + obj.set_street(self.rand_text(self.SHORT)) if _randint(0, 1) == 1: - o.set_city( self.rand_text(self.SHORT)) + obj.set_city(self.rand_text(self.SHORT)) if _randint(0, 1) == 1: - o.set_postal_code( self.rand_text(self.SHORT)) + obj.set_postal_code(self.rand_text(self.SHORT)) if _randint(0, 1) == 1: - o.set_phone( self.rand_text(self.SHORT)) + obj.set_phone(self.rand_text(self.SHORT)) if _randint(0, 1) == 1: - o.set_state( self.rand_text(self.SHORT)) + obj.set_state(self.rand_text(self.SHORT)) if _randint(0, 1) == 1: - o.set_country( self.rand_text(self.SHORT)) + obj.set_country(self.rand_text(self.SHORT)) if _randint(0, 1) == 1: - o.set_county( self.rand_text(self.SHORT)) + obj.set_county(self.rand_text(self.SHORT)) - if issubclass(o.__class__, MediaBase): + if issubclass(obj.__class__, MediaBase): # FIXME: frequency changed to prevent recursion while _randint(0, 10) == 1: - o.add_media_reference( self.fill_object( MediaRef())) + obj.add_media_reference(self.fill_object(MediaRef())) - if isinstance(o,Media): + if isinstance(obj, Media): if _randint(0, 3) == 1: - o.set_description(str(self.rand_text(self.LONG))) + obj.set_description(str(self.rand_text(self.LONG))) path = os.path.abspath(_choice((ICON, LOGO, SPLASH))) - o.set_path(str(path)) + obj.set_path(str(path)) mime = get_type(path) - o.set_mime_type(mime) + obj.set_mime_type(mime) else: - o.set_description(str(self.rand_text(self.SHORT))) - o.set_path(os.path.abspath(str(ICON))) - o.set_mime_type("image/png") + obj.set_description(str(self.rand_text(self.SHORT))) + obj.set_path(os.path.abspath(str(ICON))) + obj.set_mime_type("image/png") - if isinstance(o,MediaRef): + if isinstance(obj, MediaRef): if not self.generated_media or _randint(0, 10) == 1: - m = Media() - self.fill_object(m) - self.db.add_media( m, self.trans) - self.generated_media.append( m.get_handle()) - o.set_reference_handle(_choice(self.generated_media)) + med = Media() + self.fill_object(med) + self.db.add_media(med, self.trans) + self.generated_media.append(med.get_handle()) + obj.set_reference_handle(_choice(self.generated_media)) if _randint(0, 1) == 1: - o.set_rectangle((_randint(0, 200), _randint(0, 200), - _randint(0, 200), _randint(0, 200))) + obj.set_rectangle((_randint(0, 200), _randint(0, 200), + _randint(0, 200), _randint(0, 200))) - if isinstance(o,Name): - o.set_type( self.rand_type( NameType())) + if isinstance(obj, Name): + obj.set_type(self.rand_type(NameType())) if _randint(0, 1) == 1: - o.set_title( self.rand_text(self.SHORT)) + obj.set_title(self.rand_text(self.SHORT)) if _randint(0, 1) == 1: patronymic = Surname() patronymic.set_surname(self.rand_text(self.FIRSTNAME_MALE)) patronymic.set_origintype(NameOriginType.PATRONYMIC) - o.add_surname(patronymic) + obj.add_surname(patronymic) if _randint(0, 1) == 1: - o.get_primary_surname().set_prefix( self.rand_text(self.SHORT)) + obj.get_primary_surname().set_prefix( + self.rand_text(self.SHORT)) if _randint(0, 1) == 1: - o.set_suffix( self.rand_text(self.SHORT)) + obj.set_suffix(self.rand_text(self.SHORT)) if _randint(0, 1) == 1: - o.set_call_name( self.rand_text(self.FIRSTNAME)) + obj.set_call_name(self.rand_text(self.FIRSTNAME)) if _randint(0, 1) == 1: - o.set_group_as( o.get_surname()[:1]) - # o.set_display_as() - # o.set_sort_as() + obj.set_group_as(obj.get_surname()[:1]) + # obj.set_display_as() + # obj.set_sort_as() - if isinstance(o,Note): - type = self.rand_type(NoteType()) - if type == NoteType.HTML_CODE: - o.set( self.rand_text(self.NOTE)) + if isinstance(obj, Note): + n_type = self.rand_type(NoteType()) + if n_type == NoteType.HTML_CODE: + obj.set(self.rand_text(self.NOTE)) else: - o.set_styledtext(self.rand_text(self.STYLED_TEXT)) - o.set_format(_choice((Note.FLOWED, Note.FORMATTED))) - o.set_type(type) + obj.set_styledtext(self.rand_text(self.STYLED_TEXT)) + obj.set_format(_choice((Note.FLOWED, Note.FORMATTED))) + obj.set_type(n_type) - if issubclass(o.__class__, NoteBase): + if issubclass(obj.__class__, NoteBase): while _randint(0, 1) == 1: if not self.generated_notes or _randint(0, 10) == 1: - n = Note() - self.fill_object(n) - self.db.add_note( n, self.trans) - self.generated_notes.append( n.get_handle()) + note = Note() + self.fill_object(note) + self.db.add_note(note, self.trans) + self.generated_notes.append(note.get_handle()) n_h = _choice(self.generated_notes) - o.add_note(n_h) + obj.add_note(n_h) - if isinstance(o, Place): - o.set_title(self.rand_text(self.LONG)) - o.set_name(PlaceName(value=self.rand_text(self.SHORT))) - o.set_code(self.rand_text(self.SHORT)) + if isinstance(obj, Place): + obj.set_title(self.rand_text(self.LONG)) + obj.set_name(PlaceName(value=self.rand_text(self.SHORT))) + obj.set_code(self.rand_text(self.SHORT)) if _randint(0, 1) == 1: if _randint(0, 4) == 1: - o.set_longitude(self.rand_text(self.SHORT)) + obj.set_longitude(self.rand_text(self.SHORT)) else: - o.set_longitude(str(_random() * 360.0 - 180.0)) + obj.set_longitude(str(_random() * 360.0 - 180.0)) if _randint(0, 1) == 1: if _randint(0, 4) == 1: - o.set_latitude( self.rand_text(self.SHORT)) + obj.set_latitude(self.rand_text(self.SHORT)) else: - o.set_latitude(str(_random() * 180.0 - 90.0)) + obj.set_latitude(str(_random() * 180.0 - 90.0)) while _randint(0, 1) == 1: - o.add_alternate_locations(self.fill_object(Location())) + obj.add_alternate_locations(self.fill_object(Location())) - if issubclass(o.__class__, PlaceBase): + if issubclass(obj.__class__, PlaceBase): if _randint(0, 1) == 1: - o.set_place_handle(self.rand_place()) + obj.set_place_handle(self.rand_place()) - if issubclass(o.__class__, BasicPrimaryObject): + if issubclass(obj.__class__, BasicPrimaryObject): if _randint(0, 1) == 1: - o.set_gramps_id( self.rand_text(self.SHORT)) + obj.set_gramps_id(self.rand_text(self.SHORT)) - if issubclass(o.__class__, PrivacyBase): - o.set_privacy( _randint(0, 5) == 1) + if issubclass(obj.__class__, PrivacyBase): + obj.set_privacy(_randint(0, 5) == 1) - if isinstance(o,RepoRef): + if isinstance(obj, RepoRef): if not self.generated_repos or _randint(0, 10) == 1: - r = Repository() - self.fill_object(r) - self.db.add_repository( r, self.trans) - self.generated_repos.append(r.get_handle()) - o.set_reference_handle(_choice(self.generated_repos)) + rep = Repository() + self.fill_object(rep) + self.db.add_repository(rep, self.trans) + self.generated_repos.append(rep.get_handle()) + obj.set_reference_handle(_choice(self.generated_repos)) if _randint(0, 1) == 1: - o.set_call_number( self.rand_text(self.SHORT)) - o.set_media_type( self.rand_type(SourceMediaType())) + obj.set_call_number(self.rand_text(self.SHORT)) + obj.set_media_type(self.rand_type(SourceMediaType())) - if isinstance(o,Repository): - o.set_type( self.rand_type(RepositoryType())) - o.set_name( self.rand_text(self.SHORT)) + if isinstance(obj, Repository): + obj.set_type(self.rand_type(RepositoryType())) + obj.set_name(self.rand_text(self.SHORT)) - if isinstance(o,Source): - o.set_title( self.rand_text(self.SHORT)) + if isinstance(obj, Source): + obj.set_title(self.rand_text(self.SHORT)) if _randint(0, 1) == 1: - o.set_author( self.rand_text(self.SHORT)) + obj.set_author(self.rand_text(self.SHORT)) if _randint(0, 1) == 1: - o.set_publication_info( self.rand_text(self.LONG)) + obj.set_publication_info(self.rand_text(self.LONG)) if _randint(0, 1) == 1: - o.set_abbreviation( self.rand_text(self.SHORT)) + obj.set_abbreviation(self.rand_text(self.SHORT)) while _randint(0, 1) == 1: sattr = SrcAttribute() sattr.set_type(self.rand_text(self.SHORT)) sattr.set_value(self.rand_text(self.SHORT)) - o.add_attribute(sattr) + obj.add_attribute(sattr) while _randint(0, 1) == 1: - r = RepoRef() - self.fill_object(r) - o.add_repo_reference( r) + rep_ref = RepoRef() + self.fill_object(rep_ref) + obj.add_repo_reference(rep_ref) - if issubclass(o.__class__, CitationBase): + if issubclass(obj.__class__, CitationBase): while _randint(0, 1) == 1: if not self.generated_citations or _randint(1, 10) == 1: - s = Citation() - self.fill_object(s) - self.db.add_citation( s, self.trans) - self.generated_citations.append(s.get_handle()) + cit = Citation() + self.fill_object(cit) + self.db.add_citation(cit, self.trans) + self.generated_citations.append(cit.get_handle()) s_h = _choice(self.generated_citations) - o.add_citation(s_h) + obj.add_citation(s_h) - if isinstance(o,Citation): + if isinstance(obj, Citation): if not self.generated_sources or _randint(0, 10) == 1: - s = Source() - self.fill_object(s) - self.db.add_source( s, self.trans) - self.generated_sources.append( s.get_handle()) - o.set_reference_handle(_choice(self.generated_sources)) + src = Source() + self.fill_object(src) + self.db.add_source(src, self.trans) + self.generated_sources.append(src.get_handle()) + obj.set_reference_handle(_choice(self.generated_sources)) if _randint(0, 1) == 1: - o.set_page( self.rand_text(self.NUMERIC)) - #if _randint(0, 1) == 1: - # o.set_text( self.rand_text(self.SHORT)) - #if _randint(0, 1) == 1: - # (year, d) = self.rand_date( ) - # o.set_date_object( d) - o.set_confidence_level(_choice(list(conf_strings.keys()))) + obj.set_page(self.rand_text(self.NUMERIC)) + # if _randint(0, 1) == 1: + # obj.set_text( self.rand_text(self.SHORT)) + # if _randint(0, 1) == 1: + # (year, dat) = self.rand_date( ) + # obj.set_date_object( dat) + obj.set_confidence_level(_choice(list(conf_strings.keys()))) - if issubclass(o.__class__, TagBase): + if issubclass(obj.__class__, TagBase): if _randint(0, 1) == 1: - o.set_tag_list(self.rand_tags()) + obj.set_tag_list(self.rand_tags()) - if issubclass(o.__class__, UrlBase): + if issubclass(obj.__class__, UrlBase): while _randint(0, 1) == 1: - u = Url() - self.fill_object(u) - o.add_url(u) + url = Url() + self.fill_object(url) + obj.add_url(url) - if isinstance(o,Url): - o.set_path("http://www.gramps-project.org/?test=%s" % self.rand_text(self.SHORT)) - o.set_description( self.rand_text(self.SHORT)) - o.set_type( self.rand_type(UrlType())) + if isinstance(obj, Url): + obj.set_path("http://www.gramps-project.org/?test=%s" % + self.rand_text(self.SHORT)) + obj.set_description(self.rand_text(self.SHORT)) + obj.set_type(self.rand_type(UrlType())) - return o + return obj - def rand_personal_event( self, type=None, start=None, end=None): - if type: - typeval = EventType(type) + def rand_personal_event(self, e_type=None, start=None, end=None): + """ Random personal event """ + if e_type: + typeval = EventType(e_type) else: typeval = self.rand_type(EventType()) - return self._rand_event( typeval, start, end) + return self._rand_event(typeval, start, end) - def rand_family_event( self, type=None, start=None, end=None): - if type: - typeval = EventType(type) + def rand_family_event(self, e_type=None, start=None, end=None): + """ Random family event """ + if e_type: + EventType(e_type) else: typeval = EventType.UNKNOWN while int(typeval) not in self.FAMILY_EVENTS: typeval = self.rand_type(EventType()) - return self._rand_event( typeval, start, end) + return self._rand_event(typeval, start, end) - def _rand_event( self, type, start, end): - e = Event() - self.fill_object(e) - e.set_type( type) - (year, d) = self.rand_date( start, end) - e.set_date_object( d) - event_h = self.db.add_event(e, self.trans) + def _rand_event(self, e_type, start, end): + """ Random general event """ + evt = Event() + self.fill_object(evt) + evt.set_type(e_type) + (year, dat) = self.rand_date(start, end) + evt.set_date_object(dat) + event_h = self.db.add_event(evt, self.trans) self.generated_events.append(event_h) event_ref = EventRef() self.fill_object(event_ref) @@ -1911,8 +1983,8 @@ class TestcaseGenerator(tool.BatchTool): def rand_type(self, gtype): if issubclass(gtype.__class__, GrampsType): - map = gtype.get_map() - key = _choice(list(map.keys())) + gmap = gtype.get_map() + key = _choice(list(gmap.keys())) if key == gtype.get_custom(): value = self.rand_text(self.SHORT) else: @@ -1955,98 +2027,103 @@ class TestcaseGenerator(tool.BatchTool): def add_parent_place(self, place, handle): place_ref = PlaceRef() place_ref.ref = handle - year, random_date = self.rand_date() + dummy, random_date = self.rand_date() place_ref.set_date_object(random_date) place.add_placeref(place_ref) - def rand_text(self, type=None): + def rand_text(self, t_type=None): + """ make random text strings according to desired type """ # for lastnamesnames - syllables1 = ["sa","li","na","ma","no","re","mi","cha","ki","du","ba","ku","el"] + syllables1 = ["sa", "li", "na", "ma", "no", "re", "mi", + "cha", "ki", "du", "ba", "ku", "el"] # for firstnames - syllables2 = ["as","il","an","am","on","er","im","ach","ik","ud","ab","ul","le"] + syllables2 = ["as", "il", "an", "am", "on", "er", "im", + "ach", "ik", "ud", "ab", "ul", "le"] # others - syllables3 = ["ka", "po", "lo", "chi", "she", "di", "fa", "go", "ja", "ne", "pe"] + syllables3 = ["ka", "po", "lo", "chi", "she", "di", "fa", + "go", "ja", "ne", "pe"] - syllables = syllables1 + syllables2 +syllables3 + syllables = syllables1 + syllables2 + syllables3 minwords = 5 maxwords = 8 minsyllables = 2 maxsyllables = 5 - if type == self.STYLED_TEXT: + # result = "" if t_type != self.STYLED_TEXT else StyledText("") + if t_type == self.STYLED_TEXT: result = StyledText("") else: result = "" - if self.options.handler.options_dict['specialchars']: + if self.options_dict['specialchars']: result = result + "ä<ö&ü%ß'\"" - if self.options.handler.options_dict['add_serial'] and type != self.TAG: + if self.options_dict['add_serial'] and t_type != self.TAG: result = result + "#+#%06d#-#" % self.text_serial_number self.text_serial_number = self.text_serial_number + 1 - if not type: - type = self.SHORT + if not t_type: + t_type = self.SHORT - if type == self.SHORT or type == self.TAG: + if t_type == self.SHORT or t_type == self.TAG: minwords = 1 maxwords = 3 minsyllables = 2 maxsyllables = 4 - if type == self.LONG: + if t_type == self.LONG: minwords = 5 maxwords = 8 minsyllables = 2 maxsyllables = 5 - if type == self.FIRSTNAME: - type = _choice((self.FIRSTNAME_MALE, self.FIRSTNAME_FEMALE)) + if t_type == self.FIRSTNAME: + t_type = _choice((self.FIRSTNAME_MALE, self.FIRSTNAME_FEMALE)) - if type == self.FIRSTNAME_MALE or type == self.FIRSTNAME_FEMALE: + if t_type == self.FIRSTNAME_MALE or t_type == self.FIRSTNAME_FEMALE: syllables = syllables2 minwords = 1 maxwords = 5 minsyllables = 2 maxsyllables = 5 - if not self.options.handler.options_dict['long_names']: + if not self.options_dict['long_names']: maxwords = 2 maxsyllables = 3 - if type == self.LASTNAME: + if t_type == self.LASTNAME: syllables = syllables1 minwords = 1 maxwords = 1 minsyllables = 2 maxsyllables = 5 - if not self.options.handler.options_dict['long_names']: + if not self.options_dict['long_names']: maxsyllables = 3 - if type == self.NOTE or type == self.STYLED_TEXT: + if t_type == self.NOTE or t_type == self.STYLED_TEXT: result = result + "Generated by TestcaseGenerator." minwords = 20 maxwords = 100 - if type == self.NUMERIC: + if t_type == self.NUMERIC: if _randint(0, 1) == 1: return "%d %s" % (_randint(1, 100), result) if _randint(0, 1) == 1: return "%d, %d %s" % (_randint(1, 100), _randint(100, 1000), result) - m = _randint(100, 1000) - return "%d - %d %s" % (m, m+_randint(1, 5), result) + med = _randint(100, 1000) + return "%d - %d %s" % (med, med + _randint(1, 5), result) - for i in range(0, _randint(minwords, maxwords)): + for dummy in range(0, _randint(minwords, maxwords)): if result: result = result + " " word = "" for j in range(0, _randint(minsyllables, maxsyllables)): word = word + _choice(syllables) - if type == self.FIRSTNAME_MALE: + if t_type == self.FIRSTNAME_MALE: word = word + _choice(("a", "e", "i", "o", "u")) if _randint(0, 3) == 1: word = word.title() - if type == self.NOTE: + if t_type == self.NOTE: if _randint(0, 10) == 1: word = "%s" % word elif _randint(0, 10) == 1: @@ -2057,36 +2134,35 @@ class TestcaseGenerator(tool.BatchTool): word = word + "." elif _randint(0, 30) == 1: word = word + ".\n" - if type == self.STYLED_TEXT: + if t_type == self.STYLED_TEXT: tags = [] if _randint(0, 10) == 1: tags += [StyledTextTag(StyledTextTagType.BOLD, True, - [(0, len(word))])] + [(0, len(word))])] elif _randint(0, 10) == 1: tags += [StyledTextTag(StyledTextTagType.ITALIC, True, - [(0, len(word))])] + [(0, len(word))])] elif _randint(0, 10) == 1: tags += [StyledTextTag(StyledTextTagType.UNDERLINE, True, - [(0, len(word))])] - word = StyledText(word, tags) + [(0, len(word))])] + sword = StyledText(word, tags) if _randint(0, 20) == 1: - word = word + "." + sword = sword + "." elif _randint(0, 30) == 1: - word = word + ".\n" - if type == self.STYLED_TEXT: - result = StyledText("").join((result, word)) + sword = sword + ".\n" + result = StyledText("").join((result, sword)) else: result += word - if type == self.LASTNAME: - n = _randint(0, 2) - if n == 0: + if t_type == self.LASTNAME: + case = _randint(0, 2) + if case == 0: result = result.title() - elif n == 1: + elif case == 1: result = result.upper() - if self.options.handler.options_dict['add_linebreak'] and \ - type != self.TAG: + if self.options_dict['add_linebreak'] and \ + t_type != self.TAG: result = result + "\nNEWLINE" return result @@ -2097,66 +2173,73 @@ class TestcaseGenerator(tool.BatchTool): def rand_tags(self): maxtags = 5 taglist = [] - for counter in range(0, _randint(1, maxtags)): + for dummy in range(0, _randint(1, maxtags)): tag = _choice(self.generated_tags) if tag not in taglist: taglist.append(tag) return taglist -#------------------------------------------------------------------------ + +# ----------------------------------------------------------------------- # +# The options class for the tool # -# -#------------------------------------------------------------------------ +# ----------------------------------------------------------------------- class TestcaseGeneratorOptions(tool.ToolOptions): """ Defines options and provides handling interface. """ - def __init__(self, name,person_id=None): - tool.ToolOptions.__init__(self, name,person_id) + def __init__(self, name, person_id=None): + tool.ToolOptions.__init__(self, name, person_id) # Options specific for this report self.options_dict = { - 'lowlevel' : 0, - 'bugs' : 0, - 'persons' : 1, - 'person_count' : 2000, - 'long_names' : 0, - 'specialchars' : 0, - 'add_serial' : 0, - 'add_linebreak' : 0, + 'lowlevel': 0, + 'bugs': 0, + 'persons': 1, + 'person_count': 2000, + 'long_names': 0, + 'specialchars': 0, + 'add_serial': 0, + 'add_linebreak': 0, } self.options_help = { - 'lowlevel' : ("=0/1", - "Whether to create low level database errors.", - ["Skip test","Create low level database errors"], - True), - 'bugs' : ("=0/1", - "Whether to create invalid database references.", - ["Skip test","Create invalid Database references"], - True), - 'persons' : ("=0/1", - "Whether to create a bunch of dummy persons", - ["Dont create persons","Create dummy persons"], - True), - 'person_count' : ("=int", - "Number of dummy persons to generate", - "Number of persons"), - 'long_names' : ("=0/1", - "Whether to create short or long names", - ["Short names","Long names"], - True), - 'specialchars' : ("=0/1", - "Whether to ass some special characters to every text field", - ["No special characters","Add special characters"], - True), - 'add_serial' : ("=0/1", - "Whether to add a serial number to every text field", - ["No serial","Add serial number"], - True), - 'add_linebreak' : ("=0/1", - "Whether to add a line break to every text field", - ["No linebreak","Add line break"], - True), + 'lowlevel': ("=0/1", + "Whether to create low level database errors.", + ["Skip test", + "Create low level database errors"], + True), + 'bugs': ("=0/1", + "Whether to create invalid database references.", + ["Skip test", + "Create invalid Database references"], + True), + 'persons': ("=0/1", + "Whether to create a bunch of dummy persons", + ["Dont create persons", "Create dummy persons"], + True), + 'person_count': ("=int", + "Number of dummy persons to generate", + "Number of persons"), + 'long_names': ("=0/1", + "Whether to create short or long names", + ["Short names", "Long names"], + True), + 'specialchars': ("=0/1", + "Whether to ass some special characters to every" + " text field", + ["No special characters", + "Add special characters"], + True), + 'add_serial': ("=0/1", + "Whether to add a serial number to every text " + "field", + ["No serial", "Add serial number"], + True), + 'add_linebreak': ("=0/1", + "Whether to add a line break to every text " + "field", + ["No linebreak", "Add line break"], + True), }