def testTitle(self): gedcomfile = gedcom.parse_string( "0 HEAD\n0 @I1@ INDI\n1 NAME\n2 GIVN Bob\n2 SURN Cox\n1 TITL King\n0 TRLR" ) self.assertEqual(list(gedcomfile.individuals)[0].title, 'King') gedcomfile = gedcom.parse_string( "0 HEAD\n0 @I1@ INDI\n1 NAME\n2 GIVN Bob\n2 SURN Cox\n0 TRLR") self.assertEqual(list(gedcomfile.individuals)[0].title, None)
def testIdAssismentIsRobust(self): gedcomfile = gedcom.parse_string( "0 HEAD\n0 @I1@ INDI\n1 NAME\n2 GIVN Bob\n2 SURN Cox\n\n0 TRLR") element1 = gedcom.Individual() self.assertEqual(element1.id, None) gedcomfile.add_element(element1) self.assertEqual(element1.id, '@I2@')
def testDeath(self): gedcomfile = gedcom.parse_string( "0 HEAD\n0 @I1@ INDI\n1 NAME\n2 GIVN Bob\n2 SURN Cox\n1 DEAT\n2 DATE 1980\n2 PLAC London\n0 TRLR" ) ind = list(gedcomfile.individuals)[0] death = ind.death self.assertEqual(death.place, "London") self.assertEqual(death.date, "1980")
def testFamilies(self): gedcomfile = gedcom.parse_string(GEDCOM_FILE) fam = list(gedcomfile.families)[0] self.assertEqual(len(fam.husbands), 1) husband = fam.husbands[0].as_individual() self.assertEqual(husband.name, ('Robert', 'Cox')) self.assertEqual(husband.id, '@I1@') self.assertEqual(len(fam.wives), 1) wives = fam.wives[0].as_individual() self.assertEqual(wives.name, ('Joann', 'Para')) self.assertEqual(wives.id, '@I2@')
def testSaveFile(self): gedcomfile = gedcom.parse_string(GEDCOM_FILE) outputfile = tempfile.NamedTemporaryFile() outputfilename = outputfile.name gedcomfile.save(outputfile) outputfile.seek(0, 0) self.assertEqual(outputfile.read(), GEDCOM_FILE.encode("utf8")) self.assertRaises(Exception, gedcomfile.save, (outputfilename)) outputfile.close() gedcomfile.save(outputfilename) with open(outputfilename) as output: self.assertEqual(output.read(), GEDCOM_FILE) remove(outputfilename)
def testSaveFile(self): gedcomfile = gedcom.parse_string(GEDCOM_FILE) outputfile = tempfile.NamedTemporaryFile() outputfilename = outputfile.name gedcomfile.save(outputfile) outputfile.seek(0,0) self.assertEqual(outputfile.read(), GEDCOM_FILE.encode("utf8")) self.assertRaises(Exception, gedcomfile.save, (outputfilename)) outputfile.close() gedcomfile.save(outputfilename) with open(outputfilename) as output: self.assertEqual(output.read(), GEDCOM_FILE) remove(outputfilename)
def testCanParse(self): parsed = gedcom.parse_string(GEDCOM_FILE) self.assertTrue(isinstance(parsed, gedcom.GedcomFile)) people = list(parsed.individuals) self.assertTrue(len(people), 3) bob = people[0] self.assertEqual(bob.name, ("Robert", "Cox")) self.assertEqual(bob.aka, [("Bob", "Cox"), ('Rob', 'Cox')]) self.assertEqual(bob.sex, 'M') self.assertEqual(bob.gender, 'M') self.assertTrue(bob.is_male) self.assertFalse(bob.is_female) self.assertEqual(bob.parents, []) self.assertEqual(bob.father, None) self.assertEqual(bob.mother, None) joann = people[1] self.assertEqual(joann.name, ("Joann", "Para")) self.assertEqual(joann.sex, 'F') self.assertEqual(joann.gender, 'F') self.assertFalse(joann.is_male) self.assertTrue(joann.is_female) self.assertEqual(joann.parents, []) bobby_jo = people[2] self.assertEqual(bobby_jo.name, ("Bobby Jo", "Cox")) self.assertEqual(bobby_jo.sex, 'M') self.assertEqual(bobby_jo.gender, 'M') self.assertTrue(bobby_jo.is_male) self.assertFalse(bobby_jo.is_female) self.assertEqual(bobby_jo.parents, [bob, joann]) self.assertEqual(bobby_jo.father, bob) self.assertEqual(bobby_jo.mother, joann) families = list(parsed.families) self.assertEqual(len(families), 1) family = families[0] self.assertEqual(family.__class__, gedcom.Family) self.assertEqual([p.as_individual() for p in family.partners], [bob, joann])
def testCanParse(self): parsed = gedcom.parse_string(GEDCOM_FILE) self.assertTrue(isinstance(parsed, gedcom.GedcomFile)) people = list(parsed.individuals) self.assertTrue(len(people), 3) bob = people[0] self.assertEquals(bob.name, ("Robert", "Cox")) self.assertEquals(bob.aka, [("Bob", "Cox"), ('Rob', 'Cox')]) self.assertEquals(bob.sex, 'M') self.assertEquals(bob.gender, 'M') self.assertTrue(bob.is_male) self.assertFalse(bob.is_female) self.assertEquals(bob.parents, []) self.assertEquals(bob.father, None) self.assertEquals(bob.mother, None) joann = people[1] self.assertEquals(joann.name, ("Joann", "Para")) self.assertEquals(joann.sex, 'F') self.assertEquals(joann.gender, 'F') self.assertFalse(joann.is_male) self.assertTrue(joann.is_female) self.assertEquals(joann.parents, []) bobby_jo = people[2] self.assertEquals(bobby_jo.name, ("Bobby Jo", "Cox")) self.assertEquals(bobby_jo.sex, 'M') self.assertEquals(bobby_jo.gender, 'M') self.assertTrue(bobby_jo.is_male) self.assertFalse(bobby_jo.is_female) self.assertEquals(bobby_jo.parents, [bob, joann]) self.assertEquals(bobby_jo.father, bob) self.assertEquals(bobby_jo.mother, joann) families = list(parsed.families) self.assertEquals(len(families), 1) family = families[0] self.assertEquals(family.__class__, gedcom.Family) self.assertEquals([p.as_individual() for p in family.partners], [bob, joann])
def testNoteConc(self): gedcomfile = gedcom.parse_string("0 HEAD\n0 @I1@ INDI\n1 NAME\n2 GIVN Bob\n2 SURN Cox\n1 NOTE foo\n2 CONC bar\n0 TRLR") self.assertEqual(list(gedcomfile.individuals)[0].note, 'foobar')
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 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))
def testIdAssismentIsRobust(self): gedcomfile = gedcom.parse_string("0 HEAD\n0 @I1@ INDI\n1 NAME\n2 GIVN Bob\n2 SURN Cox\n\n0 TRLR") element1 = gedcom.Individual() self.assertEqual(element1.id, None) gedcomfile.add_element(element1) self.assertEqual(element1.id, '@I2@')
def testSupportNameInGivenAndSurname(self): gedcomfile = gedcom.parse_string("0 HEAD\n0 @I1@ INDI\n1 NAME\n2 GIVN Bob\n2 SURN Cox\n\n0 TRLR") self.assertEqual(gedcomfile['@I1@'].name, ('Bob', 'Cox'))
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))
def testSupportNameInGivenAndSurname(self): gedcomfile = gedcom.parse_string( "0 HEAD\n0 @I1@ INDI\n1 NAME\n2 GIVN Bob\n2 SURN Cox\n\n0 TRLR") self.assertEqual(gedcomfile['@I1@'].name, ('Bob', 'Cox'))
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 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 testLastNameOnly1(self): gedcomfile = gedcom.parse_string("0 HEAD\n0 @I1@ INDI\n1 NAME\n2 SURN Bob\n0 TRLR") self.assertEqual(list(gedcomfile.individuals)[0].name, (None, 'Bob'))
def testTitle(self): gedcomfile = gedcom.parse_string("0 HEAD\n0 @I1@ INDI\n1 NAME\n2 GIVN Bob\n2 SURN Cox\n1 TITL King\n0 TRLR") self.assertEqual(list(gedcomfile.individuals)[0].title, 'King') gedcomfile = gedcom.parse_string("0 HEAD\n0 @I1@ INDI\n1 NAME\n2 GIVN Bob\n2 SURN Cox\n0 TRLR") self.assertEqual(list(gedcomfile.individuals)[0].title, None)
def testNoteError(self): gedcomfile = gedcom.parse_string("0 HEAD\n0 @I1@ INDI\n1 NAME\n2 GIVN Bob\n2 SURN Cox\n1 NOTE foo\n2 TITL bar\n0 TRLR") ind = list(gedcomfile.individuals)[0] self.assertRaises(ValueError, lambda : ind.note)
def testNoteConc(self): gedcomfile = gedcom.parse_string( "0 HEAD\n0 @I1@ INDI\n1 NAME\n2 GIVN Bob\n2 SURN Cox\n1 NOTE foo\n2 CONC bar\n0 TRLR" ) self.assertEqual(list(gedcomfile.individuals)[0].note, 'foobar')
def testNoteError(self): gedcomfile = gedcom.parse_string( "0 HEAD\n0 @I1@ INDI\n1 NAME\n2 GIVN Bob\n2 SURN Cox\n1 NOTE foo\n2 TITL bar\n0 TRLR" ) ind = list(gedcomfile.individuals)[0] self.assertRaises(ValueError, lambda: ind.note)
def testDeath(self): gedcomfile = gedcom.parse_string("0 HEAD\n0 @I1@ INDI\n1 NAME\n2 GIVN Bob\n2 SURN Cox\n1 DEAT\n2 DATE 1980\n2 PLAC London\n0 TRLR") ind = list(gedcomfile.individuals)[0] death = ind.death self.assertEquals(death.place, "London") self.assertEquals(death.date, "1980")
def testFirstNameOnly2(self): gedcomfile = gedcom.parse_string( "0 HEAD\n0 @I1@ INDI\n1 NAME Bob\n0 TRLR") self.assertEqual(list(gedcomfile.individuals)[0].name, ('Bob', None))
def testFirstNameOnly2(self): gedcomfile = gedcom.parse_string("0 HEAD\n0 @I1@ INDI\n1 NAME Bob\n0 TRLR") self.assertEqual(list(gedcomfile.individuals)[0].name, ('Bob', None))
def testLastNameOnly1(self): gedcomfile = gedcom.parse_string( "0 HEAD\n0 @I1@ INDI\n1 NAME\n2 SURN Bob\n0 TRLR") self.assertEqual(list(gedcomfile.individuals)[0].name, (None, 'Bob'))
def testEmptyName(self): gedcomfile = gedcom.parse_string("0 HEAD\n0 @I1@ INDI\n1 NAME \n0 TRLR") self.assertEqual(list(gedcomfile.individuals)[0].name, (None, None))
def testEmptyName(self): gedcomfile = gedcom.parse_string( "0 HEAD\n0 @I1@ INDI\n1 NAME \n0 TRLR") self.assertEqual(list(gedcomfile.individuals)[0].name, (None, None))
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)