* src/plugins/Check.py (check_parent_relationships): Catch some more database errors. Messages in the report still need some work.
* src/plugins/TestcaseGenerator.py: New plugin that creates some of the errors that crashed Check.py before. svn: r4241
This commit is contained in:
parent
20a785d887
commit
510bc975ac
@ -4,6 +4,12 @@
|
||||
|
||||
* src/plugins/Check.py (check_parent_relationships): typo
|
||||
|
||||
* src/plugins/Check.py (check_parent_relationships): Catch some more
|
||||
database errors. Messages in the report still need some work.
|
||||
* src/plugins/TestcaseGenerator.py: New plugin that creates some of
|
||||
the errors that crashed Check.py before.
|
||||
|
||||
|
||||
2005-03-25 Richard Taylor <rjt-gramps@thegrindstone.me.uk>
|
||||
* src/ScratchPad.py (ScratchPadWindow): moved content of pad to a
|
||||
class attribute so that it is preserved when the pad is closed.
|
||||
|
@ -99,14 +99,24 @@ class CheckIntegrity:
|
||||
mother_handle = family.get_mother_handle()
|
||||
if father_handle:
|
||||
father = self.db.get_person_from_handle(father_handle)
|
||||
if not father:
|
||||
family.set_father_handle(None)
|
||||
self.db.commit_family(family,self.trans)
|
||||
self.broken_parent_links.append((father_handle,family_handle))
|
||||
father_handle = None
|
||||
if mother_handle:
|
||||
mother = self.db.get_person_from_handle(mother_handle)
|
||||
if not mother:
|
||||
family.set_father_handle(None)
|
||||
self.db.commit_family(family,self.trans)
|
||||
self.broken_parent_links.append((mother_handle,family_handle))
|
||||
mother_handle = None
|
||||
|
||||
if father_handle and family_handle not in father.get_family_handle_list():
|
||||
if father_handle and father and family_handle not in father.get_family_handle_list():
|
||||
self.broken_parent_links.append((father_handle,family_handle))
|
||||
father.add_family_handle(family_handle)
|
||||
self.db.commit_person(father,self.trans)
|
||||
if mother_handle and family_handle not in mother.get_family_handle_list():
|
||||
if mother_handle and mother and family_handle not in mother.get_family_handle_list():
|
||||
self.broken_parent_links.append((mother_handle,family_handle))
|
||||
mother.add_family_handle(family_handle)
|
||||
self.db.commit_person(mother,self.trans)
|
||||
@ -238,8 +248,10 @@ class CheckIntegrity:
|
||||
family = self.db.get_family_from_handle(family_handle)
|
||||
mother_handle = family.get_mother_handle()
|
||||
father_handle = family.get_father_handle()
|
||||
father = None
|
||||
if father_handle:
|
||||
father = self.db.get_person_from_handle(father_handle)
|
||||
mother = None
|
||||
if mother_handle:
|
||||
mother = self.db.get_person_from_handle(mother_handle)
|
||||
rel_type = family.get_relationship()
|
||||
@ -247,12 +259,12 @@ class CheckIntegrity:
|
||||
if not father_handle and not mother_handle:
|
||||
continue
|
||||
elif not father_handle:
|
||||
if mother.get_gender() == RelLib.Person.MALE:
|
||||
if mother and mother.get_gender() == RelLib.Person.MALE:
|
||||
family.set_father_handle(mother_handle)
|
||||
family.set_mother_handle(None)
|
||||
self.db.commit_family(family,self.trans)
|
||||
elif not mother_handle:
|
||||
if father.get_gender() == RelLib.Person.FEMALE:
|
||||
if father and father.get_gender() == RelLib.Person.FEMALE:
|
||||
family.set_mother_handle(father_handle)
|
||||
family.set_father_handle(None)
|
||||
self.db.commit_family(family,self.trans)
|
||||
@ -333,7 +345,10 @@ class CheckIntegrity:
|
||||
for (person_handle,family_handle) in self.broken_parent_links:
|
||||
person = self.db.get_person_from_handle(person_handle)
|
||||
family = self.db.get_family_from_handle(family_handle)
|
||||
if person:
|
||||
cn = person.get_primary_name().get_name()
|
||||
else:
|
||||
cn = _("Non existing person")
|
||||
f = self.db.get_person_from_handle(family.get_father_handle())
|
||||
m = self.db.get_person_from_handle(family.get_mother_handle())
|
||||
if f and m:
|
||||
@ -341,8 +356,10 @@ class CheckIntegrity:
|
||||
m.get_primary_name().get_name())
|
||||
elif f:
|
||||
pn = f.get_primary_name().get_name()
|
||||
else:
|
||||
elif m:
|
||||
pn = m.get_primary_name().get_name()
|
||||
else:
|
||||
pn = "Non existing person"
|
||||
self.text.write('\t')
|
||||
self.text.write(_("%s was restored to the family of %s\n") % (cn,pn))
|
||||
|
||||
|
271
gramps2/src/plugins/TestcaseGenerator.py
Normal file
271
gramps2/src/plugins/TestcaseGenerator.py
Normal file
@ -0,0 +1,271 @@
|
||||
#
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
# Copyright (C) 2000-2005 Martin Hawlisch, Donald N. Allingham
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
|
||||
# $Id$
|
||||
|
||||
"Create person and family testcases"
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# standard python modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import os
|
||||
import re
|
||||
import time
|
||||
from random import randint,choice
|
||||
from gettext import gettext as _
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# GRAMPS modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import Errors
|
||||
import RelLib
|
||||
import latin_utf8
|
||||
import Utils
|
||||
import const
|
||||
from QuestionDialog import ErrorDialog
|
||||
from DateHandler import parser as _dp
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
#
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
class TestcaseGenerator:
|
||||
def __init__(self,database,active_person,callback,parent):
|
||||
print "__init__"
|
||||
self.db = database
|
||||
self.person_count = 0
|
||||
|
||||
def run(self):
|
||||
print "run"
|
||||
self.trans = self.db.transaction_begin()
|
||||
self.generate_broken_relations()
|
||||
person1_h = self.generate_person(0)
|
||||
self.generate_family(person1_h)
|
||||
self.db.transaction_commit(self.trans,_("Testcase generator"))
|
||||
|
||||
|
||||
def generate_broken_relations(self):
|
||||
# Create a family, that links to father and mother, but father does not link back
|
||||
person1_h = self.generate_person(RelLib.Person.MALE,"Broken1","Family links to this person, but person does not link back")
|
||||
person2_h = self.generate_person(RelLib.Person.FEMALE,"Broken1",None)
|
||||
fam = RelLib.Family()
|
||||
fam.set_father_handle(person1_h)
|
||||
fam.set_mother_handle(person2_h)
|
||||
fam.set_relationship(RelLib.Family.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)
|
||||
|
||||
# Create a family, that misses the link to the father
|
||||
person1_h = self.generate_person(RelLib.Person.MALE,"Broken2",None)
|
||||
person2_h = self.generate_person(RelLib.Person.FEMALE,"Broken2",None)
|
||||
fam = RelLib.Family()
|
||||
#fam.set_father_handle(person1_h)
|
||||
fam.set_mother_handle(person2_h)
|
||||
fam.set_relationship(RelLib.Family.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)
|
||||
|
||||
# Create a family, that misses the link to the mother
|
||||
person1_h = self.generate_person(RelLib.Person.MALE,"Broken3",None)
|
||||
person2_h = self.generate_person(RelLib.Person.FEMALE,"Broken3",None)
|
||||
fam = RelLib.Family()
|
||||
fam.set_father_handle(person1_h)
|
||||
#fam.set_mother_handle(person2_h)
|
||||
fam.set_relationship(RelLib.Family.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)
|
||||
|
||||
# Create a family, that links to father and mother, but father does not link back
|
||||
person1_h = self.generate_person(RelLib.Person.MALE,"Broken4",None)
|
||||
person2_h = self.generate_person(RelLib.Person.FEMALE,"Broken4","Family links to this person, but person does not link back")
|
||||
fam = RelLib.Family()
|
||||
fam.set_father_handle(person1_h)
|
||||
fam.set_mother_handle(person2_h)
|
||||
fam.set_relationship(RelLib.Family.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)
|
||||
|
||||
# Create two married people of same sex.
|
||||
person1_h = self.generate_person(RelLib.Person.MALE,"Broken5",None)
|
||||
person2_h = self.generate_person(RelLib.Person.MALE,"Broken5",None)
|
||||
fam = RelLib.Family()
|
||||
fam.set_father_handle(person1_h)
|
||||
fam.set_mother_handle(person2_h)
|
||||
fam.set_relationship(RelLib.Family.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)
|
||||
|
||||
# Create a family, that contains an invalid handle to for the father
|
||||
#person1_h = self.generate_person(RelLib.Person.MALE,"Broken6",None)
|
||||
person2_h = self.generate_person(RelLib.Person.FEMALE,"Broken6",None)
|
||||
fam = RelLib.Family()
|
||||
fam.set_father_handle("InvalidHandle1")
|
||||
fam.set_mother_handle(person2_h)
|
||||
fam.set_relationship(RelLib.Family.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)
|
||||
|
||||
# Create a family, that contains an invalid handle to for the mother
|
||||
person1_h = self.generate_person(RelLib.Person.MALE,"Broken7",None)
|
||||
#person2_h = self.generate_person(RelLib.Person.FEMALE,"Broken7",None)
|
||||
fam = RelLib.Family()
|
||||
fam.set_father_handle(person1_h)
|
||||
fam.set_mother_handle("InvalidHandle2")
|
||||
fam.set_relationship(RelLib.Family.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)
|
||||
|
||||
|
||||
|
||||
def generate_person(self,gender=None,lastname=None,note=None):
|
||||
print "generate_person"
|
||||
np = RelLib.Person()
|
||||
|
||||
# Note
|
||||
if note:
|
||||
np.set_note(note)
|
||||
|
||||
# Gender
|
||||
if gender == None:
|
||||
gender = randint(0,1)
|
||||
print "Random gender"
|
||||
np.set_gender(gender)
|
||||
|
||||
# Name
|
||||
syllables1 = ["sa","li","na","ma","no","re","mi","cha","ki","du"]
|
||||
syllables2 = ["as","il","an","am","on","er","im","ach","ik","ud"]
|
||||
|
||||
name = RelLib.Name()
|
||||
firstname = ""
|
||||
for i in range(0,randint(2,5)):
|
||||
firstname = firstname + choice(syllables1)
|
||||
if not lastname:
|
||||
lastname = ""
|
||||
for i in range(0,randint(2,5)):
|
||||
lastname = lastname + choice(syllables1)
|
||||
name.set_first_name(firstname)
|
||||
name.set_surname(lastname)
|
||||
np.set_primary_name(name)
|
||||
|
||||
self.person_count = self.person_count+1
|
||||
|
||||
return( self.db.add_person(np,self.trans))
|
||||
|
||||
def generate_family(self,person1_h):
|
||||
print "generate_family"
|
||||
person1 = self.db.get_person_from_handle(person1_h)
|
||||
if person1.get_gender() == 1:
|
||||
person2_h = self.generate_person(0)
|
||||
else:
|
||||
person2_h = person1_h
|
||||
person1_h = self.generate_person(1)
|
||||
|
||||
fam = RelLib.Family()
|
||||
fam.set_father_handle(person1_h)
|
||||
fam.set_mother_handle(person2_h)
|
||||
fam.set_relationship(RelLib.Family.MARRIED)
|
||||
fam_h = self.db.add_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)
|
||||
person2 = self.db.get_person_from_handle(person2_h)
|
||||
person2.add_family_handle(fam_h)
|
||||
self.db.commit_person(person2,self.trans)
|
||||
|
||||
lastname = person1.get_primary_name().get_surname()
|
||||
|
||||
if self.person_count < 20:
|
||||
for i in range(0,randint(1,10)):
|
||||
child_h = self.generate_person(None, lastname)
|
||||
fam = self.db.get_family_from_handle(fam_h)
|
||||
fam.add_child_handle(child_h)
|
||||
self.db.commit_family(fam,self.trans)
|
||||
child = self.db.get_person_from_handle(child_h)
|
||||
child.add_parent_family_handle(fam_h,RelLib.Person.CHILD_REL_BIRTH,RelLib.Person.CHILD_REL_BIRTH)
|
||||
self.db.commit_person(child,self.trans)
|
||||
if randint(0,3) > 0:
|
||||
self.generate_family(child_h)
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
#
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
def TestcaseGeneratorPlugin(database,active_person,callback,parent=None):
|
||||
print "TestcaseGeneratorPlugin"
|
||||
fg = TestcaseGenerator(database,active_person,callback,parent)
|
||||
fg.run()
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
#
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from PluginMgr import register_tool
|
||||
|
||||
register_tool(
|
||||
TestcaseGeneratorPlugin,
|
||||
_("Generate Testcases for persons and families"),
|
||||
category=_("Debug"),
|
||||
description=_("The testcase generator will generate some persons and families."
|
||||
"that habe brolen links in the database or data that is in conflict to a relation.")
|
||||
)
|
Loading…
Reference in New Issue
Block a user