PlaceName constructor shortcut; Place.set_name type check;

bug fixes for testcasegenerator

1. Added PlaceName(value=..., lang=...) shortcut; will add to others

2. Added an instance check on Place.set_name() to make sure it
is a PlaceName

3. Fixed Testcasegenerator to make proper fake places, and a bug
in handling windows
This commit is contained in:
Doug Blank 2015-05-27 18:13:44 -04:00
parent a943e63b84
commit 51402bd486
3 changed files with 11 additions and 3 deletions

View File

@ -314,6 +314,8 @@ class Place(CitationBase, NoteBase, MediaBase, UrlBase, PrimaryObject):
:param name: name to assign to the Place
:type name: PlaceName
"""
if not isinstance(name, PlaceName):
raise ValueError("Place.set_name(name) requires a PlaceName()")
self.name = name
def get_name(self):

View File

@ -45,7 +45,7 @@ class PlaceName(SecondaryObject, DateBase):
This class is for keeping information about place names.
"""
def __init__(self, source=None):
def __init__(self, source=None, **kwargs):
"""
Create a new PlaceName instance, copying from the source if present.
"""
@ -56,6 +56,11 @@ class PlaceName(SecondaryObject, DateBase):
else:
self.value = ''
self.lang = ''
for key in kwargs:
if key in ["value", "lang"]:
setattr(self, key, kwargs[key])
else:
raise AttributeError("PlaceName does not have property '%s'" % key)
def serialize(self):
"""

View File

@ -50,7 +50,7 @@ from gramps.gen.lib import (Address, Attribute, AttributeType, ChildRef,
ChildRefType, Citation, Date, Event, EventRef, EventRoleType,
EventType, Family, FamilyRelType, GrampsType, LdsOrd, Location,
MediaObject, MediaRef, Name, NameOriginType, NameType, Note,
NoteType, Person, PersonRef, Place, PlaceType, PlaceRef,
NoteType, Person, PersonRef, Place, PlaceType, PlaceRef, PlaceName,
RepoRef, Repository, RepositoryType, Source, SourceMediaType,
SrcAttribute, SrcAttributeType, Surname, Tag, Url, UrlType)
from gramps.gen.lib.addressbase import AddressBase
@ -194,6 +194,7 @@ class TestcaseGenerator(tool.BatchTool):
def init_gui(self,uistate):
title = "%s - Gramps" % _("Generate testcases")
self.top = Gtk.Dialog(title, parent=uistate.window)
self.window = uistate.window
self.top.set_default_size(400,150)
self.top.vbox.set_spacing(5)
label = Gtk.Label(label='<span size="larger" weight="bold">%s</span>' % _("Generate testcases"))
@ -1670,7 +1671,7 @@ class TestcaseGenerator(tool.BatchTool):
if isinstance(o, Place):
o.set_title(self.rand_text(self.LONG))
o.set_name(self.rand_text(self.SHORT))
o.set_name(PlaceName(value=self.rand_text(self.SHORT)))
o.set_code(self.rand_text(self.SHORT))
if randint(0, 1) == 1:
if randint(0, 4) == 1: