chore: merge origin/combined-feat into add-source-parsing

Co-authored-by: jaredhowland <1877384+jaredhowland@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]andjaredhowland authored and GitHub committed 2026-04-18 04:00:50 +00:00
commit 676b4014ca
5 files changed
+590 -206

No files matched your search

+1
View File
@@ -41,6 +41,7 @@ def sample_gedcom_content():
1 NAME John /Doe/
2 GIVN John
2 SURN Doe
1 _FSFTID G123-ABC
1 SEX M
1 BIRT
2 DATE 1 JAN 1950
+267 -41
View File
@@ -17,6 +17,7 @@ from gedcom_parser import GedcomParser
from individual import Individual
class TestIndividualBasicInfo:
"""Tests for basic individual information extraction."""
@@ -80,6 +81,15 @@ class TestIndividualBasicInfo:
"""Test gender extraction."""
assert john_doe.get_gender() == 'M'
def test_get_fs_id(self, john_doe, sample_gedcom_file):
"""Test FamilySearch Tree ID extraction from _FSFTID tag."""
assert john_doe.get_fs_id() == 'G123-ABC'
parser = GedcomParser(sample_gedcom_file)
individuals = parser.get_individuals()
jane = [ind for ind in individuals if 'Jane' in str(ind.get_name())]
jane_doe = Individual(jane[0], parser.parser)
assert jane_doe.get_fs_id() == ''
def test_get_gender_default_unknown(self, sample_gedcom_file):
"""Test that missing gender defaults to 'U'."""
gedcom_content = """0 HEAD
@@ -101,6 +111,7 @@ class TestIndividualBasicInfo:
assert person.get_gender() == 'U'
class TestBirthAndDeath:
"""Tests for birth and death information extraction."""
@@ -109,22 +120,22 @@ class TestBirthAndDeath:
"""Get the John Doe individual from sample GEDCOM."""
parser = GedcomParser(sample_gedcom_file)
individuals = parser.get_individuals()
john = [ind for ind in individuals if 'John' in str(ind.get_name())]
john = [ind for ind in individuals if "John" in str(ind.get_name())]
return Individual(john[0], parser.parser)
def test_get_birth_info(self, john_doe):
"""Test birth information extraction."""
birth = john_doe.get_birth_info()
assert birth['date'] == '1 JAN 1950'
assert birth['place'] == 'New York, USA'
assert birth['year'] == '1950'
assert birth["date"] == "1 JAN 1950"
assert birth["place"] == "New York, USA"
assert birth["year"] == "1950"
def test_get_death_info(self, john_doe):
"""Test death information extraction."""
death = john_doe.get_death_info()
assert death['date'] == '15 JUN 2020'
assert death['place'] == 'Los Angeles, USA'
assert death['year'] == '2020'
assert death["date"] == "15 JUN 2020"
assert death["place"] == "Los Angeles, USA"
assert death["year"] == "2020"
def test_get_birth_info_missing(self, sample_gedcom_file):
"""Test birth info when not present."""
@@ -138,16 +149,17 @@ class TestBirthAndDeath:
0 TRLR
"""
temp_file = sample_gedcom_file.parent / "no_birth.ged"
temp_file.write_text(gedcom_content, encoding='utf-8')
temp_file.write_text(gedcom_content, encoding="utf-8")
parser = GedcomParser(temp_file)
individuals = parser.get_individuals()
person = Individual(individuals[0], parser.parser)
birth = person.get_birth_info()
assert birth['date'] == ''
assert birth['place'] == ''
assert birth['year'] == ''
assert birth["date"] == ""
assert birth["place"] == ""
assert birth["year"] == ""
class TestEvents:
@@ -158,7 +170,7 @@ class TestEvents:
"""Get the John Doe individual from sample GEDCOM."""
parser = GedcomParser(sample_gedcom_file)
individuals = parser.get_individuals()
john = [ind for ind in individuals if 'John' in str(ind.get_name())]
john = [ind for ind in individuals if "John" in str(ind.get_name())]
return Individual(john[0], parser.parser)
def test_get_events(self, john_doe):
@@ -169,11 +181,11 @@ class TestEvents:
assert len(events) >= 3
# Find occupation event
occu_events = [e for e in events if e['type'] == 'OCCU']
occu_events = [e for e in events if e["type"] == "OCCU"]
assert len(occu_events) >= 1
occu = occu_events[0]
assert occu['details'] == 'Engineer'
assert occu['date'] == '1975'
assert occu["details"] == "Engineer"
assert occu["date"] == "1975"
def test_get_events_with_all_types(self, temp_dir):
"""Test extraction of various event types."""
@@ -199,7 +211,7 @@ class TestEvents:
0 TRLR
"""
temp_file = temp_dir / "events.ged"
temp_file.write_text(gedcom_content, encoding='utf-8')
temp_file.write_text(gedcom_content, encoding="utf-8")
parser = GedcomParser(temp_file)
individuals = parser.get_individuals()
@@ -208,12 +220,141 @@ class TestEvents:
events = person.get_events()
event_types = [e['type'] for e in events]
assert 'BIRT' in event_types
assert 'DEAT' in event_types
assert 'OCCU' in event_types
assert 'EDUC' in event_types
assert 'RESI' in event_types
assert 'BURI' in event_types
assert "BIRT" in event_types
assert "DEAT" in event_types
assert "OCCU" in event_types
assert "EDUC" in event_types
assert "RESI" in event_types
assert "BURI" in event_types
resi = next(e for e in events if e["type"] == "RESI")
assert resi['place'] == 'New York'
assert resi['lat'] == ''
assert resi['long'] == ''
assert "EDUC" in event_types
assert "RESI" in event_types
assert "BURI" in event_types
def test_get_events_with_coords(self, temp_dir):
"""Test extraction of place coordinates from MAP -> LATI/LONG under PLAC."""
gedcom_content = """0 HEAD
1 SOUR TestApp
1 GEDC
2 VERS 5.5.1
1 CHAR UTF-8
0 @I1@ INDI
1 NAME Test /Person/
1 RESI
2 PLAC Newplace
3 MAP
4 LATI 40.7128
4 LONG -74.0060
0 TRLR
"""
temp_file = temp_dir / "coords.ged"
temp_file.write_text(gedcom_content, encoding="utf-8")
parser = GedcomParser(temp_file)
individuals = parser.get_individuals()
person = Individual(individuals[0], parser.parser)
events = person.get_events()
resi = next(e for e in events if e["type"] == "RESI")
assert resi["place"] == "Newplace"
assert resi["lat"] == "40.7128"
assert resi["long"] == "-74.0060"
def test_get_events_coords_direct_children(self, temp_dir):
"""Test PLAC with LATI/LONG directly under PLAC (not within MAP)."""
gedcom_content = """0 HEAD
1 SOUR TestApp
1 GEDC
2 VERS 5.5.1
1 CHAR UTF-8
0 @I1@ INDI
1 NAME Test /Person/
1 RESI
2 PLAC Somewhere
3 LATI 12.34
3 LONG 56.78
0 TRLR
"""
temp_file = temp_dir / "coords_direct.ged"
temp_file.write_text(gedcom_content, encoding="utf-8")
parser = GedcomParser(temp_file)
individuals = parser.get_individuals()
person = Individual(individuals[0], parser.parser)
events = person.get_events()
resi = next(e for e in events if e["type"] == "RESI")
assert resi["place"] == "Somewhere"
assert resi["lat"] == "12.34"
assert resi["long"] == "56.78"
def test_get_events_coords_missing_lat(self, temp_dir):
"""Test MAP present with only LONG value; LATI missing."""
gedcom_content = """0 HEAD
1 SOUR TestApp
1 GEDC
2 VERS 5.5.1
1 CHAR UTF-8
0 @I1@ INDI
1 NAME Test /Person/
1 RESI
2 PLAC Coastal
3 MAP
4 LONG -3.1415
0 TRLR
"""
temp_file = temp_dir / "coords_missing_lat.ged"
temp_file.write_text(gedcom_content, encoding="utf-8")
parser = GedcomParser(temp_file)
individuals = parser.get_individuals()
person = Individual(individuals[0], parser.parser)
events = person.get_events()
resi = next(e for e in events if e["type"] == "RESI")
assert resi["place"] == "Coastal"
assert resi["lat"] == ""
assert resi["long"] == "-3.1415"
def test_get_events_coords_nested_structure(self, temp_dir):
"""Test LATI/LONG extraction from nested nodes under PLAC."""
gedcom_content = """0 HEAD
1 SOUR TestApp
1 GEDC
2 VERS 5.5.1
1 CHAR UTF-8
0 @I1@ INDI
1 NAME Test /Person/
1 RESI
2 PLAC Deepplace
3 MAP
4 META
5 LATI 48.8566
5 LONG 2.3522
0 TRLR
"""
temp_file = temp_dir / "coords_nested.ged"
temp_file.write_text(gedcom_content, encoding="utf-8")
parser = GedcomParser(temp_file)
individuals = parser.get_individuals()
person = Individual(individuals[0], parser.parser)
events = person.get_events()
resi = next(e for e in events if e["type"] == "RESI")
assert resi["place"] == "Deepplace"
assert resi["lat"] == "48.8566"
assert resi["long"] == "2.3522"
class TestFamilyRelationships:
@@ -228,57 +369,114 @@ class TestFamilyRelationships:
"""Test parent extraction for a child."""
individuals = parsed_gedcom.get_individuals()
# Alice (I3) should have parents John (I1) and Jane (I2)
alice = [ind for ind in individuals if 'Alice' in str(ind.get_name())]
alice = [ind for ind in individuals if "Alice" in str(ind.get_name())]
alice_obj = Individual(alice[0], parsed_gedcom.parser)
parents = alice_obj.get_parents()
assert len(parents) == 2
parent_names = [p.get_full_name() for p in parents]
assert any('John' in name for name in parent_names)
assert any('Jane' in name for name in parent_names)
assert any("John" in name for name in parent_names)
assert any("Jane" in name for name in parent_names)
def test_get_children(self, parsed_gedcom):
"""Test children extraction for a parent."""
individuals = parsed_gedcom.get_individuals()
# John (I1) should have child Alice (I3)
john = [ind for ind in individuals if 'John' in str(ind.get_name())]
john = [ind for ind in individuals if "John" in str(ind.get_name())]
john_obj = Individual(john[0], parsed_gedcom.parser)
children = john_obj.get_children()
assert len(children) >= 1
child_names = [c.get_full_name() for c in children]
assert any('Alice' in name for name in child_names)
assert any("Alice" in name for name in child_names)
def test_get_partners(self, parsed_gedcom):
"""Test partner/spouse extraction."""
individuals = parsed_gedcom.get_individuals()
# John (I1) should have partner Jane (I2)
john = [ind for ind in individuals if 'John' in str(ind.get_name())]
john = [ind for ind in individuals if "John" in str(ind.get_name())]
john_obj = Individual(john[0], parsed_gedcom.parser)
partners = john_obj.get_partners()
assert len(partners) >= 1
partner_names = [p.get_full_name() for p in partners]
assert any('Jane' in name for name in partner_names)
assert any("Jane" in name for name in partner_names)
def test_get_families(self, parsed_gedcom):
"""Test family data extraction including marriage info."""
individuals = parsed_gedcom.get_individuals()
john = [ind for ind in individuals if 'John' in str(ind.get_name())]
john = [ind for ind in individuals if "John" in str(ind.get_name())]
john_obj = Individual(john[0], parsed_gedcom.parser)
families = john_obj.get_families()
assert len(families) >= 1
family = families[0]
assert family['partner'] is not None
assert 'Jane' in family['partner'].get_full_name()
assert family['marriage_date'] == '20 JUN 1975'
assert family['marriage_place'] == 'New York, USA'
assert len(family['children']) >= 1
assert family["partner"] is not None
assert "Jane" in family["partner"].get_full_name()
assert family["marriage_date"] == "20 JUN 1975"
assert family["marriage_place"] == "New York, USA"
assert len(family["children"]) >= 1
def test_get_families_marriage_coords_not_leaked(self, temp_dir):
"""Ensure marriage coordinates do not leak between multiple families."""
gedcom_content = """0 HEAD
1 SOUR TestApp
1 GEDC
2 VERS 5.5.1
1 CHAR UTF-8
0 @I1@ INDI
1 NAME Parent /One/
1 SEX M
1 FAMS @F1@
1 FAMS @F2@
0 @I2@ INDI
1 NAME Partner /One/
1 SEX F
1 FAMS @F1@
0 @I3@ INDI
1 NAME Partner /Two/
1 SEX F
1 FAMS @F2@
0 @F1@ FAM
1 HUSB @I1@
1 WIFE @I2@
1 MARR
2 DATE 1 JAN 2000
2 PLAC Place One
3 MAP
4 LATI 11.11
4 LONG 22.22
0 @F2@ FAM
1 HUSB @I1@
1 WIFE @I3@
1 MARR
2 DATE 1 JAN 2010
2 PLAC Place Two
0 TRLR
"""
temp_file = temp_dir / "family_coords_leak.ged"
temp_file.write_text(gedcom_content, encoding="utf-8")
parser = GedcomParser(temp_file)
individuals = parser.get_individuals()
parent = [ind for ind in individuals if ind.get_pointer() == "@I1@"][0]
parent_obj = Individual(parent, parser.parser)
families = parent_obj.get_families()
assert len(families) == 2
family_one = [f for f in families if f["marriage_place"] == "Place One"][0]
family_two = [f for f in families if f["marriage_place"] == "Place Two"][0]
assert family_one["marriage_lat"] == "11.11"
assert family_one["marriage_long"] == "22.22"
assert family_two["marriage_lat"] == ""
assert family_two["marriage_long"] == ""
class TestImagesAndMedia:
@@ -299,8 +497,33 @@ class TestImagesAndMedia:
assert image['title'] == 'Photo of John'
assert image['format'] == 'jpeg'
def test_get_images_empty(self, temp_dir):
"""Test image extraction when no images are present."""
def test_get_notes_inline(self, temp_dir):
"""Test inline note extraction."""
gedcom_content = """0 HEAD
1 SOUR TestApp
1 GEDC
2 VERS 5.5.1
1 CHAR UTF-8
0 @I1@ INDI
1 NAME Test /Person/
1 NOTE This is an inline note.
2 CONT It has multiple lines.
0 TRLR
"""
temp_file = temp_dir / "inline_notes.ged"
temp_file.write_text(gedcom_content, encoding='utf-8')
parser = GedcomParser(temp_file)
individuals = parser.get_individuals()
person = Individual(individuals[0], parser.parser)
notes = person.get_notes()
assert len(notes) >= 1
assert 'inline note' in notes[0].lower()
assert 'multiple lines' in notes[0].lower()
def test_get_notes_empty(self, temp_dir):
"""Test note extraction when no notes are present."""
gedcom_content = """0 HEAD
1 SOUR TestApp
1 GEDC
@@ -310,15 +533,16 @@ class TestImagesAndMedia:
1 NAME Test /Person/
0 TRLR
"""
temp_file = temp_dir / "no_images.ged"
temp_file = temp_dir / "no_notes.ged"
temp_file.write_text(gedcom_content, encoding='utf-8')
parser = GedcomParser(temp_file)
individuals = parser.get_individuals()
person = Individual(individuals[0], parser.parser)
images = person.get_images()
assert len(images) == 0
notes = person.get_notes()
assert len(notes) == 0
class TestNotes:
@@ -383,6 +607,7 @@ class TestNotes:
assert len(notes) == 0
class TestStories:
"""Tests for custom story tag extraction."""
@@ -414,7 +639,7 @@ class TestStories:
0 TRLR
"""
temp_file = temp_dir / "no_stories.ged"
temp_file.write_text(gedcom_content, encoding='utf-8')
temp_file.write_text(gedcom_content, encoding="utf-8")
parser = GedcomParser(temp_file)
individuals = parser.get_individuals()
@@ -424,6 +649,7 @@ class TestStories:
assert len(stories) == 0
class TestAttributes:
"""Tests for physical attribute extraction."""
+29
View File
@@ -129,6 +129,7 @@ class TestMetadataFormatting:
# Check for YAML frontmatter metadata
assert 'ID: I1' in content
assert 'FamilySearch ID: G123-ABC' in content
assert 'Name: John Doe' in content
assert 'Sex: M' in content
@@ -236,6 +237,34 @@ class TestEventFormatting:
# Birth should not appear as a separate event
assert 'Birth' not in life_events_section or 'Marriage' in content
def test_coordinates_written(self, generator, temp_dir):
"""Ensure that coordinates extracted from PLAC/MAP are written into notes."""
gedcom_content = """0 HEAD
1 SOUR TestApp
1 GEDC
2 VERS 5.5.1
1 CHAR UTF-8
0 @I1@ INDI
1 NAME Locator /Person/
1 RESI
2 PLAC Mapville
3 MAP
4 LATI 51.5074
4 LONG -0.1278
0 TRLR
"""
temp_file = temp_dir / "coords_note.ged"
temp_file.write_text(gedcom_content, encoding='utf-8')
parser = GedcomParser(temp_file)
individuals = parser.get_individuals()
person = Individual(individuals[0], parser.parser)
file_path = generator.generate_note(person)
content = file_path.read_text()
assert '- **Coordinates**: 51.5074, -0.1278' in content
class TestImageHandling:
"""Tests for image embedding in notes."""