Exemple #1
0
    def test_find_descendants(self):
        lines = [
            '0 @P@ PARENT',
            '1 @P1@ CHILD',
            '1 @P2@ CHILD',
            '2 @P21@ CHILD',
            '2 @P22@ CHILD',
            '1 @P3@ CHILD',
            '1 @P4@ CHILD',
            '2 @P41@ CHILD',
            '3 @P411@ CHILD',
            '2 @P42@ CHILD',
        ]
        buf = io.BytesIO('\n'.join(lines).encode('utf-8'))
        db = api.parse(buf)
        self.assertEqual(1, len(db.root_records))

        root = db.root_records[0]
        self.assertListEqual(root.find_descendants('NOTTHERE'), [])
        self.assertListEqual(
            [record.pointer for record in root.find_descendants('CHILD')],
            [
                '@P1@',
                '@P2@',
                '@P3@',
                '@P4@',
                '@P21@',
                '@P22@',
                '@P41@',
                '@P42@',
                '@P411@',
            ],
        )
Exemple #2
0
 def test_that_multiple_root_records_parse_correctly(self):
     string_data = '\n'.join([
         '0 @I14938282@ INDI',
         '1 NAME Andrew /Bear/',
         '2 GIVN Andrew',
         '2 SURN Bear',
         '1 SEX M',
         '1 BIRT',
         '2 DATE AFT 1773',
         '2 SOUR @S68885317@',
         '1 SOUR @S68885317@',
         '2 PAGE 17',
         '0 @S68885317@ SOUR',
         '1 TITL Three Bears Of Earl Township, Lancaster County, '
         'Pennsylvania, And Other Early Bears',
         '1 AUTH Jane Evans Best',
         '1 PUBL Pennsylvania Mennonite Heritage',
         '1 DATE Oct 1981',
         '1 PLAC Lancaster, Pennsylvania, United States',
         '1 REFN Volume IV, Number 4',
         '1 REPO @R41744368@',
         '0 @R41744368@ REPO',
         '1 NAME Dave Shawley',
         '1 ADDR [email protected]',
     ])
     db = api.parse(io.BytesIO(string_data.encode('utf-8')))
     self.assertEqual(3, len(db.root_records))
     self.assertEqual(21, db.record_count)
Exemple #3
0
 def test_that_single_root_record_parses_correctly(self):
     string_data = '\n'.join([
         '0 HEAD',
         '1 SOUR SyniumFamilyTree',
         '2 NAME MacFamilyTree',
         '2 VERS 8.3.5',
         '1 CHAR UTF-8',
         '1 GEDC',
         '2 VERS 5.5.1',
         '2 FORM LINEAGE-LINKED',
         '1 PLAC',
         '2 FORM Place,County,State,Country',
     ])
     db = api.parse(io.BytesIO(string_data.encode('utf-8')))
     self.assertEqual(10, db.record_count)
     self.assertEqual(1, len(db.root_records))
     self.assertEqual(string_data + '\n', db.root_records[0].as_string())
Exemple #4
0
    def test_that_write_processes_all_records(self):
        lines = [
            '0 @F59501820@ FAM',
            '1 HUSB @I49205438@',
            '1 WIFE @I72999056@',
            '1 CHIL @I17651300@',
            '2 PEDI birth',
            '1 CHIL @I30378916@',
            '2 PEDI birth',
            '1 CHIL @I29261188@',
            '2 PEDI birth',
            '1 CHIL @I30782740@',
            '2 PEDI birth',
            '1 CHIL @I32365563@',
            '2 PEDI birth',
            '1 CHIL @I22387942@',
            '2 PEDI birth',
            '1 CHIL @I33483194@',
            '2 PEDI birth',
            '1 CHIL @I14938282@',
            '2 PEDI birth',
            '1 CHIL @I79238897@',
            '2 PEDI birth',
        ]
        buf = io.BytesIO('\n'.join(lines).encode('utf-8'))

        record_from_line = models.Record.from_line
        as_string = unittest.mock.Mock(side_effect=models.Record.as_string)
        file_object = io.BytesIO()

        def patched_from_line(*args, **kwargs):
            obj = record_from_line(*args, **kwargs)
            obj.as_string = lambda: as_string(obj)
            return obj

        with unittest.mock.patch('gedcom.api.models.Record') as record_cls:
            record_cls.from_line.side_effect = patched_from_line
            db = api.parse(buf)
            db.write(file_object)

        self.assertEqual(record_cls.from_line.call_count, len(lines))
        self.assertEqual(as_string.call_count, len(lines))
        self.assertEqual(buf.getvalue(), '\n'.join(lines).encode('utf-8'))
Exemple #5
0
    def test_that_pointers_are_registered_in_db(self):
        string_data = '\n'.join([
            '0 @I14938282@ INDI',
            '1 NAME Andrew /Bear/',
            '2 GIVN Andrew',
            '2 SURN Bear',
            '1 SOUR @S68885317@',
            '2 PAGE 17',
            '0 @S68885317@ SOUR',
            '1 TITL Three Bears Of Earl Township, Lancaster County, '
            'Pennsylvania, And Other Early Bears',
            '1 REPO @R41744368@',
            '0 @R41744368@ REPO',
            '1 NAME Dave Shawley',
            '1 ADDR [email protected]',
        ])

        db = api.parse(io.BytesIO(string_data.encode('utf-8')))
        self.assertIs(db.find_pointer('@I14938282@'), db.root_records[0])
        self.assertIs(db.find_pointer('@S68885317@'), db.root_records[1])
        self.assertIs(db.find_pointer('@R41744368@'), db.root_records[2])
Exemple #6
0
    def test_find_records(self):
        lines = [
            '0 @P@ PARENT',
            '1 @P1@ CHILD',
            '1 @P2@ CHILD',
            '2 @P21@ CHILD',
            '2 @P22@ CHILD',
            '0 @Q@ PARENT',
            '1 @Q1@ CHILD',
            '1 @Q2@ CHILD',
            '2 @Q21@ CHILD',
            '3 @Q211@ CHILD',
            '2 @Q22@ CHILD',
        ]
        buf = io.BytesIO('\n'.join(lines).encode('utf-8'))
        db = api.parse(buf)

        self.assertListEqual(
            [record.pointer for record in db.find_records('CHILD')],
            [
                '@P1@',
                '@P2@',
                '@P21@',
                '@P22@',
                '@Q1@',
                '@Q2@',
                '@Q21@',
                '@Q22@',
                '@Q211@',
            ],
        )

        self.assertListEqual(
            [record.pointer for record in db.find_records('PARENT')],
            ['@P@', '@Q@'],
        )
Exemple #7
0
 def test_that_empty_file_results_in_empty_database(self):
     db = api.parse(io.BytesIO(b''))
     self.assertEqual(db.record_count, 0)