2005-12-06 12:08:09 +05:30
|
|
|
# -*- coding: utf-8 -*-
|
2005-03-27 03:29:15 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2006-01-19 10:00:40 +05:30
|
|
|
# Copyright (C) 2000-2006 Martin Hawlisch, Donald N. Allingham
|
2005-03-27 03:29:15 +05:30
|
|
|
#
|
|
|
|
# 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
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2005-05-24 18:38:06 +05:30
|
|
|
import traceback
|
|
|
|
import sys
|
2005-03-27 03:29:15 +05:30
|
|
|
from random import randint,choice
|
2006-04-07 03:32:46 +05:30
|
|
|
from gettext import gettext as _
|
2005-03-27 03:29:15 +05:30
|
|
|
|
2005-03-31 19:53:39 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GNOME libraries
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import gtk
|
|
|
|
import gtk.glade
|
|
|
|
|
2005-03-27 03:29:15 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import Errors
|
2007-10-08 22:11:39 +05:30
|
|
|
import gen.lib
|
2006-03-11 06:42:06 +05:30
|
|
|
from PluginUtils import Tool, register_tool
|
2005-03-27 03:29:15 +05:30
|
|
|
import const
|
2006-03-03 18:01:35 +05:30
|
|
|
import Utils
|
2006-08-27 13:00:59 +05:30
|
|
|
import LdsUtils
|
2005-03-27 03:29:15 +05:30
|
|
|
from QuestionDialog import ErrorDialog
|
|
|
|
from DateHandler import parser as _dp
|
2005-05-24 18:38:06 +05:30
|
|
|
from DateHandler import displayer as _dd
|
2005-03-27 03:29:15 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2005-12-06 12:08:09 +05:30
|
|
|
class TestcaseGenerator(Tool.Tool):
|
|
|
|
NUMERIC = 0
|
|
|
|
FIRSTNAME = 1
|
|
|
|
FIRSTNAME_FEMALE = 2
|
|
|
|
FIRSTNAME_MALE = 3
|
|
|
|
LASTNAME = 4
|
|
|
|
NOTE = 5
|
|
|
|
SHORT = 6
|
|
|
|
LONG = 7
|
|
|
|
|
2006-04-10 04:23:53 +05:30
|
|
|
def __init__(self, dbstate, uistate, options_class, name, callback=None):
|
|
|
|
if dbstate.db.readonly:
|
2005-12-06 12:08:09 +05:30
|
|
|
return
|
2006-04-10 04:23:53 +05:30
|
|
|
|
|
|
|
Tool.Tool.__init__(self, dbstate, options_class, name)
|
2005-12-06 12:08:09 +05:30
|
|
|
|
2005-03-27 03:29:15 +05:30
|
|
|
self.person_count = 0
|
2005-03-31 19:53:39 +05:30
|
|
|
self.persons_todo = []
|
|
|
|
self.parents_todo = []
|
2005-12-06 12:08:09 +05:30
|
|
|
self.person_dates = {}
|
2006-03-03 18:01:35 +05:30
|
|
|
self.generated_repos = []
|
2005-12-06 12:08:09 +05:30
|
|
|
self.generated_sources = []
|
|
|
|
self.generated_media = []
|
|
|
|
self.generated_places = []
|
2005-12-30 21:26:21 +05:30
|
|
|
self.generated_events = []
|
2006-04-05 22:27:28 +05:30
|
|
|
self.generated_families = []
|
2007-02-23 02:26:58 +05:30
|
|
|
self.generated_notes = []
|
2005-12-06 12:08:09 +05:30
|
|
|
self.text_serial_number = 1
|
2005-03-27 03:29:15 +05:30
|
|
|
|
2005-12-06 12:08:09 +05:30
|
|
|
# If an active persons exists the generated tree is connected to that person
|
2006-04-10 04:23:53 +05:30
|
|
|
if self.person:
|
2005-12-06 12:08:09 +05:30
|
|
|
# try to get birth and death year
|
|
|
|
try:
|
2006-04-10 04:23:53 +05:30
|
|
|
bh = self.person.get_birth_handle()
|
2005-12-06 12:08:09 +05:30
|
|
|
b = self.db.get_event_from_handle( bh)
|
|
|
|
do = b.get_date_object()
|
|
|
|
birth = do.get_year()
|
|
|
|
except AttributeError:
|
|
|
|
birth = None
|
|
|
|
try:
|
2006-04-10 04:23:53 +05:30
|
|
|
dh = self.person.get_death_handle()
|
2005-12-06 12:08:09 +05:30
|
|
|
b = self.db.get_event_from_handle( dh)
|
|
|
|
do = b.get_date_object()
|
|
|
|
death = do.get_year()
|
|
|
|
except AttributeError:
|
|
|
|
death = None
|
|
|
|
if not birth and not death:
|
|
|
|
birth = randint(1700,1900)
|
|
|
|
if birth and not death:
|
|
|
|
death = birth + randint(20,90)
|
|
|
|
if death and not birth:
|
|
|
|
birth = death - randint(20,90)
|
2006-04-10 04:23:53 +05:30
|
|
|
self.person_dates[self.person.get_handle()] = (birth,death)
|
2005-12-06 12:08:09 +05:30
|
|
|
|
2006-04-10 04:23:53 +05:30
|
|
|
self.persons_todo.append(self.person.get_handle())
|
|
|
|
self.parents_todo.append(self.person.get_handle())
|
2005-12-06 12:08:09 +05:30
|
|
|
|
2006-04-10 04:23:53 +05:30
|
|
|
if uistate:
|
|
|
|
self.init_gui(uistate)
|
2005-12-06 12:08:09 +05:30
|
|
|
else:
|
|
|
|
self.run_tool(cli=True)
|
|
|
|
|
2006-04-10 04:23:53 +05:30
|
|
|
def init_gui(self,uistate):
|
2005-03-31 19:53:39 +05:30
|
|
|
title = "%s - GRAMPS" % _("Generate testcases")
|
|
|
|
self.top = gtk.Dialog(title)
|
|
|
|
self.top.set_default_size(400,150)
|
|
|
|
self.top.set_has_separator(False)
|
|
|
|
self.top.vbox.set_spacing(5)
|
|
|
|
label = gtk.Label('<span size="larger" weight="bold">%s</span>' % _("Generate testcases"))
|
|
|
|
label.set_use_markup(True)
|
|
|
|
self.top.vbox.pack_start(label,0,0,5)
|
|
|
|
|
|
|
|
self.check_bugs = gtk.CheckButton( _("Generate Database errors"))
|
2005-12-06 12:08:09 +05:30
|
|
|
self.check_bugs.set_active( self.options.handler.options_dict['bugs'])
|
2005-03-31 19:53:39 +05:30
|
|
|
self.top.vbox.pack_start(self.check_bugs,0,0,5)
|
|
|
|
|
2005-05-24 18:38:06 +05:30
|
|
|
self.check_dates = gtk.CheckButton( _("Generate date tests"))
|
2005-12-06 12:08:09 +05:30
|
|
|
self.check_dates.set_active( self.options.handler.options_dict['dates'])
|
2005-05-24 18:38:06 +05:30
|
|
|
self.top.vbox.pack_start(self.check_dates,0,0,5)
|
|
|
|
|
2005-03-31 19:53:39 +05:30
|
|
|
self.check_persons = gtk.CheckButton( _("Generate dummy families"))
|
2005-12-06 12:08:09 +05:30
|
|
|
self.check_persons.set_active( self.options.handler.options_dict['persons'])
|
2005-03-31 19:53:39 +05:30
|
|
|
self.top.vbox.pack_start(self.check_persons,0,0,5)
|
|
|
|
|
2005-04-14 18:48:20 +05:30
|
|
|
self.check_trans = gtk.CheckButton( _("Don't block transactions"))
|
2005-12-06 12:08:09 +05:30
|
|
|
self.check_trans.set_active( self.options.handler.options_dict['no_trans'])
|
2005-04-14 18:48:20 +05:30
|
|
|
self.top.vbox.pack_start(self.check_trans,0,0,5)
|
|
|
|
|
2005-12-06 12:08:09 +05:30
|
|
|
self.check_longnames = gtk.CheckButton( _("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_specialchars = gtk.CheckButton( _("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_serial = gtk.CheckButton( _("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)
|
|
|
|
|
2006-04-04 20:58:43 +05:30
|
|
|
self.check_linebreak = gtk.CheckButton( _("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)
|
|
|
|
|
2005-03-31 19:53:39 +05:30
|
|
|
self.entry_count = gtk.Entry()
|
2005-12-06 12:08:09 +05:30
|
|
|
self.entry_count.set_text( unicode( self.options.handler.options_dict['person_count']))
|
2005-03-31 19:53:39 +05:30
|
|
|
self.top.vbox.pack_start(self.entry_count,0,0,5)
|
|
|
|
|
|
|
|
self.top.add_button(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL)
|
|
|
|
self.top.add_button(gtk.STOCK_OK,gtk.RESPONSE_OK)
|
|
|
|
self.top.add_button(gtk.STOCK_HELP,gtk.RESPONSE_HELP)
|
|
|
|
self.top.show_all()
|
|
|
|
|
|
|
|
response = self.top.run()
|
2005-12-06 12:08:09 +05:30
|
|
|
self.options.handler.options_dict['bugs'] = int(
|
|
|
|
self.check_bugs.get_active())
|
|
|
|
self.options.handler.options_dict['dates'] = int(
|
|
|
|
self.check_dates.get_active())
|
|
|
|
self.options.handler.options_dict['persons'] = int(
|
|
|
|
self.check_persons.get_active())
|
|
|
|
self.options.handler.options_dict['no_trans'] = int(
|
|
|
|
self.check_trans.get_active())
|
|
|
|
self.options.handler.options_dict['long_names'] = int(
|
|
|
|
self.check_longnames.get_active())
|
|
|
|
self.options.handler.options_dict['specialchars'] = int(
|
|
|
|
self.check_specialchars.get_active())
|
|
|
|
self.options.handler.options_dict['add_serial'] = int(
|
|
|
|
self.check_serial.get_active())
|
2006-04-04 20:58:43 +05:30
|
|
|
self.options.handler.options_dict['add_linebreak'] = int(
|
|
|
|
self.check_linebreak.get_active())
|
2005-12-06 12:08:09 +05:30
|
|
|
self.options.handler.options_dict['person_count'] = int(
|
|
|
|
self.entry_count.get_text())
|
2005-03-31 19:53:39 +05:30
|
|
|
self.top.destroy()
|
|
|
|
|
|
|
|
if response == gtk.RESPONSE_OK:
|
2005-12-06 12:08:09 +05:30
|
|
|
self.run_tool( cli=False)
|
|
|
|
# Save options
|
|
|
|
self.options.handler.save_options()
|
|
|
|
|
|
|
|
def run_tool(self, cli=False):
|
|
|
|
self.cli = cli
|
|
|
|
if( not cli):
|
|
|
|
title = "%s - GRAMPS" % _("Generate testcases")
|
|
|
|
self.top = gtk.Window()
|
|
|
|
self.top.set_title(title)
|
|
|
|
self.top.set_position(gtk.WIN_POS_MOUSE)
|
|
|
|
self.top.set_modal(True)
|
|
|
|
self.top.set_default_size(400,150)
|
|
|
|
vbox = gtk.VBox()
|
|
|
|
self.top.add(vbox)
|
|
|
|
label = gtk.Label(_("Generating persons and families.\nPlease wait."))
|
|
|
|
vbox.pack_start(label,0,0,5)
|
|
|
|
self.progress = gtk.ProgressBar()
|
|
|
|
self.progress.set_fraction(0.0)
|
|
|
|
vbox.pack_end(self.progress,0,0,5)
|
|
|
|
self.top.show_all()
|
|
|
|
while gtk.events_pending():
|
|
|
|
gtk.main_iteration()
|
2005-03-31 19:53:39 +05:30
|
|
|
|
2005-04-14 18:48:20 +05:30
|
|
|
self.transaction_count = 0;
|
|
|
|
|
2005-12-06 12:08:09 +05:30
|
|
|
if not self.options.handler.options_dict['no_trans']:
|
2006-11-22 20:57:31 +05:30
|
|
|
batch = False
|
2005-04-14 18:48:20 +05:30
|
|
|
self.db.disable_signals()
|
2006-01-19 10:00:40 +05:30
|
|
|
else:
|
|
|
|
batch = False
|
2006-11-22 20:57:31 +05:30
|
|
|
self.trans = self.db.transaction_begin("")
|
2005-05-24 18:38:06 +05:30
|
|
|
|
2006-11-22 20:57:31 +05:30
|
|
|
if False and self.options.handler.options_dict['no_trans']:
|
2005-05-24 18:38:06 +05:30
|
|
|
|
|
|
|
print "TESTING SIGNALS..."
|
|
|
|
|
|
|
|
print "\nCREATE PERSON"
|
2007-10-08 22:11:39 +05:30
|
|
|
p = gen.lib.Person()
|
2006-11-22 20:57:31 +05:30
|
|
|
h = self.db.add_person( p, self.trans)
|
2005-05-24 18:38:06 +05:30
|
|
|
print "\nUPDATE PERSON"
|
|
|
|
self.db.commit_person( p, self.trans)
|
|
|
|
print "\nDELETE PERSON"
|
2006-11-22 20:57:31 +05:30
|
|
|
self.db.remove_person( h, self.trans)
|
2005-05-24 18:38:06 +05:30
|
|
|
|
|
|
|
print "\nCREATE FAMILY"
|
2007-10-08 22:11:39 +05:30
|
|
|
f = gen.lib.Family()
|
2006-11-22 20:57:31 +05:30
|
|
|
h = self.db.add_family( f, self.trans)
|
2005-05-24 18:38:06 +05:30
|
|
|
print "\nUPDATE FAMILY"
|
|
|
|
self.db.commit_family( f, self.trans)
|
|
|
|
print "\nDELETE FAMILY"
|
2006-11-22 20:57:31 +05:30
|
|
|
self.db.remove_family( h, self.trans)
|
2005-05-24 18:38:06 +05:30
|
|
|
|
|
|
|
print "\nCREATE EVENT"
|
2007-10-08 22:11:39 +05:30
|
|
|
e = gen.lib.Event()
|
2006-11-22 20:57:31 +05:30
|
|
|
h = self.db.add_event( e, self.trans)
|
2005-05-24 18:38:06 +05:30
|
|
|
print "\nUPDATE EVENT"
|
|
|
|
self.db.commit_event( e, self.trans)
|
|
|
|
print "\nDELETE EVENT"
|
2006-11-22 20:57:31 +05:30
|
|
|
self.db.remove_event( h, self.trans)
|
2005-05-24 18:38:06 +05:30
|
|
|
|
|
|
|
print "\nCREATE PLACE"
|
2007-10-08 22:11:39 +05:30
|
|
|
p = gen.lib.Place()
|
2006-11-22 20:57:31 +05:30
|
|
|
h = self.db.add_place( p, self.trans)
|
2005-05-24 18:38:06 +05:30
|
|
|
print "\nUPDATE PLACE"
|
|
|
|
self.db.commit_place( p, self.trans)
|
|
|
|
print "\nDELETE PLACE"
|
2006-11-22 20:57:31 +05:30
|
|
|
self.db.remove_place( h, self.trans)
|
2005-05-24 18:38:06 +05:30
|
|
|
|
|
|
|
print "\nCREATE SOURCE"
|
2007-10-08 22:11:39 +05:30
|
|
|
s = gen.lib.Source()
|
2006-11-22 20:57:31 +05:30
|
|
|
h = self.db.add_source( s, self.trans)
|
2005-05-24 18:38:06 +05:30
|
|
|
print "\nUPDATE SOURCE"
|
|
|
|
self.db.commit_source( s, self.trans)
|
|
|
|
print "\nDELETE SOURCE"
|
2006-11-22 20:57:31 +05:30
|
|
|
self.db.remove_source( h, self.trans)
|
2005-05-24 18:38:06 +05:30
|
|
|
|
|
|
|
print "\nCREATE MEDIA"
|
2007-10-08 22:11:39 +05:30
|
|
|
m = gen.lib.MediaObject()
|
2006-11-22 20:57:31 +05:30
|
|
|
h = self.db.add_object( m, self.trans)
|
2005-05-24 18:38:06 +05:30
|
|
|
print "\nUPDATE MEDIA"
|
|
|
|
self.db.commit_media_object( m, self.trans)
|
|
|
|
print "\nDELETE MEDIA"
|
2006-11-22 20:57:31 +05:30
|
|
|
self.db.remove_object( h, self.trans)
|
2005-05-24 18:38:06 +05:30
|
|
|
|
|
|
|
print "DONE."
|
|
|
|
|
|
|
|
|
|
|
|
print "TESTING DB..."
|
|
|
|
|
|
|
|
print "\nCREATE PERSON None"
|
|
|
|
self.db.add_person( None, self.trans)
|
|
|
|
print "\nUPDATE PERSON None"
|
|
|
|
self.db.commit_person( None, self.trans)
|
|
|
|
print "\nDELETE PERSON Invalid Handle"
|
|
|
|
self.db.remove_person( "Invalid Handle", self.trans)
|
|
|
|
|
|
|
|
print "\nCREATE FAMILY None"
|
|
|
|
self.db.add_family( None, self.trans)
|
|
|
|
print "\nUPDATE FAMILY None"
|
|
|
|
self.db.commit_family( None, self.trans)
|
|
|
|
print "\nDELETE FAMILY Invalid Handle"
|
|
|
|
self.db.remove_family( "Invalid Handle", self.trans)
|
|
|
|
|
|
|
|
print "\nCREATE EVENT None"
|
|
|
|
self.db.add_event( None, self.trans)
|
|
|
|
print "\nUPDATE EVENT None"
|
|
|
|
self.db.commit_event( None, self.trans)
|
|
|
|
print "\nDELETE EVENT Invalid Handle"
|
|
|
|
self.db.remove_event( "Invalid Handle", self.trans)
|
|
|
|
|
|
|
|
print "\nCREATE PLACE None"
|
|
|
|
self.db.add_place( None, self.trans)
|
|
|
|
print "\nUPDATE PLACE None"
|
|
|
|
self.db.commit_place( None, self.trans)
|
|
|
|
print "\nDELETE PLACE Invalid Handle"
|
|
|
|
self.db.remove_place( "Invalid Handle", self.trans)
|
|
|
|
|
|
|
|
print "\nCREATE SOURCE None"
|
|
|
|
self.db.add_source( None, self.trans)
|
|
|
|
print "\nUPDATE SOURCE None"
|
|
|
|
self.db.commit_source( None, self.trans)
|
|
|
|
print "\nDELETE SOURCE Invalid Handle"
|
|
|
|
self.db.remove_source( "Invalid Handle", self.trans)
|
|
|
|
|
|
|
|
print "\nCREATE MEDIA None"
|
|
|
|
self.db.add_object( None, self.trans)
|
|
|
|
print "\nUPDATE MEDIA None"
|
|
|
|
self.db.commit_media_object( None, self.trans)
|
|
|
|
print "\nDELETE MEDIA Invalid Handle"
|
|
|
|
self.db.remove_object( "Invalid Handle", self.trans)
|
|
|
|
|
|
|
|
print "DONE."
|
|
|
|
|
|
|
|
|
2006-03-03 18:01:35 +05:30
|
|
|
# if self.options.handler.options_dict['bugs']\
|
|
|
|
# or self.options.handler.options_dict['dates']\
|
|
|
|
# or self.options.handler.options_dict['persons']:
|
|
|
|
# # bootstrap random source and media
|
|
|
|
# self.rand_source()
|
|
|
|
# self.rand_media()
|
2005-12-06 12:08:09 +05:30
|
|
|
|
|
|
|
|
|
|
|
if self.options.handler.options_dict['bugs']:
|
2005-03-31 19:53:39 +05:30
|
|
|
self.generate_broken_relations()
|
2005-05-24 18:38:06 +05:30
|
|
|
|
2005-12-06 12:08:09 +05:30
|
|
|
if self.options.handler.options_dict['dates']:
|
2005-05-24 18:38:06 +05:30
|
|
|
self.generate_date_tests()
|
2005-03-31 19:53:39 +05:30
|
|
|
|
2005-12-06 12:08:09 +05:30
|
|
|
if self.options.handler.options_dict['persons']:
|
2006-11-22 20:57:31 +05:30
|
|
|
while True:
|
|
|
|
if not self.persons_todo:
|
|
|
|
ph = self.generate_person(0)
|
|
|
|
self.persons_todo.append( ph)
|
|
|
|
self.parents_todo.append( ph)
|
|
|
|
person_h = self.persons_todo.pop(0)
|
2005-03-31 19:53:39 +05:30
|
|
|
self.generate_family(person_h)
|
2005-04-02 02:02:06 +05:30
|
|
|
if randint(0,3) == 0:
|
|
|
|
self.generate_family(person_h)
|
|
|
|
if randint(0,7) == 0:
|
|
|
|
self.generate_family(person_h)
|
2005-12-06 12:08:09 +05:30
|
|
|
if self.person_count > self.options.handler.options_dict['person_count']:
|
2005-03-31 19:53:39 +05:30
|
|
|
break
|
|
|
|
for child_h in self.parents_todo:
|
|
|
|
self.generate_parents(child_h)
|
2005-12-06 12:08:09 +05:30
|
|
|
if self.person_count > self.options.handler.options_dict['person_count']:
|
2005-03-31 19:53:39 +05:30
|
|
|
break
|
|
|
|
|
2005-03-27 03:29:15 +05:30
|
|
|
self.db.transaction_commit(self.trans,_("Testcase generator"))
|
2005-12-06 12:08:09 +05:30
|
|
|
if not self.options.handler.options_dict['no_trans']:
|
2005-04-14 18:48:20 +05:30
|
|
|
self.db.enable_signals()
|
|
|
|
self.db.request_rebuild()
|
2005-12-06 12:08:09 +05:30
|
|
|
if( not cli):
|
|
|
|
self.top.destroy()
|
2005-03-31 19:53:39 +05:30
|
|
|
|
2005-03-27 03:29:15 +05:30
|
|
|
|
|
|
|
def generate_broken_relations(self):
|
|
|
|
# Create a family, that links to father and mother, but father does not link back
|
2007-10-08 22:11:39 +05:30
|
|
|
person1_h = self.generate_person(gen.lib.Person.MALE,"Broken1","Family links to this person, but person does not link back")
|
|
|
|
person2_h = self.generate_person(gen.lib.Person.FEMALE,"Broken1",None)
|
|
|
|
fam = gen.lib.Family()
|
2005-03-27 03:29:15 +05:30
|
|
|
fam.set_father_handle(person1_h)
|
|
|
|
fam.set_mother_handle(person2_h)
|
2007-10-08 22:11:39 +05:30
|
|
|
fam.set_relationship((gen.lib.FamilyRelType.MARRIED,''))
|
2005-03-27 03:29:15 +05:30
|
|
|
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)
|
2005-04-14 18:48:20 +05:30
|
|
|
self.commit_transaction() # COMMIT TRANSACTION STEP
|
2005-03-27 03:29:15 +05:30
|
|
|
|
|
|
|
# Create a family, that misses the link to the father
|
2007-10-08 22:11:39 +05:30
|
|
|
person1_h = self.generate_person(gen.lib.Person.MALE,"Broken2",None)
|
|
|
|
person2_h = self.generate_person(gen.lib.Person.FEMALE,"Broken2",None)
|
|
|
|
fam = gen.lib.Family()
|
2005-03-27 03:29:15 +05:30
|
|
|
#fam.set_father_handle(person1_h)
|
|
|
|
fam.set_mother_handle(person2_h)
|
2007-10-08 22:11:39 +05:30
|
|
|
fam.set_relationship((gen.lib.FamilyRelType.MARRIED,''))
|
2005-03-27 03:29:15 +05:30
|
|
|
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)
|
2005-04-14 18:48:20 +05:30
|
|
|
self.commit_transaction() # COMMIT TRANSACTION STEP
|
2005-03-27 03:29:15 +05:30
|
|
|
|
|
|
|
# Create a family, that misses the link to the mother
|
2007-10-08 22:11:39 +05:30
|
|
|
person1_h = self.generate_person(gen.lib.Person.MALE,"Broken3",None)
|
|
|
|
person2_h = self.generate_person(gen.lib.Person.FEMALE,"Broken3",None)
|
|
|
|
fam = gen.lib.Family()
|
2005-03-27 03:29:15 +05:30
|
|
|
fam.set_father_handle(person1_h)
|
|
|
|
#fam.set_mother_handle(person2_h)
|
2007-10-08 22:11:39 +05:30
|
|
|
fam.set_relationship((gen.lib.FamilyRelType.MARRIED,''))
|
2005-03-27 03:29:15 +05:30
|
|
|
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)
|
2005-04-14 18:48:20 +05:30
|
|
|
self.commit_transaction() # COMMIT TRANSACTION STEP
|
2005-03-27 03:29:15 +05:30
|
|
|
|
|
|
|
# Create a family, that links to father and mother, but father does not link back
|
2007-10-08 22:11:39 +05:30
|
|
|
person1_h = self.generate_person(gen.lib.Person.MALE,"Broken4",None)
|
|
|
|
person2_h = self.generate_person(gen.lib.Person.FEMALE,"Broken4","Family links to this person, but person does not link back")
|
|
|
|
fam = gen.lib.Family()
|
2005-03-27 03:29:15 +05:30
|
|
|
fam.set_father_handle(person1_h)
|
|
|
|
fam.set_mother_handle(person2_h)
|
2007-10-08 22:11:39 +05:30
|
|
|
fam.set_relationship((gen.lib.FamilyRelType.MARRIED,''))
|
2005-03-27 03:29:15 +05:30
|
|
|
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)
|
2005-04-14 18:48:20 +05:30
|
|
|
self.commit_transaction() # COMMIT TRANSACTION STEP
|
2005-03-27 03:29:15 +05:30
|
|
|
|
|
|
|
# Create two married people of same sex.
|
2007-10-08 22:11:39 +05:30
|
|
|
person1_h = self.generate_person(gen.lib.Person.MALE,"Broken5",None)
|
|
|
|
person2_h = self.generate_person(gen.lib.Person.MALE,"Broken5",None)
|
|
|
|
fam = gen.lib.Family()
|
2005-03-27 03:29:15 +05:30
|
|
|
fam.set_father_handle(person1_h)
|
|
|
|
fam.set_mother_handle(person2_h)
|
2007-10-08 22:11:39 +05:30
|
|
|
fam.set_relationship((gen.lib.FamilyRelType.MARRIED,''))
|
2005-03-27 03:29:15 +05:30
|
|
|
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)
|
2005-04-14 18:48:20 +05:30
|
|
|
self.commit_transaction() # COMMIT TRANSACTION STEP
|
2005-03-27 03:29:15 +05:30
|
|
|
|
|
|
|
# Create a family, that contains an invalid handle to for the father
|
2007-10-08 22:11:39 +05:30
|
|
|
#person1_h = self.generate_person(gen.lib.Person.MALE,"Broken6",None)
|
|
|
|
person2_h = self.generate_person(gen.lib.Person.FEMALE,"Broken6",None)
|
|
|
|
fam = gen.lib.Family()
|
2005-03-27 03:29:15 +05:30
|
|
|
fam.set_father_handle("InvalidHandle1")
|
|
|
|
fam.set_mother_handle(person2_h)
|
2007-10-08 22:11:39 +05:30
|
|
|
fam.set_relationship((gen.lib.FamilyRelType.MARRIED,''))
|
2005-03-27 03:29:15 +05:30
|
|
|
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)
|
2005-04-14 18:48:20 +05:30
|
|
|
self.commit_transaction() # COMMIT TRANSACTION STEP
|
2005-03-27 03:29:15 +05:30
|
|
|
|
|
|
|
# Create a family, that contains an invalid handle to for the mother
|
2007-10-08 22:11:39 +05:30
|
|
|
person1_h = self.generate_person(gen.lib.Person.MALE,"Broken7",None)
|
|
|
|
#person2_h = self.generate_person(gen.lib.Person.FEMALE,"Broken7",None)
|
|
|
|
fam = gen.lib.Family()
|
2005-03-27 03:29:15 +05:30
|
|
|
fam.set_father_handle(person1_h)
|
|
|
|
fam.set_mother_handle("InvalidHandle2")
|
2007-10-08 22:11:39 +05:30
|
|
|
fam.set_relationship((gen.lib.FamilyRelType.MARRIED,''))
|
2005-03-27 03:29:15 +05:30
|
|
|
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)
|
2005-04-14 18:48:20 +05:30
|
|
|
self.commit_transaction() # COMMIT TRANSACTION STEP
|
2005-03-27 03:29:15 +05:30
|
|
|
|
|
|
|
|
2005-03-30 16:07:40 +05:30
|
|
|
# Creates a family where the child does not link back to the family
|
2007-10-08 22:11:39 +05:30
|
|
|
person1_h = self.generate_person(gen.lib.Person.MALE,"Broken8",None)
|
|
|
|
person2_h = self.generate_person(gen.lib.Person.FEMALE,"Broken8",None)
|
2005-03-30 16:07:40 +05:30
|
|
|
child_h = self.generate_person(None,"Broken8",None)
|
2007-10-08 22:11:39 +05:30
|
|
|
fam = gen.lib.Family()
|
2005-03-30 16:07:40 +05:30
|
|
|
fam.set_father_handle(person1_h)
|
|
|
|
fam.set_mother_handle(person2_h)
|
2007-10-08 22:11:39 +05:30
|
|
|
fam.set_relationship((gen.lib.FamilyRelType.MARRIED,''))
|
|
|
|
child_ref = gen.lib.ChildRef()
|
2006-08-28 01:43:55 +05:30
|
|
|
child_ref.set_reference_handle(child_h)
|
|
|
|
self.fill_object(child_ref)
|
|
|
|
fam.add_child_ref(child_ref)
|
2005-03-30 16:07:40 +05:30
|
|
|
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)
|
|
|
|
#child = self.db.get_person_from_handle(child_h)
|
|
|
|
#person2.add_parent_family_handle(fam_h)
|
|
|
|
#self.db.commit_person(child,self.trans)
|
2005-04-14 18:48:20 +05:30
|
|
|
self.commit_transaction() # COMMIT TRANSACTION STEP
|
2005-03-30 16:07:40 +05:30
|
|
|
|
|
|
|
# Creates a family where the child is not linked, but the child links to the family
|
2007-10-08 22:11:39 +05:30
|
|
|
person1_h = self.generate_person(gen.lib.Person.MALE,"Broken9",None)
|
|
|
|
person2_h = self.generate_person(gen.lib.Person.FEMALE,"Broken9",None)
|
2005-03-30 16:07:40 +05:30
|
|
|
child_h = self.generate_person(None,"Broken9",None)
|
2007-10-08 22:11:39 +05:30
|
|
|
fam = gen.lib.Family()
|
2005-03-30 16:07:40 +05:30
|
|
|
fam.set_father_handle(person1_h)
|
|
|
|
fam.set_mother_handle(person2_h)
|
2007-10-08 22:11:39 +05:30
|
|
|
fam.set_relationship((gen.lib.FamilyRelType.MARRIED,''))
|
2005-03-30 16:07:40 +05:30
|
|
|
#fam.add_child_handle(child_h)
|
2007-10-08 22:11:39 +05:30
|
|
|
child_ref = gen.lib.ChildRef()
|
2006-08-28 01:43:55 +05:30
|
|
|
child_ref.set_reference_handle(child_h)
|
|
|
|
self.fill_object(child_ref)
|
|
|
|
fam.add_child_ref(child_ref)
|
2005-03-30 16:07:40 +05:30
|
|
|
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)
|
|
|
|
child = self.db.get_person_from_handle(child_h)
|
2006-08-28 01:43:55 +05:30
|
|
|
child.add_parent_family_handle(fam_h)
|
2005-03-30 16:07:40 +05:30
|
|
|
self.db.commit_person(child,self.trans)
|
2005-04-14 18:48:20 +05:30
|
|
|
self.commit_transaction() # COMMIT TRANSACTION STEP
|
2005-03-30 16:07:40 +05:30
|
|
|
|
2005-04-01 15:29:18 +05:30
|
|
|
# Creates a person having a non existing birth event handle set
|
|
|
|
person_h = self.generate_person(None,"Broken11",None)
|
|
|
|
person = self.db.get_person_from_handle(person_h)
|
2007-10-08 22:11:39 +05:30
|
|
|
event_ref = gen.lib.EventRef()
|
2005-05-27 19:18:47 +05:30
|
|
|
event_ref.set_reference_handle("InvalidHandle4")
|
|
|
|
person.set_birth_ref(event_ref)
|
2005-04-01 15:29:18 +05:30
|
|
|
self.db.commit_person(person,self.trans)
|
2005-04-14 18:48:20 +05:30
|
|
|
self.commit_transaction() # COMMIT TRANSACTION STEP
|
2005-04-01 15:29:18 +05:30
|
|
|
|
|
|
|
# Creates a person having a non existing death event handle set
|
|
|
|
person_h = self.generate_person(None,"Broken12",None)
|
|
|
|
person = self.db.get_person_from_handle(person_h)
|
2007-10-08 22:11:39 +05:30
|
|
|
event_ref = gen.lib.EventRef()
|
2005-05-27 19:18:47 +05:30
|
|
|
event_ref.set_reference_handle("InvalidHandle5")
|
|
|
|
person.set_death_ref(event_ref)
|
2005-04-01 15:29:18 +05:30
|
|
|
self.db.commit_person(person,self.trans)
|
2005-04-14 18:48:20 +05:30
|
|
|
self.commit_transaction() # COMMIT TRANSACTION STEP
|
2005-04-01 15:29:18 +05:30
|
|
|
|
|
|
|
# Creates a person having a non existing event handle set
|
|
|
|
person_h = self.generate_person(None,"Broken13",None)
|
|
|
|
person = self.db.get_person_from_handle(person_h)
|
2007-10-08 22:11:39 +05:30
|
|
|
event_ref = gen.lib.EventRef()
|
2005-05-27 19:18:47 +05:30
|
|
|
event_ref.set_reference_handle("InvalidHandle6")
|
|
|
|
person.add_event_ref(event_ref)
|
2005-04-01 15:29:18 +05:30
|
|
|
self.db.commit_person(person,self.trans)
|
2005-04-14 18:48:20 +05:30
|
|
|
self.commit_transaction() # COMMIT TRANSACTION STEP
|
2005-04-01 15:29:18 +05:30
|
|
|
|
|
|
|
# Creates a person with a birth event having an empty type
|
|
|
|
person_h = self.generate_person(None,"Broken14",None)
|
2007-10-08 22:11:39 +05:30
|
|
|
event = gen.lib.Event()
|
2006-08-28 01:43:55 +05:30
|
|
|
event.set_type('')
|
2005-04-01 15:29:18 +05:30
|
|
|
event.set_description("Test for Broken14")
|
|
|
|
event_h = self.db.add_event(event,self.trans)
|
2007-10-08 22:11:39 +05:30
|
|
|
event_ref = gen.lib.EventRef()
|
2005-05-27 19:18:47 +05:30
|
|
|
event_ref.set_reference_handle(event_h)
|
2005-04-01 15:29:18 +05:30
|
|
|
person = self.db.get_person_from_handle(person_h)
|
2005-05-27 19:18:47 +05:30
|
|
|
person.set_birth_ref(event_ref)
|
2005-04-01 15:29:18 +05:30
|
|
|
self.db.commit_person(person,self.trans)
|
2005-04-14 18:48:20 +05:30
|
|
|
self.commit_transaction() # COMMIT TRANSACTION STEP
|
2005-04-01 15:29:18 +05:30
|
|
|
|
|
|
|
# Creates a person with a death event having an empty type
|
|
|
|
person_h = self.generate_person(None,"Broken15",None)
|
2007-10-08 22:11:39 +05:30
|
|
|
event = gen.lib.Event()
|
2005-04-01 15:29:18 +05:30
|
|
|
event.set_description("Test for Broken15")
|
|
|
|
event_h = self.db.add_event(event,self.trans)
|
2007-10-08 22:11:39 +05:30
|
|
|
event_ref = gen.lib.EventRef()
|
2005-05-27 19:18:47 +05:30
|
|
|
event_ref.set_reference_handle(event_h)
|
2005-04-01 15:29:18 +05:30
|
|
|
person = self.db.get_person_from_handle(person_h)
|
2005-05-27 19:18:47 +05:30
|
|
|
person.set_death_ref(event_ref)
|
2005-04-01 15:29:18 +05:30
|
|
|
self.db.commit_person(person,self.trans)
|
2005-04-14 18:48:20 +05:30
|
|
|
self.commit_transaction() # COMMIT TRANSACTION STEP
|
2005-04-01 15:29:18 +05:30
|
|
|
|
|
|
|
# Creates a person with an event having an empty type
|
|
|
|
person_h = self.generate_person(None,"Broken16",None)
|
2007-10-08 22:11:39 +05:30
|
|
|
event = gen.lib.Event()
|
2005-04-01 15:29:18 +05:30
|
|
|
event.set_description("Test for Broken16")
|
|
|
|
event_h = self.db.add_event(event,self.trans)
|
2007-10-08 22:11:39 +05:30
|
|
|
event_ref = gen.lib.EventRef()
|
2005-05-27 19:18:47 +05:30
|
|
|
event_ref.set_reference_handle(event_h)
|
2005-04-01 15:29:18 +05:30
|
|
|
person = self.db.get_person_from_handle(person_h)
|
2005-05-27 19:18:47 +05:30
|
|
|
person.add_event_ref(event_ref)
|
2005-04-01 15:29:18 +05:30
|
|
|
self.db.commit_person(person,self.trans)
|
2005-04-14 18:48:20 +05:30
|
|
|
self.commit_transaction() # COMMIT TRANSACTION STEP
|
2005-04-01 15:29:18 +05:30
|
|
|
|
2005-12-06 12:08:09 +05:30
|
|
|
# Creates a person with a birth event pointing to nonexisting place
|
|
|
|
person_h = self.generate_person(None,"Broken17",None)
|
2007-10-08 22:11:39 +05:30
|
|
|
event = gen.lib.Event()
|
|
|
|
event.set_type(gen.lib.EventType.BIRTH)
|
2005-12-06 12:08:09 +05:30
|
|
|
event.set_place_handle("InvalidHandle7")
|
|
|
|
event.set_description("Test for Broken17")
|
|
|
|
event_h = self.db.add_event(event,self.trans)
|
2007-10-08 22:11:39 +05:30
|
|
|
event_ref = gen.lib.EventRef()
|
2006-08-28 01:43:55 +05:30
|
|
|
event_ref.set_reference_handle(event_h)
|
2005-12-06 12:08:09 +05:30
|
|
|
person = self.db.get_person_from_handle(person_h)
|
2006-08-28 01:43:55 +05:30
|
|
|
person.set_birth_ref(event_ref)
|
2005-12-06 12:08:09 +05:30
|
|
|
self.db.commit_person(person,self.trans)
|
|
|
|
self.commit_transaction() # COMMIT TRANSACTION STEP
|
|
|
|
|
|
|
|
# Creates a person with an event pointing to nonexisting place
|
|
|
|
person_h = self.generate_person(None,"Broken18",None)
|
2007-10-08 22:11:39 +05:30
|
|
|
event = gen.lib.Event()
|
|
|
|
event.set_type(gen.lib.EventType.BIRTH)
|
2005-12-06 12:08:09 +05:30
|
|
|
event.set_place_handle("InvalidHandle8")
|
|
|
|
event.set_description("Test for Broken18")
|
|
|
|
event_h = self.db.add_event(event,self.trans)
|
2007-10-08 22:11:39 +05:30
|
|
|
event_ref = gen.lib.EventRef()
|
2006-08-28 01:43:55 +05:30
|
|
|
event_ref.set_reference_handle(event_h)
|
2005-12-06 12:08:09 +05:30
|
|
|
person = self.db.get_person_from_handle(person_h)
|
2006-08-28 01:43:55 +05:30
|
|
|
person.add_event_ref(event_ref)
|
2005-12-06 12:08:09 +05:30
|
|
|
self.db.commit_person(person,self.trans)
|
|
|
|
self.commit_transaction() # COMMIT TRANSACTION STEP
|
|
|
|
|
2005-04-01 15:29:18 +05:30
|
|
|
|
2005-05-24 18:38:06 +05:30
|
|
|
def generate_date_tests(self):
|
|
|
|
dates = []
|
|
|
|
# first some valid dates
|
2007-10-08 22:11:39 +05:30
|
|
|
calendar = gen.lib.Date.CAL_GREGORIAN
|
|
|
|
for quality in (gen.lib.Date.QUAL_NONE, gen.lib.Date.QUAL_ESTIMATED,
|
|
|
|
gen.lib.Date.QUAL_CALCULATED):
|
|
|
|
for modifier in (gen.lib.Date.MOD_NONE, gen.lib.Date.MOD_BEFORE,
|
|
|
|
gen.lib.Date.MOD_AFTER, gen.lib.Date.MOD_ABOUT):
|
2005-05-24 18:38:06 +05:30
|
|
|
for slash1 in (False,True):
|
2007-10-08 22:11:39 +05:30
|
|
|
d = gen.lib.Date()
|
2005-05-24 18:38:06 +05:30
|
|
|
d.set(quality,modifier,calendar,(4,7,1789,slash1),"Text comment")
|
|
|
|
dates.append( d)
|
2007-10-08 22:11:39 +05:30
|
|
|
for modifier in (gen.lib.Date.MOD_RANGE, gen.lib.Date.MOD_SPAN):
|
2005-05-24 18:38:06 +05:30
|
|
|
for slash1 in (False,True):
|
|
|
|
for slash2 in (False,True):
|
2007-10-08 22:11:39 +05:30
|
|
|
d = gen.lib.Date()
|
2005-05-24 18:38:06 +05:30
|
|
|
d.set(quality,modifier,calendar,(4,7,1789,slash1,5,8,1876,slash2),"Text comment")
|
|
|
|
dates.append( d)
|
2007-10-08 22:11:39 +05:30
|
|
|
modifier = gen.lib.Date.MOD_TEXTONLY
|
|
|
|
d = gen.lib.Date()
|
|
|
|
d.set(quality,modifier,calendar,gen.lib.Date.EMPTY,
|
2006-02-04 03:33:53 +05:30
|
|
|
"This is a textual date")
|
2005-05-24 18:38:06 +05:30
|
|
|
dates.append( d)
|
|
|
|
|
2006-11-22 20:57:31 +05:30
|
|
|
# test invalid dates
|
|
|
|
dateval = (4,7,1789,False,5,8,1876,False)
|
|
|
|
for l in range(1,len(dateval)):
|
2007-10-08 22:11:39 +05:30
|
|
|
d = gen.lib.Date()
|
2006-11-22 20:57:31 +05:30
|
|
|
try:
|
2007-10-08 22:11:39 +05:30
|
|
|
d.set(gen.lib.Date.QUAL_NONE,gen.lib.Date.MOD_NONE,
|
|
|
|
gen.lib.Date.CAL_GREGORIAN,dateval[:l],"Text comment")
|
2006-11-22 20:57:31 +05:30
|
|
|
dates.append( d)
|
|
|
|
except Errors.DateError, e:
|
|
|
|
d.set_as_text("Date identified value correctly as invalid.\n%s" % e)
|
|
|
|
dates.append( d)
|
|
|
|
except:
|
2007-10-08 22:11:39 +05:30
|
|
|
d = gen.lib.Date()
|
2006-11-22 20:57:31 +05:30
|
|
|
d.set_as_text("Date.set Exception %s" % ("".join(traceback.format_exception(*sys.exc_info())),))
|
|
|
|
dates.append( d)
|
|
|
|
for l in range(1,len(dateval)):
|
2007-10-08 22:11:39 +05:30
|
|
|
d = gen.lib.Date()
|
2006-11-22 20:57:31 +05:30
|
|
|
try:
|
2007-10-08 22:11:39 +05:30
|
|
|
d.set(gen.lib.Date.QUAL_NONE,gen.lib.Date.MOD_SPAN,gen.lib.Date.CAL_GREGORIAN,dateval[:l],"Text comment")
|
2006-11-22 20:57:31 +05:30
|
|
|
dates.append( d)
|
|
|
|
except Errors.DateError, e:
|
|
|
|
d.set_as_text("Date identified value correctly as invalid.\n%s" % e)
|
|
|
|
dates.append( d)
|
|
|
|
except:
|
2007-10-08 22:11:39 +05:30
|
|
|
d = gen.lib.Date()
|
2006-11-22 20:57:31 +05:30
|
|
|
d.set_as_text("Date.set Exception %s" % ("".join(traceback.format_exception(*sys.exc_info())),))
|
|
|
|
dates.append( d)
|
2007-10-08 22:11:39 +05:30
|
|
|
d = gen.lib.Date()
|
|
|
|
d.set(gen.lib.Date.QUAL_NONE,gen.lib.Date.MOD_NONE,
|
|
|
|
gen.lib.Date.CAL_GREGORIAN,(44,7,1789,False),"Text comment")
|
2006-11-22 20:57:31 +05:30
|
|
|
dates.append( d)
|
2007-10-08 22:11:39 +05:30
|
|
|
d = gen.lib.Date()
|
|
|
|
d.set(gen.lib.Date.QUAL_NONE,gen.lib.Date.MOD_NONE,
|
|
|
|
gen.lib.Date.CAL_GREGORIAN,(4,77,1789,False),"Text comment")
|
2006-11-22 20:57:31 +05:30
|
|
|
dates.append( d)
|
2007-10-08 22:11:39 +05:30
|
|
|
d = gen.lib.Date()
|
|
|
|
d.set(gen.lib.Date.QUAL_NONE,gen.lib.Date.MOD_SPAN,
|
|
|
|
gen.lib.Date.CAL_GREGORIAN,
|
2006-11-22 20:57:31 +05:30
|
|
|
(4,7,1789,False,55,8,1876,False),"Text comment")
|
|
|
|
dates.append( d)
|
2007-10-08 22:11:39 +05:30
|
|
|
d = gen.lib.Date()
|
|
|
|
d.set(gen.lib.Date.QUAL_NONE,gen.lib.Date.MOD_SPAN,
|
|
|
|
gen.lib.Date.CAL_GREGORIAN,
|
2006-11-22 20:57:31 +05:30
|
|
|
(4,7,1789,False,5,88,1876,False),"Text comment")
|
|
|
|
dates.append( d)
|
2005-05-24 18:38:06 +05:30
|
|
|
|
|
|
|
# now add them as birth to new persons
|
2006-11-22 20:57:31 +05:30
|
|
|
i = 1
|
2005-05-24 18:38:06 +05:30
|
|
|
for dateval in dates:
|
2007-10-08 22:11:39 +05:30
|
|
|
person = gen.lib.Person()
|
|
|
|
name = gen.lib.Name()
|
2006-11-22 20:57:31 +05:30
|
|
|
name.set_surname("DateTest")
|
|
|
|
name.set_first_name("Test %d" % i)
|
|
|
|
person.set_primary_name( name)
|
|
|
|
self.db.add_person(person,self.trans)
|
2007-10-08 22:11:39 +05:30
|
|
|
bevent = gen.lib.Event()
|
|
|
|
bevent.set_type(gen.lib.EventType.BIRTH)
|
2005-05-24 18:38:06 +05:30
|
|
|
bevent.set_date_object(dateval)
|
|
|
|
bevent_h = self.db.add_event(bevent,self.trans)
|
2005-12-30 21:26:21 +05:30
|
|
|
self.generated_events.append(bevent_h)
|
2007-10-08 22:11:39 +05:30
|
|
|
bevent_ref = gen.lib.EventRef()
|
2005-05-27 19:18:47 +05:30
|
|
|
bevent_ref.set_reference_handle(bevent_h)
|
2005-05-24 18:38:06 +05:30
|
|
|
# for the death event display the date as text and parse it back to a new date
|
|
|
|
ndate = None
|
|
|
|
try:
|
|
|
|
datestr = _dd.display( dateval)
|
|
|
|
try:
|
|
|
|
ndate = _dp.parse( datestr)
|
|
|
|
if not ndate:
|
2007-10-08 22:11:39 +05:30
|
|
|
ndate = gen.lib.Date()
|
2005-05-24 18:38:06 +05:30
|
|
|
ndate.set_as_text("DateParser None")
|
2007-10-08 22:11:39 +05:30
|
|
|
person.set_marker(gen.lib.MarkerType.TODO_TYPE)
|
2006-11-22 20:57:31 +05:30
|
|
|
else:
|
2007-10-08 22:11:39 +05:30
|
|
|
person.set_marker(gen.lib.MarkerType.COMPLETE)
|
2005-05-24 18:38:06 +05:30
|
|
|
except:
|
2007-10-08 22:11:39 +05:30
|
|
|
ndate = gen.lib.Date()
|
2005-05-24 18:38:06 +05:30
|
|
|
ndate.set_as_text("DateParser Exception %s" % ("".join(traceback.format_exception(*sys.exc_info())),))
|
2007-10-08 22:11:39 +05:30
|
|
|
person.set_marker(gen.lib.MarkerType.TODO_TYPE)
|
2005-05-24 18:38:06 +05:30
|
|
|
except:
|
2007-10-08 22:11:39 +05:30
|
|
|
ndate = gen.lib.Date()
|
2005-05-24 18:38:06 +05:30
|
|
|
ndate.set_as_text("DateDisplay Exception: %s" % ("".join(traceback.format_exception(*sys.exc_info())),))
|
2007-10-08 22:11:39 +05:30
|
|
|
person.set_marker(gen.lib.MarkerType.TODO_TYPE)
|
2005-05-24 18:38:06 +05:30
|
|
|
|
2007-10-08 22:11:39 +05:30
|
|
|
if dateval.get_modifier() != gen.lib.Date.MOD_TEXTONLY \
|
|
|
|
and ndate.get_modifier() == gen.lib.Date.MOD_TEXTONLY:
|
2005-05-24 18:38:06 +05:30
|
|
|
# parser was unable to correctly parse the string
|
|
|
|
ndate.set_as_text( "TEXTONLY: "+ndate.get_text())
|
2007-10-08 22:11:39 +05:30
|
|
|
person.set_marker(gen.lib.MarkerType.TODO_TYPE)
|
|
|
|
if dateval.get_modifier() == gen.lib.Date.MOD_TEXTONLY \
|
2006-11-22 20:57:31 +05:30
|
|
|
and dateval.get_text().count("Traceback") \
|
2007-10-08 22:11:39 +05:30
|
|
|
and person.get_marker() == gen.lib.MarkerType.COMPLETE:
|
|
|
|
person.set_marker(gen.lib.MarkerType.TODO_TYPE)
|
2005-05-24 18:38:06 +05:30
|
|
|
|
2007-10-08 22:11:39 +05:30
|
|
|
devent = gen.lib.Event()
|
|
|
|
devent.set_type(gen.lib.EventType.DEATH)
|
2005-05-24 18:38:06 +05:30
|
|
|
devent.set_date_object(ndate)
|
|
|
|
devent_h = self.db.add_event(devent,self.trans)
|
2005-12-30 21:26:21 +05:30
|
|
|
self.generated_events.append(devent_h)
|
2007-10-08 22:11:39 +05:30
|
|
|
devent_ref = gen.lib.EventRef()
|
2005-05-27 19:18:47 +05:30
|
|
|
devent_ref.set_reference_handle(devent_h)
|
|
|
|
person.set_birth_ref(bevent_ref)
|
|
|
|
person.set_death_ref(devent_ref)
|
2005-05-24 18:38:06 +05:30
|
|
|
self.db.commit_person(person,self.trans)
|
2006-11-22 20:57:31 +05:30
|
|
|
i = i + 1
|
2005-05-24 18:38:06 +05:30
|
|
|
self.commit_transaction() # COMMIT TRANSACTION STEP
|
2005-03-27 03:29:15 +05:30
|
|
|
|
2005-12-06 12:08:09 +05:30
|
|
|
def generate_person(self,gender=None,lastname=None,note=None, alive_in_year=None):
|
|
|
|
if not self.cli:
|
|
|
|
self.progress.set_fraction(min(1.0,max(0.0, 1.0*self.person_count/self.options.handler.options_dict['person_count'])))
|
|
|
|
if self.person_count % 10 == 0:
|
|
|
|
while gtk.events_pending():
|
|
|
|
gtk.main_iteration()
|
2005-03-31 19:53:39 +05:30
|
|
|
|
2005-04-14 18:48:20 +05:30
|
|
|
self.commit_transaction() # COMMIT TRANSACTION STEP
|
2005-03-31 19:53:39 +05:30
|
|
|
|
2007-10-08 22:11:39 +05:30
|
|
|
np = gen.lib.Person()
|
2006-03-03 18:01:35 +05:30
|
|
|
self.fill_object(np)
|
2005-05-26 11:18:14 +05:30
|
|
|
|
2005-03-27 03:29:15 +05:30
|
|
|
# Gender
|
|
|
|
if gender == None:
|
|
|
|
gender = randint(0,1)
|
2005-12-06 12:08:09 +05:30
|
|
|
if randint(0,10) == 1: # Set some persons to unknown gender
|
2007-10-08 22:11:39 +05:30
|
|
|
np.set_gender(gen.lib.Person.UNKNOWN)
|
2005-12-06 12:08:09 +05:30
|
|
|
else:
|
|
|
|
np.set_gender(gender)
|
2005-03-27 03:29:15 +05:30
|
|
|
|
|
|
|
# Name
|
2007-10-08 22:11:39 +05:30
|
|
|
name = gen.lib.Name()
|
2006-03-03 18:01:35 +05:30
|
|
|
self.fill_object( name)
|
2005-12-06 12:08:09 +05:30
|
|
|
(firstname,lastname) = self.rand_name(lastname, gender)
|
2005-03-27 03:29:15 +05:30
|
|
|
name.set_first_name(firstname)
|
|
|
|
name.set_surname(lastname)
|
2006-11-22 20:57:31 +05:30
|
|
|
if randint(0,1) == 1:
|
|
|
|
name.set_title( self.rand_text(self.SHORT))
|
|
|
|
if randint(0,1) == 1:
|
|
|
|
name.set_patronymic( self.rand_text(self.FIRSTNAME_MALE))
|
|
|
|
if randint(0,1) == 1:
|
|
|
|
name.set_surname_prefix( self.rand_text(self.SHORT))
|
|
|
|
if randint(0,1) == 1:
|
|
|
|
name.set_suffix( self.rand_text(self.SHORT))
|
|
|
|
if randint(0,1) == 1:
|
|
|
|
name.set_call_name( self.rand_text(self.FIRSTNAME))
|
2005-03-27 03:29:15 +05:30
|
|
|
np.set_primary_name(name)
|
2005-12-06 12:08:09 +05:30
|
|
|
|
|
|
|
# generate some slightly different alternate name
|
|
|
|
firstname2 = firstname.replace("m", "n").replace("l", "i").replace("b", "d")
|
|
|
|
if firstname2 != firstname:
|
2007-10-08 22:11:39 +05:30
|
|
|
alt_name = gen.lib.Name(name)
|
2006-11-22 20:57:31 +05:30
|
|
|
self.fill_object( alt_name)
|
|
|
|
if randint(0,2) == 1:
|
|
|
|
alt_name.set_surname(self.rand_text(self.LASTNAME))
|
|
|
|
elif randint(0,2) == 1:
|
|
|
|
alt_name.set_surname(lastname)
|
|
|
|
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:
|
|
|
|
alt_name.set_patronymic( self.rand_text(self.FIRSTNAME_MALE))
|
|
|
|
if randint(0,1) == 1:
|
|
|
|
alt_name.set_surname_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))
|
2005-12-06 12:08:09 +05:30
|
|
|
np.add_alternate_name( alt_name)
|
|
|
|
firstname2 = firstname.replace("a", "e").replace("o", "u").replace("r", "p")
|
|
|
|
if firstname2 != firstname:
|
2007-10-08 22:11:39 +05:30
|
|
|
alt_name = gen.lib.Name(name)
|
2006-11-22 20:57:31 +05:30
|
|
|
self.fill_object( alt_name)
|
|
|
|
if randint(0,2) == 1:
|
|
|
|
alt_name.set_surname(self.rand_text(self.LASTNAME))
|
|
|
|
elif randint(0,2) == 1:
|
|
|
|
alt_name.set_surname(lastname)
|
|
|
|
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:
|
|
|
|
alt_name.set_patronymic( self.rand_text(self.FIRSTNAME_MALE))
|
|
|
|
if randint(0,1) == 1:
|
|
|
|
alt_name.set_surname_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))
|
2005-12-06 12:08:09 +05:30
|
|
|
np.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)
|
|
|
|
|
|
|
|
# birth
|
|
|
|
if randint(0,1) == 1:
|
2007-10-08 22:11:39 +05:30
|
|
|
(birth_year, eref) = self.rand_personal_event( gen.lib.EventType.BIRTH, by,by)
|
2005-12-06 12:08:09 +05:30
|
|
|
np.set_birth_ref(eref)
|
2005-03-27 03:29:15 +05:30
|
|
|
|
2005-12-06 12:08:09 +05:30
|
|
|
# baptism
|
|
|
|
if randint(0,1) == 1:
|
2006-03-03 18:01:35 +05:30
|
|
|
(bapt_year, eref) = self.rand_personal_event(
|
2007-10-08 22:11:39 +05:30
|
|
|
choice( (gen.lib.EventType.BAPTISM, gen.lib.EventType.CHRISTEN)), by, by+2)
|
2005-12-06 12:08:09 +05:30
|
|
|
np.add_event_ref(eref)
|
|
|
|
|
|
|
|
# death
|
|
|
|
death_year = None
|
|
|
|
if randint(0,1) == 1:
|
2007-10-08 22:11:39 +05:30
|
|
|
(death_year, eref) = self.rand_personal_event( gen.lib.EventType.DEATH, dy,dy)
|
2005-12-06 12:08:09 +05:30
|
|
|
np.set_death_ref(eref)
|
|
|
|
|
|
|
|
# burial
|
|
|
|
if randint(0,1) == 1:
|
2006-03-03 18:01:35 +05:30
|
|
|
(bur_year, eref) = self.rand_personal_event(
|
2007-10-08 22:11:39 +05:30
|
|
|
choice( (gen.lib.EventType.BURIAL, gen.lib.EventType.CREMATION)), dy, dy+2)
|
2006-03-03 18:01:35 +05:30
|
|
|
np.add_event_ref(eref)
|
2005-12-30 21:26:21 +05:30
|
|
|
|
2006-03-03 18:01:35 +05:30
|
|
|
# some other events
|
|
|
|
while randint(0,5) == 1:
|
|
|
|
(birth_year, eref) = self.rand_personal_event( None, by,dy)
|
|
|
|
np.set_birth_ref(eref)
|
|
|
|
|
2005-12-30 21:26:21 +05:30
|
|
|
# some shared events
|
2006-04-14 00:50:11 +05:30
|
|
|
if self.generated_events:
|
|
|
|
while randint(0,5) == 1:
|
|
|
|
e_h = choice(self.generated_events)
|
2007-10-08 22:11:39 +05:30
|
|
|
eref = gen.lib.EventRef()
|
2006-04-14 18:09:17 +05:30
|
|
|
self.fill_object( eref)
|
|
|
|
eref.set_reference_handle(e_h)
|
2007-10-08 22:11:39 +05:30
|
|
|
eref.set_role( self.rand_type(gen.lib.EventRoleType()))
|
2006-04-14 18:09:17 +05:30
|
|
|
np.add_event_ref(eref)
|
2005-12-06 12:08:09 +05:30
|
|
|
|
2006-11-22 20:57:31 +05:30
|
|
|
# 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']:
|
|
|
|
break
|
|
|
|
if alive_in_year:
|
|
|
|
asso_h = self.generate_person(None, None, alive_in_year = alive_in_year)
|
|
|
|
else:
|
|
|
|
asso_h = self.generate_person()
|
2007-10-08 22:11:39 +05:30
|
|
|
asso = gen.lib.PersonRef()
|
2006-11-22 20:57:31 +05:30
|
|
|
asso.set_reference_handle(asso_h)
|
|
|
|
asso.set_relation(self.rand_text(self.SHORT))
|
|
|
|
self.fill_object(asso)
|
|
|
|
np.add_person_ref(asso)
|
|
|
|
if randint(0,2) == 0:
|
|
|
|
self.persons_todo.append(asso_h)
|
|
|
|
|
2005-12-06 12:08:09 +05:30
|
|
|
person_handle = self.db.add_person(np,self.trans)
|
|
|
|
|
2005-03-27 03:29:15 +05:30
|
|
|
self.person_count = self.person_count+1
|
2005-12-06 12:08:09 +05:30
|
|
|
self.person_dates[person_handle] = (by,dy)
|
2005-03-27 03:29:15 +05:30
|
|
|
|
2005-04-14 18:48:20 +05:30
|
|
|
self.commit_transaction() # COMMIT TRANSACTION STEP
|
|
|
|
|
2005-12-06 12:08:09 +05:30
|
|
|
return( person_handle)
|
2005-03-27 03:29:15 +05:30
|
|
|
|
|
|
|
def generate_family(self,person1_h):
|
|
|
|
person1 = self.db.get_person_from_handle(person1_h)
|
2006-04-22 01:33:09 +05:30
|
|
|
if not person1:
|
|
|
|
return
|
2005-12-06 12:08:09 +05:30
|
|
|
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))
|
|
|
|
|
2005-03-27 03:29:15 +05:30
|
|
|
if person1.get_gender() == 1:
|
2006-03-03 18:01:35 +05:30
|
|
|
if randint(0,7)==1:
|
|
|
|
person2_h = None
|
2005-12-06 12:08:09 +05:30
|
|
|
else:
|
2006-03-03 18:01:35 +05:30
|
|
|
if alive_in_year:
|
|
|
|
person2_h = self.generate_person(0, alive_in_year = alive_in_year)
|
|
|
|
else:
|
|
|
|
person2_h = self.generate_person(0)
|
2005-03-27 03:29:15 +05:30
|
|
|
else:
|
|
|
|
person2_h = person1_h
|
2006-03-03 18:01:35 +05:30
|
|
|
if randint(0,7)==1:
|
|
|
|
person1_h = None
|
2005-12-06 12:08:09 +05:30
|
|
|
else:
|
2006-03-03 18:01:35 +05:30
|
|
|
if alive_in_year:
|
|
|
|
person1_h = self.generate_person(1, alive_in_year = alive_in_year)
|
|
|
|
else:
|
|
|
|
person1_h = self.generate_person(1)
|
2005-03-27 03:29:15 +05:30
|
|
|
|
2006-03-03 18:01:35 +05:30
|
|
|
if person1_h and randint(0,2) > 0:
|
2005-03-31 19:53:39 +05:30
|
|
|
self.parents_todo.append(person1_h)
|
2006-03-03 18:01:35 +05:30
|
|
|
if person2_h and randint(0,2) > 0:
|
2005-03-31 19:53:39 +05:30
|
|
|
self.parents_todo.append(person2_h)
|
|
|
|
|
2007-10-08 22:11:39 +05:30
|
|
|
fam = gen.lib.Family()
|
2005-05-26 11:18:14 +05:30
|
|
|
self.add_defaults(fam)
|
2006-03-03 18:01:35 +05:30
|
|
|
if person1_h:
|
|
|
|
fam.set_father_handle(person1_h)
|
|
|
|
if person2_h:
|
|
|
|
fam.set_mother_handle(person2_h)
|
2005-03-27 03:29:15 +05:30
|
|
|
fam_h = self.db.add_family(fam,self.trans)
|
2006-04-05 22:27:28 +05:30
|
|
|
self.generated_families.append(fam_h)
|
2005-03-27 03:29:15 +05:30
|
|
|
fam = self.db.commit_family(fam,self.trans)
|
2006-03-03 18:01:35 +05:30
|
|
|
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)
|
|
|
|
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)
|
2005-03-27 03:29:15 +05:30
|
|
|
|
|
|
|
lastname = person1.get_primary_name().get_surname()
|
|
|
|
|
2005-03-31 19:53:39 +05:30
|
|
|
for i in range(0,randint(1,10)):
|
2006-11-22 20:57:31 +05:30
|
|
|
if self.person_count > self.options.handler.options_dict['person_count']:
|
|
|
|
break
|
2005-12-06 12:08:09 +05:30
|
|
|
if alive_in_year:
|
|
|
|
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]
|
|
|
|
alive_in_year = born
|
2005-03-31 19:53:39 +05:30
|
|
|
fam = self.db.get_family_from_handle(fam_h)
|
2007-10-08 22:11:39 +05:30
|
|
|
child_ref = gen.lib.ChildRef()
|
2006-04-14 00:50:11 +05:30
|
|
|
child_ref.set_reference_handle(child_h)
|
|
|
|
self.fill_object(child_ref)
|
|
|
|
fam.add_child_ref(child_ref)
|
2005-03-31 19:53:39 +05:30
|
|
|
self.db.commit_family(fam,self.trans)
|
|
|
|
child = self.db.get_person_from_handle(child_h)
|
2006-04-14 00:50:11 +05:30
|
|
|
child.add_parent_family_handle(fam_h)
|
2005-03-31 19:53:39 +05:30
|
|
|
self.db.commit_person(child,self.trans)
|
|
|
|
if randint(0,3) > 0:
|
|
|
|
self.persons_todo.append(child_h)
|
2005-04-14 18:48:20 +05:30
|
|
|
self.commit_transaction() # COMMIT TRANSACTION STEP
|
2005-04-02 02:02:06 +05:30
|
|
|
|
2005-03-31 19:53:39 +05:30
|
|
|
def generate_parents(self,child_h):
|
2005-05-28 02:29:59 +05:30
|
|
|
if not child_h:
|
|
|
|
return
|
2005-03-31 19:53:39 +05:30
|
|
|
child = self.db.get_person_from_handle(child_h)
|
2006-11-22 20:57:31 +05:30
|
|
|
if not child:
|
|
|
|
print "ERROR: Person handle %s does not exist in database" % child_h
|
|
|
|
return
|
2005-03-31 19:53:39 +05:30
|
|
|
if child.get_parent_family_handle_list():
|
|
|
|
return
|
|
|
|
|
2005-12-06 12:08:09 +05:30
|
|
|
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)
|
|
|
|
person2_h = self.generate_person(0, alive_in_year=born)
|
|
|
|
else:
|
|
|
|
person1_h = self.generate_person(1,lastname)
|
|
|
|
person2_h = self.generate_person(0)
|
2005-03-31 19:53:39 +05:30
|
|
|
|
2005-04-02 02:02:06 +05:30
|
|
|
if randint(0,2) > 1:
|
2005-03-31 19:53:39 +05:30
|
|
|
self.parents_todo.append(person1_h)
|
2005-04-02 02:02:06 +05:30
|
|
|
if randint(0,2) > 1:
|
2005-03-31 19:53:39 +05:30
|
|
|
self.parents_todo.append(person2_h)
|
|
|
|
|
2007-10-08 22:11:39 +05:30
|
|
|
fam = gen.lib.Family()
|
2005-12-06 12:08:09 +05:30
|
|
|
self.add_defaults(fam)
|
2005-03-31 19:53:39 +05:30
|
|
|
fam.set_father_handle(person1_h)
|
|
|
|
fam.set_mother_handle(person2_h)
|
2007-10-08 22:11:39 +05:30
|
|
|
child_ref = gen.lib.ChildRef()
|
2006-04-14 00:50:11 +05:30
|
|
|
child_ref.set_reference_handle(child_h)
|
|
|
|
self.fill_object(child_ref)
|
|
|
|
fam.add_child_ref(child_ref)
|
2005-03-31 19:53:39 +05:30
|
|
|
fam_h = self.db.add_family(fam,self.trans)
|
2006-04-05 22:27:28 +05:30
|
|
|
self.generated_families.append(fam_h)
|
2005-03-31 19:53:39 +05:30
|
|
|
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)
|
2006-04-14 00:50:11 +05:30
|
|
|
child.add_parent_family_handle(fam_h)
|
2005-03-31 19:53:39 +05:30
|
|
|
self.db.commit_person(child,self.trans)
|
2005-04-14 18:48:20 +05:30
|
|
|
self.commit_transaction() # COMMIT TRANSACTION STEP
|
2005-03-31 19:53:39 +05:30
|
|
|
|
2006-03-03 18:01:35 +05:30
|
|
|
def add_defaults(self,object):
|
|
|
|
self.fill_object( object)
|
2005-12-06 12:08:09 +05:30
|
|
|
|
|
|
|
def rand_name( self, lastname=None, gender=None):
|
2007-10-08 22:11:39 +05:30
|
|
|
if gender == gen.lib.Person.MALE:
|
2005-12-06 12:08:09 +05:30
|
|
|
firstname = self.rand_text( self.FIRSTNAME_MALE)
|
2007-10-08 22:11:39 +05:30
|
|
|
elif gender == gen.lib.Person.FEMALE:
|
2005-12-06 12:08:09 +05:30
|
|
|
firstname = self.rand_text( self.FIRSTNAME_FEMALE)
|
|
|
|
else:
|
|
|
|
firstname = self.rand_text( self.FIRSTNAME)
|
|
|
|
if not lastname:
|
|
|
|
lastname = self.rand_text( self.LASTNAME)
|
|
|
|
return (firstname,lastname)
|
|
|
|
|
|
|
|
def rand_date( self, start=None, end=None):
|
|
|
|
"""
|
|
|
|
Generates a random date object between the given years start and end
|
|
|
|
"""
|
|
|
|
if not start and not end:
|
|
|
|
start = randint(1700,2000)
|
|
|
|
if start and not end:
|
|
|
|
end = start + randint(0,100)
|
|
|
|
if end and not start:
|
|
|
|
start = end - randint(0,100)
|
|
|
|
year = randint(start,end)
|
|
|
|
|
2007-10-08 22:11:39 +05:30
|
|
|
ndate = gen.lib.Date()
|
2005-12-06 12:08:09 +05:30
|
|
|
if randint(0,10) == 1:
|
|
|
|
# Some get a textual date
|
|
|
|
ndate.set_as_text( choice((self.rand_text(self.SHORT),"Unknown","??","Don't know","TODO!")))
|
|
|
|
else:
|
|
|
|
if randint(0,10) == 1:
|
|
|
|
# some get an empty date
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
# regular dates
|
2007-10-08 22:11:39 +05:30
|
|
|
calendar = gen.lib.Date.CAL_GREGORIAN
|
|
|
|
quality = choice( (gen.lib.Date.QUAL_NONE,
|
|
|
|
gen.lib.Date.QUAL_ESTIMATED,
|
|
|
|
gen.lib.Date.QUAL_CALCULATED))
|
|
|
|
modifier = choice( (gen.lib.Date.MOD_NONE,
|
|
|
|
gen.lib.Date.MOD_BEFORE,
|
|
|
|
gen.lib.Date.MOD_AFTER,\
|
|
|
|
gen.lib.Date.MOD_ABOUT,
|
|
|
|
gen.lib.Date.MOD_RANGE,
|
|
|
|
gen.lib.Date.MOD_SPAN))
|
2005-12-06 12:08:09 +05:30
|
|
|
day = randint(0,28)
|
|
|
|
if day > 0: # avoid days without month
|
|
|
|
month = randint(1,12)
|
|
|
|
else:
|
|
|
|
month = randint(0,12)
|
|
|
|
|
2007-10-08 22:11:39 +05:30
|
|
|
if modifier in (gen.lib.Date.MOD_RANGE, gen.lib.Date.MOD_SPAN):
|
2005-12-06 12:08:09 +05:30
|
|
|
day2 = randint(0,28)
|
|
|
|
if day2 > 0:
|
|
|
|
month2 = randint(1,12)
|
|
|
|
else:
|
|
|
|
month2 = randint(0,12)
|
|
|
|
year2 = year + randint(1,5)
|
|
|
|
ndate.set(quality,modifier,calendar,(day,month,year,False,day2,month2,year2,False),"")
|
|
|
|
else:
|
|
|
|
ndate.set(quality,modifier,calendar,(day,month,year,False),"")
|
|
|
|
|
|
|
|
return (year, ndate)
|
2006-03-03 18:01:35 +05:30
|
|
|
|
|
|
|
def fill_object( self, o):
|
|
|
|
|
2007-10-08 22:11:39 +05:30
|
|
|
if isinstance(o,gen.lib.Address):
|
2006-03-03 18:01:35 +05:30
|
|
|
if randint(0,1) == 1:
|
|
|
|
o.set_street( self.rand_text(self.SHORT))
|
|
|
|
|
2007-10-08 22:11:39 +05:30
|
|
|
if issubclass(o.__class__,gen.lib._AddressBase.AddressBase):
|
2006-03-03 18:01:35 +05:30
|
|
|
while randint(0,1) == 1:
|
2007-10-08 22:11:39 +05:30
|
|
|
a = gen.lib.Address()
|
2006-03-03 18:01:35 +05:30
|
|
|
self.fill_object(a)
|
|
|
|
o.add_address( a)
|
|
|
|
|
2007-10-08 22:11:39 +05:30
|
|
|
if isinstance(o,gen.lib.Attribute):
|
|
|
|
o.set_type( self.rand_type(gen.lib.AttributeType()))
|
2006-03-03 18:01:35 +05:30
|
|
|
o.set_value( self.rand_text(self.SHORT))
|
|
|
|
|
2007-10-08 22:11:39 +05:30
|
|
|
if issubclass(o.__class__,gen.lib._AttributeBase.AttributeBase):
|
2006-03-03 18:01:35 +05:30
|
|
|
while randint(0,1) == 1:
|
2007-10-08 22:11:39 +05:30
|
|
|
a = gen.lib.Attribute()
|
2006-03-03 18:01:35 +05:30
|
|
|
self.fill_object(a)
|
|
|
|
o.add_attribute( a)
|
|
|
|
|
2007-10-08 22:11:39 +05:30
|
|
|
if isinstance(o,gen.lib.ChildRef):
|
2006-04-14 00:50:11 +05:30
|
|
|
if randint(0,3) == 1:
|
2007-10-08 22:11:39 +05:30
|
|
|
o.set_mother_relation( self.rand_type( gen.lib.ChildRefType()))
|
2006-04-14 00:50:11 +05:30
|
|
|
if randint(0,3) == 1:
|
2007-10-08 22:11:39 +05:30
|
|
|
o.set_father_relation( self.rand_type( gen.lib.ChildRefType()))
|
2006-04-14 00:50:11 +05:30
|
|
|
|
2007-10-08 22:11:39 +05:30
|
|
|
if issubclass(o.__class__,gen.lib._DateBase.DateBase):
|
2006-03-03 18:01:35 +05:30
|
|
|
if randint(0,1) == 1:
|
|
|
|
(y,d) = self.rand_date()
|
|
|
|
o.set_date_object( d)
|
|
|
|
|
2007-10-08 22:11:39 +05:30
|
|
|
if isinstance(o,gen.lib.Family):
|
2006-04-20 02:26:46 +05:30
|
|
|
if randint(0,2) == 1:
|
2007-10-08 22:11:39 +05:30
|
|
|
o.set_relationship( self.rand_type(gen.lib.FamilyRelType()))
|
2006-04-20 02:26:46 +05:30
|
|
|
else:
|
2007-10-08 22:11:39 +05:30
|
|
|
o.set_relationship(gen.lib.FamilyRelType(gen.lib.FamilyRelType.MARRIED))
|
2006-04-20 02:26:46 +05:30
|
|
|
|
2007-10-08 22:11:39 +05:30
|
|
|
if isinstance(o,gen.lib.LdsOrd):
|
2006-04-05 22:27:28 +05:30
|
|
|
if randint(0,1) == 1:
|
2006-05-24 10:58:33 +05:30
|
|
|
o.set_temple( choice( LdsUtils.temple_to_abrev.keys()))
|
2006-04-05 22:27:28 +05:30
|
|
|
|
2007-10-08 22:11:39 +05:30
|
|
|
if issubclass(o.__class__,gen.lib._LdsOrdBase.LdsOrdBase):
|
2006-04-05 22:27:28 +05:30
|
|
|
while randint(0,1) == 1:
|
2007-10-08 22:11:39 +05:30
|
|
|
ldsord = gen.lib.LdsOrd()
|
2006-04-05 22:27:28 +05:30
|
|
|
self.fill_object( ldsord)
|
|
|
|
# TODO: adapt type and status to family/person
|
2007-10-08 22:11:39 +05:30
|
|
|
#if isinstance(o,gen.lib.Person):
|
|
|
|
#if isinstance(o,gen.lib.Family):
|
2006-05-24 10:58:33 +05:30
|
|
|
ldsord.set_type( choice(
|
2007-10-08 22:11:39 +05:30
|
|
|
[item[0] for item in gen.lib.LdsOrd._TYPE_MAP] ))
|
|
|
|
ldsord.set_status( randint(0,len(gen.lib.LdsOrd._STATUS_MAP)-1))
|
2006-04-05 22:27:28 +05:30
|
|
|
if self.generated_families:
|
|
|
|
ldsord.set_family_handle( choice(self.generated_families))
|
|
|
|
o.add_lds_ord( ldsord)
|
|
|
|
|
2007-10-08 22:11:39 +05:30
|
|
|
if isinstance(o,gen.lib.Location):
|
2006-03-03 18:01:35 +05:30
|
|
|
if randint(0,1) == 1:
|
|
|
|
o.set_parish( self.rand_text(self.SHORT))
|
|
|
|
if randint(0,1) == 1:
|
|
|
|
o.set_county( self.rand_text(self.SHORT))
|
|
|
|
|
2007-10-08 22:11:39 +05:30
|
|
|
if issubclass(o.__class__,gen.lib._LocationBase.LocationBase):
|
2006-03-03 18:01:35 +05:30
|
|
|
if randint(0,1) == 1:
|
|
|
|
o.set_phone( self.rand_text(self.SHORT))
|
|
|
|
if randint(0,1) == 1:
|
|
|
|
o.set_city( self.rand_text(self.SHORT))
|
|
|
|
if randint(0,1) == 1:
|
|
|
|
o.set_state( self.rand_text(self.SHORT))
|
|
|
|
if randint(0,1) == 1:
|
|
|
|
o.set_country( self.rand_text(self.SHORT))
|
|
|
|
if randint(0,1) == 1:
|
|
|
|
o.set_postal_code( self.rand_text(self.SHORT))
|
|
|
|
|
2007-10-08 22:11:39 +05:30
|
|
|
if issubclass(o.__class__,gen.lib._MediaBase.MediaBase):
|
2006-03-03 18:01:35 +05:30
|
|
|
while randint(0,1) == 1:
|
2007-10-08 22:11:39 +05:30
|
|
|
o.add_media_reference( self.fill_object( gen.lib.MediaRef()))
|
2006-03-03 18:01:35 +05:30
|
|
|
|
2007-10-08 22:11:39 +05:30
|
|
|
if isinstance(o,gen.lib.MediaObject):
|
2006-12-12 17:19:57 +05:30
|
|
|
if randint(0,3) == 1:
|
|
|
|
o.set_description( self.rand_text(self.LONG))
|
|
|
|
else:
|
|
|
|
o.set_description( self.rand_text(self.SHORT))
|
|
|
|
o.set_path("/tmp/TestcaseGenerator.png")
|
|
|
|
o.set_mime_type("image/png")
|
2006-03-03 18:01:35 +05:30
|
|
|
|
2007-10-08 22:11:39 +05:30
|
|
|
if isinstance(o,gen.lib.MediaRef):
|
2006-03-03 18:01:35 +05:30
|
|
|
if not self.generated_media or randint(0,10) == 1:
|
2007-10-08 22:11:39 +05:30
|
|
|
m = gen.lib.MediaObject()
|
2006-03-03 18:01:35 +05:30
|
|
|
self.fill_object(m)
|
|
|
|
self.db.add_object( m, self.trans)
|
|
|
|
self.generated_media.append( m.get_handle())
|
|
|
|
o.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)))
|
|
|
|
|
2007-10-08 22:11:39 +05:30
|
|
|
if isinstance(o,gen.lib.Name):
|
|
|
|
o.set_type( self.rand_type( gen.lib.NameType()))
|
2006-04-14 18:09:17 +05:30
|
|
|
|
2007-10-08 22:11:39 +05:30
|
|
|
if isinstance(o,gen.lib.Note):
|
2007-02-23 02:26:58 +05:30
|
|
|
o.set( self.rand_text(self.NOTE))
|
2007-10-08 22:11:39 +05:30
|
|
|
o.set_format( choice( (gen.lib.Note.FLOWED,gen.lib.Note.FORMATTED)))
|
|
|
|
o.set_type( self.rand_type(gen.lib.NoteType()))
|
2007-02-23 02:26:58 +05:30
|
|
|
|
2007-10-08 22:11:39 +05:30
|
|
|
if issubclass(o.__class__,gen.lib._NoteBase.NoteBase):
|
2007-02-23 02:26:58 +05:30
|
|
|
while randint(0,1) == 1:
|
|
|
|
if not self.generated_notes or randint(0,10) == 1:
|
2007-10-08 22:11:39 +05:30
|
|
|
n = gen.lib.Note()
|
2007-02-23 02:26:58 +05:30
|
|
|
self.fill_object(n)
|
|
|
|
self.db.add_note( n, self.trans)
|
|
|
|
self.generated_notes.append( n.get_handle())
|
|
|
|
n_h = choice(self.generated_notes)
|
|
|
|
o.add_note(n_h)
|
2006-03-03 18:01:35 +05:30
|
|
|
|
2007-10-08 22:11:39 +05:30
|
|
|
if isinstance(o,gen.lib.Place):
|
2006-03-03 18:01:35 +05:30
|
|
|
o.set_title( self.rand_text(self.SHORT))
|
|
|
|
if randint(0,1) == 1:
|
|
|
|
o.set_longitude( self.rand_text(self.SHORT))
|
|
|
|
if randint(0,1) == 1:
|
|
|
|
o.set_latitude( self.rand_text(self.SHORT))
|
2007-10-08 22:11:39 +05:30
|
|
|
o.set_main_location( self.fill_object( gen.lib.Location()))
|
2006-03-03 18:01:35 +05:30
|
|
|
while randint(0,1) == 1:
|
2007-10-08 22:11:39 +05:30
|
|
|
o.add_alternate_locations( self.fill_object( gen.lib.Location()))
|
2006-03-03 18:01:35 +05:30
|
|
|
|
2007-10-08 22:11:39 +05:30
|
|
|
if issubclass(o.__class__,gen.lib._PrivacyBase.PrivacyBase):
|
2006-03-03 18:01:35 +05:30
|
|
|
o.set_privacy( randint(0,5) == 1)
|
|
|
|
|
2007-10-08 22:11:39 +05:30
|
|
|
if issubclass(o.__class__,gen.lib.PrimaryObject):
|
|
|
|
o.set_marker( self.rand_type(gen.lib.MarkerType()))
|
2006-03-03 18:01:35 +05:30
|
|
|
|
2007-10-08 22:11:39 +05:30
|
|
|
if isinstance(o,gen.lib.RepoRef):
|
2006-03-03 18:01:35 +05:30
|
|
|
if not self.generated_repos or randint(0,10) == 1:
|
2007-10-08 22:11:39 +05:30
|
|
|
r = gen.lib.Repository()
|
2006-03-03 18:01:35 +05:30
|
|
|
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))
|
|
|
|
if randint(0,1) == 1:
|
|
|
|
o.set_call_number( self.rand_text(self.SHORT))
|
2007-10-08 22:11:39 +05:30
|
|
|
o.set_media_type( self.rand_type(gen.lib.SourceMediaType()))
|
2006-03-03 18:01:35 +05:30
|
|
|
|
2007-10-08 22:11:39 +05:30
|
|
|
if isinstance(o,gen.lib.Repository):
|
|
|
|
o.set_type( self.rand_type(gen.lib.RepositoryType()))
|
2006-03-03 18:01:35 +05:30
|
|
|
o.set_name( self.rand_text(self.SHORT))
|
|
|
|
|
2007-10-08 22:11:39 +05:30
|
|
|
if isinstance(o,gen.lib.Source):
|
2006-03-03 18:01:35 +05:30
|
|
|
o.set_title( self.rand_text(self.SHORT))
|
|
|
|
if randint(0,1) == 1:
|
|
|
|
o.set_author( self.rand_text(self.SHORT))
|
|
|
|
if randint(0,1) == 1:
|
|
|
|
o.set_publication_info( self.rand_text(self.LONG))
|
|
|
|
if randint(0,1) == 1:
|
|
|
|
o.set_abbreviation( self.rand_text(self.SHORT))
|
|
|
|
while randint(0,1) == 1:
|
|
|
|
o.set_data_item( self.rand_text(self.SHORT), self.rand_text(self.SHORT))
|
|
|
|
while randint(0,1) == 1:
|
2007-10-08 22:11:39 +05:30
|
|
|
r = gen.lib.RepoRef()
|
2006-03-03 18:01:35 +05:30
|
|
|
self.fill_object(r)
|
|
|
|
o.add_repo_reference( r)
|
|
|
|
|
2007-10-08 22:11:39 +05:30
|
|
|
if issubclass(o.__class__,gen.lib._SourceBase.SourceBase):
|
2006-03-03 18:01:35 +05:30
|
|
|
while randint(0,1) == 1:
|
2007-10-08 22:11:39 +05:30
|
|
|
s = gen.lib.SourceRef()
|
2006-03-03 18:01:35 +05:30
|
|
|
self.fill_object(s)
|
|
|
|
o.add_source_reference( s)
|
|
|
|
|
2007-10-08 22:11:39 +05:30
|
|
|
if isinstance(o,gen.lib.SourceRef):
|
2006-03-03 18:01:35 +05:30
|
|
|
if not self.generated_sources or randint(0,10) == 1:
|
2007-10-08 22:11:39 +05:30
|
|
|
s = gen.lib.Source()
|
2006-03-03 18:01:35 +05:30
|
|
|
self.fill_object(s)
|
|
|
|
self.db.add_source( s, self.trans)
|
|
|
|
self.generated_sources.append( s.get_handle())
|
2006-05-23 05:26:57 +05:30
|
|
|
o.set_reference_handle( choice( self.generated_sources))
|
2006-03-03 18:01:35 +05:30
|
|
|
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)
|
2006-09-13 04:51:15 +05:30
|
|
|
o.set_confidence_level(choice(Utils.confidence.keys()))
|
2006-03-03 18:01:35 +05:30
|
|
|
|
2007-10-08 22:11:39 +05:30
|
|
|
if issubclass(o.__class__,gen.lib._UrlBase.UrlBase):
|
2006-03-03 18:01:35 +05:30
|
|
|
while randint(0,1) == 1:
|
2007-10-08 22:11:39 +05:30
|
|
|
u = gen.lib.Url()
|
2006-03-03 18:01:35 +05:30
|
|
|
self.fill_object(u)
|
|
|
|
o.add_url(u)
|
2005-12-06 12:08:09 +05:30
|
|
|
|
2007-10-08 22:11:39 +05:30
|
|
|
if isinstance(o,gen.lib.Url):
|
2006-12-12 17:19:57 +05:30
|
|
|
o.set_path("http://www.gramps-project.org/?test=%s" % self.rand_text(self.SHORT))
|
2006-03-03 18:01:35 +05:30
|
|
|
o.set_description( self.rand_text(self.SHORT))
|
2007-10-08 22:11:39 +05:30
|
|
|
o.set_type( self.rand_type(gen.lib.UrlType()))
|
2006-03-03 18:01:35 +05:30
|
|
|
|
|
|
|
return o
|
|
|
|
|
|
|
|
def rand_personal_event( self, type=None, start=None, end=None):
|
|
|
|
if type:
|
2007-10-08 22:11:39 +05:30
|
|
|
typeval = gen.lib.EventType(type)
|
2006-03-03 18:01:35 +05:30
|
|
|
else:
|
2007-10-08 22:11:39 +05:30
|
|
|
typeval = self.rand_type(gen.lib.EventType())
|
2006-03-03 18:01:35 +05:30
|
|
|
return self._rand_event( typeval, start, end)
|
2005-12-06 12:08:09 +05:30
|
|
|
|
2006-03-03 18:01:35 +05:30
|
|
|
def rand_family_event( self, type=None, start=None, end=None):
|
|
|
|
if type:
|
2007-10-08 22:11:39 +05:30
|
|
|
typeval = gen.lib.EventType(type)
|
2006-03-03 18:01:35 +05:30
|
|
|
else:
|
2007-10-08 22:11:39 +05:30
|
|
|
typeval = self.rand_type(gen.lib.EventType())
|
2006-03-03 18:01:35 +05:30
|
|
|
return self._rand_event( typeval, start, end)
|
|
|
|
|
|
|
|
def _rand_event( self, type, start, end):
|
2007-10-08 22:11:39 +05:30
|
|
|
e = gen.lib.Event()
|
2006-03-03 18:01:35 +05:30
|
|
|
self.fill_object(e)
|
|
|
|
e.set_type( type)
|
2006-08-27 13:00:59 +05:30
|
|
|
#if randint(0,1) == 1:
|
|
|
|
# e.set_cause( self.rand_text(self.SHORT))
|
2005-12-06 12:08:09 +05:30
|
|
|
if randint(0,1) == 1:
|
|
|
|
e.set_description( self.rand_text(self.LONG))
|
|
|
|
if randint(0,1) == 1:
|
|
|
|
e.set_place_handle( self.rand_place())
|
|
|
|
(year, d) = self.rand_date( start, end)
|
|
|
|
e.set_date_object( d)
|
2005-05-27 19:18:47 +05:30
|
|
|
event_h = self.db.add_event(e, self.trans)
|
2005-12-30 21:26:21 +05:30
|
|
|
self.generated_events.append(event_h)
|
2007-10-08 22:11:39 +05:30
|
|
|
event_ref = gen.lib.EventRef()
|
2006-03-03 18:01:35 +05:30
|
|
|
self.fill_object(event_ref)
|
2005-05-27 19:18:47 +05:30
|
|
|
event_ref.set_reference_handle(event_h)
|
2005-12-06 12:08:09 +05:30
|
|
|
return (year, event_ref)
|
|
|
|
|
2006-03-03 18:01:35 +05:30
|
|
|
def rand_type( self, list):
|
2007-10-08 22:11:39 +05:30
|
|
|
if issubclass( list.__class__, gen.lib.GrampsType):
|
2006-04-14 18:09:17 +05:30
|
|
|
map = list.get_map()
|
|
|
|
key = choice( map.keys())
|
|
|
|
if key == list.get_custom():
|
|
|
|
value = self.rand_text(self.SHORT)
|
|
|
|
else:
|
|
|
|
value = ''
|
|
|
|
list.set( (key,value))
|
|
|
|
return list
|
2005-12-06 12:08:09 +05:30
|
|
|
|
|
|
|
def rand_place( self):
|
|
|
|
if not self.generated_places or randint(0,10) == 1:
|
2007-10-08 22:11:39 +05:30
|
|
|
place = gen.lib.Place()
|
2006-03-03 18:01:35 +05:30
|
|
|
self.fill_object( place)
|
2005-12-06 12:08:09 +05:30
|
|
|
self.db.add_place( place, self.trans)
|
|
|
|
self.generated_places.append( place.get_handle())
|
2006-03-03 18:01:35 +05:30
|
|
|
return choice( self.generated_places)
|
2005-12-06 12:08:09 +05:30
|
|
|
|
|
|
|
def rand_text(self, type=None):
|
|
|
|
# for lastnamesnames
|
|
|
|
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"]
|
|
|
|
# others
|
|
|
|
syllables3 = ["ka", "po", "lo", "chi", "she", "di", "fa", "go", "ja", "ne", "pe"]
|
|
|
|
|
|
|
|
syllables = syllables1 + syllables2 +syllables3
|
|
|
|
minwords = 5
|
|
|
|
maxwords = 8
|
|
|
|
minsyllables = 2
|
|
|
|
maxsyllables = 5
|
|
|
|
|
|
|
|
result = ""
|
|
|
|
if self.options.handler.options_dict['specialchars']:
|
|
|
|
result = result + u"ä<ö&ü%ß'\""
|
|
|
|
if self.options.handler.options_dict['add_serial']:
|
|
|
|
result = result + "#+#%06d#-#" % self.text_serial_number
|
|
|
|
self.text_serial_number = self.text_serial_number + 1
|
|
|
|
|
|
|
|
if not type:
|
|
|
|
type = self.SHORT
|
|
|
|
|
|
|
|
if type == self.SHORT:
|
|
|
|
minwords = 1
|
|
|
|
maxwords = 3
|
|
|
|
minsyllables = 2
|
|
|
|
maxsyllables = 4
|
|
|
|
|
|
|
|
if type == self.LONG:
|
|
|
|
minwords = 5
|
|
|
|
maxwords = 8
|
|
|
|
minsyllables = 2
|
|
|
|
maxsyllables = 5
|
|
|
|
|
|
|
|
if type == self.FIRSTNAME:
|
|
|
|
type = choice( (self.FIRSTNAME_MALE,self.FIRSTNAME_FEMALE))
|
|
|
|
|
|
|
|
if type == self.FIRSTNAME_MALE or type == self.FIRSTNAME_FEMALE:
|
|
|
|
syllables = syllables2
|
|
|
|
minwords = 1
|
|
|
|
maxwords = 5
|
|
|
|
minsyllables = 2
|
|
|
|
maxsyllables = 5
|
|
|
|
if not self.options.handler.options_dict['long_names']:
|
|
|
|
maxwords = 2
|
|
|
|
maxsyllables = 3
|
|
|
|
|
|
|
|
if type == self.LASTNAME:
|
|
|
|
syllables = syllables1
|
|
|
|
minwords = 1
|
|
|
|
maxwords = 1
|
|
|
|
minsyllables = 2
|
|
|
|
maxsyllables = 5
|
|
|
|
if not self.options.handler.options_dict['long_names']:
|
|
|
|
maxsyllables = 3
|
|
|
|
|
|
|
|
if type == self.NOTE:
|
2006-04-14 18:09:17 +05:30
|
|
|
result = result + "Generated by TestcaseGenerator."
|
2005-12-06 12:08:09 +05:30
|
|
|
minwords = 20
|
|
|
|
maxwords = 100
|
|
|
|
|
|
|
|
if 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)
|
|
|
|
|
|
|
|
for i 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:
|
|
|
|
word = word + choice(("a","e","i","o","u"))
|
2007-02-23 02:26:58 +05:30
|
|
|
if randint(0,3) == 1:
|
|
|
|
word = word.title()
|
|
|
|
if type == self.NOTE:
|
|
|
|
if randint(0,10) == 1:
|
|
|
|
word = "<b>%s</b>" % word
|
|
|
|
elif randint(0,10) == 1:
|
|
|
|
word = "<i>%s</i>" % word
|
|
|
|
elif randint(0,10) == 1:
|
|
|
|
word = "<i>%s</i>" % word
|
2005-12-06 12:08:09 +05:30
|
|
|
if randint(0,20) == 1:
|
|
|
|
word = word + "."
|
|
|
|
elif randint(0,30) == 1:
|
|
|
|
word = word + ".\n"
|
|
|
|
result = result + word
|
|
|
|
|
|
|
|
if type == self.LASTNAME:
|
|
|
|
n = randint(0,2)
|
|
|
|
if n == 0:
|
|
|
|
result = result.title()
|
|
|
|
elif n == 1:
|
|
|
|
result = result.upper()
|
2006-04-04 20:58:43 +05:30
|
|
|
|
|
|
|
if self.options.handler.options_dict['add_linebreak']:
|
|
|
|
result = result + u"\nNEWLINE"
|
|
|
|
|
2005-12-06 12:08:09 +05:30
|
|
|
return result
|
|
|
|
|
2005-04-14 18:48:20 +05:30
|
|
|
def commit_transaction(self):
|
2006-11-22 20:57:31 +05:30
|
|
|
#if self.options.handler.options_dict['no_trans']:
|
|
|
|
self.db.transaction_commit(self.trans,_("Testcase generator step %d") % self.transaction_count)
|
|
|
|
self.transaction_count += 1
|
|
|
|
self.trans = self.db.transaction_begin()
|
2005-03-31 19:53:39 +05:30
|
|
|
|
2005-03-27 03:29:15 +05:30
|
|
|
|
2005-12-06 12:08:09 +05:30
|
|
|
#------------------------------------------------------------------------
|
2005-03-27 03:29:15 +05:30
|
|
|
#
|
2005-12-06 12:08:09 +05:30
|
|
|
#
|
2005-03-27 03:29:15 +05:30
|
|
|
#
|
2005-12-06 12:08:09 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
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 set_new_options(self):
|
|
|
|
# Options specific for this report
|
|
|
|
self.options_dict = {
|
|
|
|
'bugs' : 0,
|
|
|
|
'dates' : 1,
|
|
|
|
'persons' : 1,
|
|
|
|
'person_count' : 2000,
|
|
|
|
'no_trans' : 0,
|
|
|
|
'long_names' : 0,
|
|
|
|
'specialchars' : 0,
|
|
|
|
'add_serial' : 0,
|
2006-04-04 20:58:43 +05:30
|
|
|
'add_linebreak' : 0,
|
2005-12-06 12:08:09 +05:30
|
|
|
}
|
|
|
|
self.options_help = {
|
|
|
|
'bugs' : ("=0/1",
|
|
|
|
"Whether to create invalid database references.",
|
|
|
|
["Skip test","Create invalid Database references"],
|
|
|
|
True),
|
|
|
|
'dates' : ("=0/1",
|
|
|
|
"Whether to create test for date handling.",
|
|
|
|
["Skip test","Create date tests"],
|
|
|
|
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"),
|
|
|
|
'no_trans' : ("=0/1",
|
|
|
|
"Wheter to use one transaction or multiple small ones",
|
|
|
|
["One transaction","Multiple transactions"],
|
|
|
|
True),
|
|
|
|
'long_names' : ("=0/1",
|
|
|
|
"Wheter to create short or long names",
|
|
|
|
["Short names","Long names"],
|
|
|
|
True),
|
|
|
|
'specialchars' : ("=0/1",
|
|
|
|
"Wheter to ass some special characters to every text field",
|
|
|
|
["No special characters","Add special characters"],
|
|
|
|
True),
|
|
|
|
'add_serial' : ("=0/1",
|
|
|
|
"Wheter to add a serial number to every text field",
|
|
|
|
["No serial","Add serial number"],
|
|
|
|
True),
|
2006-04-04 20:58:43 +05:30
|
|
|
'add_linebreak' : ("=0/1",
|
|
|
|
"Wheter to add a line break to every text field",
|
|
|
|
["No linebreak","Add line break"],
|
|
|
|
True),
|
2005-12-06 12:08:09 +05:30
|
|
|
}
|
2005-03-27 03:29:15 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2005-12-06 12:08:09 +05:30
|
|
|
|
|
|
|
if __debug__:
|
|
|
|
register_tool(
|
|
|
|
name = 'testcasegenerator',
|
|
|
|
category = Tool.TOOL_DEBUG,
|
|
|
|
tool_class = TestcaseGenerator,
|
|
|
|
options_class = TestcaseGeneratorOptions,
|
|
|
|
modes = Tool.MODE_GUI | Tool.MODE_CLI,
|
|
|
|
translated_name = _("Generate Testcases for persons and families"),
|
|
|
|
status = _("Beta"),
|
|
|
|
author_name = "Martin Hawlisch",
|
|
|
|
author_email = "martin@hawlisch.de",
|
|
|
|
description = _("The testcase generator will generate some persons "
|
|
|
|
"and families that have broken links in the database "
|
|
|
|
"or data that is in conflict to a relation.")
|
|
|
|
)
|