Skip to content
This repository was archived by the owner on Mar 5, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions gedcom/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,11 +422,20 @@ def name(self):
# malformed line
raise Exception
elif len(vals) == 3:
# Normal
first, last, dud = vals

first, last, first_tail = vals
first = first.strip()
last = last.strip()
first_tail = first_tail.strip()

if not first:
# only last name
first = None
elif first_tail:
# last name embedded in first name(s)
first = " ".join([first, first_tail])

elif len(vals) > 3:
raise Exception("Malformed NAME field: " + preferred_name.value)

return first, last

Expand Down Expand Up @@ -591,7 +600,6 @@ def wives(self):
return self.get_list("WIFE")



class Spouse(Element):
"""Generic base class for HUSB/WIFE."""

Expand Down
16 changes: 16 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,18 @@ def testSupportNameInOneWithSlashes(self):
gedcomfile = gedcom.parse_string("0 HEAD\n0 @I1@ INDI\n1 NAME Bob /Cox/\n\n0 TRLR")
self.assertEqual(gedcomfile['@I1@'].name, ('Bob', 'Cox'))

def testSupportNameWithOnlyFirstName(self):
gedcomfile = gedcom.parse_string("0 HEAD\n0 @I1@ INDI\n1 NAME William\n\n0 TRLR")
self.assertEqual(gedcomfile['@I1@'].name, ('William', None))

def testSupportNameWithOnlyLastName(self):
gedcomfile = gedcom.parse_string("0 HEAD\n0 @I1@ INDI\n1 NAME /Cox/\n\n0 TRLR")
self.assertEqual(gedcomfile['@I1@'].name, (None, 'Cox'))

def testSupportNameWithEmbeddedLastName(self):
gedcomfile = gedcom.parse_string("0 HEAD\n0 @I1@ INDI\n1 NAME Bob /Cox/ James\n\n0 TRLR")
self.assertEqual(gedcomfile['@I1@'].name, ('Bob James', 'Cox'))

def testSaveFile(self):
gedcomfile = gedcom.parse_string(GEDCOM_FILE)
outputfile = tempfile.NamedTemporaryFile()
Expand Down Expand Up @@ -283,6 +295,10 @@ def testInvalidNames(self):
gedcomfile = gedcom.parse_string("0 HEAD\n0 @I1@ INDI\n1 NAME Bob /Russel\n0 TRLR")
self.assertRaises(Exception, lambda : list(gedcomfile.individuals)[0].name)

def testNameWithTooManySlashes(self):
gedcomfile = gedcom.parse_string("0 HEAD\n0 @I1@ INDI\n1 NAME Bob/Robert /Russel/\n\n0 TRLR")
self.assertRaises(Exception, lambda : list(gedcomfile.individuals)[0].name)

def testDashInID(self):
gedcomfile = gedcom.parse_string("0 HEAD\n0 @I1-123@ INDI\n1 NAME\n2 GIVN Bob\n0 TRLR")
self.assertEqual(list(gedcomfile.individuals)[0].name, ('Bob', None))
Expand Down