Esempio n. 1
0
    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)
Esempio n. 2
0
 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@')
Esempio n. 3
0
 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")
Esempio n. 4
0
    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@')
Esempio n. 5
0
    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@')
Esempio n. 6
0
    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)
Esempio n. 7
0
 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)
Esempio n. 8
0
    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])
Esempio n. 9
0
    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])
Esempio n. 10
0
 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')
Esempio n. 11
0
 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'))
Esempio n. 12
0
 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))
Esempio n. 13
0
 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@')
Esempio n. 14
0
 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'))
Esempio n. 15
0
 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))
Esempio n. 16
0
 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'))
Esempio n. 17
0
 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)
Esempio n. 18
0
 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'))
Esempio n. 19
0
 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'))
Esempio n. 20
0
    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)
Esempio n. 21
0
 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)
Esempio n. 22
0
 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')
Esempio n. 23
0
 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)
Esempio n. 24
0
 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")
Esempio n. 25
0
 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))
Esempio n. 26
0
 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))
Esempio n. 27
0
 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'))
Esempio n. 28
0
 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))
Esempio n. 29
0
 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))
Esempio n. 30
0
 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)
Esempio n. 31
0
 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)