示例#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)
示例#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@')
示例#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")
示例#4
0
文件: tests.py 项目: rory/gedcompy
    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@')
示例#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@')
示例#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)
示例#7
0
文件: tests.py 项目: BioGeek/gedcompy
 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)
示例#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])
示例#9
0
文件: tests.py 项目: BioGeek/gedcompy
    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])
示例#10
0
文件: tests.py 项目: BioGeek/gedcompy
 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')
示例#11
0
文件: tests.py 项目: BioGeek/gedcompy
 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'))
示例#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))
示例#13
0
文件: tests.py 项目: BioGeek/gedcompy
 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@')
示例#14
0
文件: tests.py 项目: BioGeek/gedcompy
 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'))
示例#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))
示例#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'))
示例#17
0
文件: tests.py 项目: BioGeek/gedcompy
 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)
示例#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'))
示例#19
0
文件: tests.py 项目: BioGeek/gedcompy
 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'))
示例#20
0
文件: tests.py 项目: BioGeek/gedcompy
    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)
示例#21
0
文件: tests.py 项目: BioGeek/gedcompy
 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)
示例#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')
示例#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)
示例#24
0
文件: tests.py 项目: BioGeek/gedcompy
 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")
示例#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))
示例#26
0
文件: tests.py 项目: BioGeek/gedcompy
 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))
示例#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'))
示例#28
0
文件: tests.py 项目: BioGeek/gedcompy
 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))
示例#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))
示例#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)
示例#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)