feat: extract place lat/long coordinates #7

Open
jaredhowland wants to merge 4 commits from jaredhowland/extract-place-coordinates into main
pull from: jaredhowland/extract-place-coordinates
3 changed files with 112 additions and 572 deletions
Showing only changes of commit 0ba00d0ef7 - Show all commits

No files matched your search

+13 -7
View File
@@ -111,7 +111,7 @@ class Individual:
- 'lat' (str): Latitude string if present, else ''
- 'long' (str): Longitude string if present, else ''
"""
birth_date, birth_place, lat, long = self._get_event_info("BIRT")
birth_date, birth_place, lat, lon = self._get_event_info("BIRT")
# Fallback to helper methods for year if available
year = self.element.get_birth_year()
@@ -122,7 +122,7 @@ class Individual:
"place": birth_place or "",
"year": birth_year,
"lat": lat,
"long": long,
"long": lon,
}
def get_death_info(self) -> Dict[str, str]:
@@ -137,7 +137,7 @@ class Individual:
- lat (str): Latitude if present, else ''
- long (str): Longitude if present, else ''
"""
death_date, death_place, lat, long = self._get_event_info("DEAT")
death_date, death_place, lat, lon = self._get_event_info("DEAT")
year = self._extract_year(death_date)
return {
@@ -145,7 +145,7 @@ class Individual:
"place": death_place or "",
"year": year,
"lat": lat,
"long": long,
"long": lon,
}
def get_gender(self) -> str:
2
@@ -408,12 +408,18 @@ class Individual:
if tag == "LATI" and not lati:
lati = child.get_value() or ""
elif tag == "LONG" and not longi:
longi = child.get_value() or ""
if lati and longi:
return lati, longi
# Don't recurse into LATI leaf nodes
continue
elif tag == "LONG" and not longi:
longi = child.get_value() or ""
if lati and longi:
return lati, longi
# Don't recurse into LONG leaf nodes
continue
# Recurse into other child nodes to find nested LATI/LONG
nested_lati, nested_longi = self._extract_lat_long_from_node(child)
if nested_lati and not lati:
lati = nested_lati
+13 -12
View File
@@ -62,10 +62,12 @@ class MarkdownGenerator:
) -> List[str]:
"""Return non-empty coordinate values from a mapping in latitude/longitude order."""
coords = []
if data.get(lat_key):
coords.append(data.get(lat_key))
if data.get(long_key):
coords.append(data.get(long_key))
lat_val = data.get(lat_key)
long_val = data.get(long_key)
if lat_val:
coords.append(lat_val)
if long_val:
coords.append(long_val)
return coords
def _get_unique_filename(self, base_name: str, individual_id: str) -> str:
@@ -150,7 +152,7 @@ class MarkdownGenerator:
f.write(f"Born: {birth['date']}\n")
if birth["place"]:
f.write(f"Place of birth: {birth['place']}\n")
# Birth coordinates if available
# Birth coordinates should be emitted even if place is empty
birth_coords = self._coordinate_values(birth)
if birth_coords:
f.write(f"Birth coordinates: {', '.join(birth_coords)}\n")
@@ -160,7 +162,7 @@ class MarkdownGenerator:
f.write(f"Passed away: {death['date']}\n")
if death["place"]:
f.write(f"Place of death: {death['place']}\n")
# Death coordinates if available
# Death coordinates should be emitted even if place is empty
death_coords = self._coordinate_values(death)
if death_coords:
f.write(f"Death coordinates: {', '.join(death_coords)}\n")
@@ -217,10 +219,11 @@ class MarkdownGenerator:
if event["date"]:
f.write(f"- **Date**: {event['date']}\n")
# Always compute coordinates, emit regardless of whether place is present
coords = self._coordinate_values(event)
if event["place"]:
f.write(f"- **Place**: {event['place']}\n")
# If coordinates were extracted, write them below the place line
coords = self._coordinate_values(event)
if coords:
f.write(f"- **Coordinates**: {', '.join(coords)}\n")
if event["details"]:
@@ -261,10 +264,8 @@ class MarkdownGenerator:
f.write(f"* Marriage date: {family['marriage_date']}\n")
if family["marriage_place"]:
f.write(f"* Marriage place: {family['marriage_place']}\n")
# Marriage coordinates if available on family record
mcoords = self._coordinate_values(
family, "marriage_lat", "marriage_long"
)
# Marriage coordinates should be emitted regardless of whether place is present
mcoords = self._coordinate_values(family, "marriage_lat", "marriage_long")
if mcoords:
f.write(f"* Marriage coordinates: {', '.join(mcoords)}\n")
+86 -553
View File
@@ -17,6 +17,7 @@ from gedcom_parser import GedcomParser
from individual import Individual
copilot-pull-request-reviewer[bot] commented 2026-04-17 06:22:28 +02:00 (Migrated from github.com)
Review

The john_doe fixture inside the first TestIndividualBasicInfo block contains an unrelated triple-quoted module docstring (lines 28–38) and never returns an Individual, and the class name is then redefined again immediately after. This looks like an accidental paste and makes the test module confusing to maintain; please remove this stray block (or make the fixture return the expected Individual) and keep only one TestIndividualBasicInfo definition.

The `john_doe` fixture inside the first `TestIndividualBasicInfo` block contains an unrelated triple-quoted module docstring (lines 28–38) and never returns an `Individual`, and the class name is then redefined again immediately after. This looks like an accidental paste and makes the test module confusing to maintain; please remove this stray block (or make the fixture return the expected `Individual`) and keep only one `TestIndividualBasicInfo` definition.
coderabbitai[bot] commented 2026-04-17 06:23:32 +02:00 (Migrated from github.com)
Review

⚠️ Potential issue | 🔴 Critical

Blocker: file is structurally broken from a bad merge/rebase.

This file cannot be imported by pytest as-is. Multiple issues:

  1. Lines 20–40: TestIndividualBasicInfo is declared twice. The first declaration's john_doe fixture opens a triple-quoted string at Line 28 (appears to be the module docstring accidentally inlined) and never returns, then a second class TestIndividualBasicInfo starts at Line 40.

  2. Lines 353–355 (inside test_get_events_coords_nested_structure): asserts reference resi, but only event_types is assigned on Line 351. resi is undefined here (Ruff F821). The resi = [e for e in events if e["type"] == "RESI"][0] line is missing.

  3. Line 604: an orphan return Individual(john[0], parser.parser) sits at class-body scope inside TestAttributes, where john is undefined (Ruff F821). It's a leftover from the duplicated john_doe fixture below.

  4. Lines 604–1135: The entire suite (TestIndividualBasicInfo, TestBirthAndDeath, TestEvents, TestFamilyRelationships, TestImagesAndMedia, TestStories) is duplicated verbatim after TestAttributes. In this second copy, TestImagesAndMedia.test_get_images (Line 1037–1047) actually calls get_notes and asserts note content — it's the wrong body pasted in.

Please re-do the diff so only a single, clean copy of each class exists, and re-add the missing resi = [e for e in events if e["type"] == "RESI"][0] assignment in test_get_events_coords_nested_structure (consider using next(...) per the Ruff RUF015 hint).

🔧 Fix for the missing resi assignment (Lines 350–355)
         events = person.get_events()
-        event_types = [e['type'] for e in 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'
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/test_individual.py` around lines 20 - 40, The file is broken by a bad
merge: remove the duplicated test class blocks so each test class (e.g.,
TestIndividualBasicInfo, TestBirthAndDeath, TestEvents, TestFamilyRelationships,
TestImagesAndMedia, TestStories, TestAttributes) appears exactly once; fix the
malformed TestIndividualBasicInfo.john_doe fixture by closing the stray
triple-quoted docstring and ensuring the fixture returns the Individual instance
(return Individual(...)); inside test_get_events_coords_nested_structure add the
missing assignment for the RESI event using a safe pattern (e.g., resi = next(e
for e in events if e["type"] == "RESI")) as suggested by RUF015; remove the
orphan "return Individual(john[0], parser.parser)" sitting at class scope in
TestAttributes and fix any remaining misplaced references to john; and restore
the correct body for TestImagesAndMedia.test_get_images so it calls the image
extraction helper (not get_notes). Ensure imports and fixtures referenced by
these methods remain valid after cleanup.

✅ Addressed in commits 747175f to 0ba00d0

_⚠️ Potential issue_ | _🔴 Critical_ **Blocker: file is structurally broken from a bad merge/rebase.** This file cannot be imported by pytest as-is. Multiple issues: 1. **Lines 20–40**: `TestIndividualBasicInfo` is declared twice. The first declaration's `john_doe` fixture opens a triple-quoted string at Line 28 (appears to be the module docstring accidentally inlined) and never returns, then a second `class TestIndividualBasicInfo` starts at Line 40. 2. **Lines 353–355** (inside `test_get_events_coords_nested_structure`): asserts reference `resi`, but only `event_types` is assigned on Line 351. `resi` is undefined here (Ruff F821). The `resi = [e for e in events if e["type"] == "RESI"][0]` line is missing. 3. **Line 604**: an orphan `return Individual(john[0], parser.parser)` sits at class-body scope inside `TestAttributes`, where `john` is undefined (Ruff F821). It's a leftover from the duplicated `john_doe` fixture below. 4. **Lines 604–1135**: The entire suite (`TestIndividualBasicInfo`, `TestBirthAndDeath`, `TestEvents`, `TestFamilyRelationships`, `TestImagesAndMedia`, `TestStories`) is duplicated verbatim after `TestAttributes`. In this second copy, `TestImagesAndMedia.test_get_images` (Line 1037–1047) actually calls `get_notes` and asserts note content — it's the wrong body pasted in. Please re-do the diff so only a single, clean copy of each class exists, and re-add the missing `resi = [e for e in events if e["type"] == "RESI"][0]` assignment in `test_get_events_coords_nested_structure` (consider using `next(...)` per the Ruff RUF015 hint). <details> <summary>🔧 Fix for the missing resi assignment (Lines 350–355)</summary> ```diff events = person.get_events() - event_types = [e['type'] for e in 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' ``` </details> <details> <summary>🤖 Prompt for AI Agents</summary> ``` Verify each finding against the current code and only fix it if needed. In `@tests/test_individual.py` around lines 20 - 40, The file is broken by a bad merge: remove the duplicated test class blocks so each test class (e.g., TestIndividualBasicInfo, TestBirthAndDeath, TestEvents, TestFamilyRelationships, TestImagesAndMedia, TestStories, TestAttributes) appears exactly once; fix the malformed TestIndividualBasicInfo.john_doe fixture by closing the stray triple-quoted docstring and ensuring the fixture returns the Individual instance (return Individual(...)); inside test_get_events_coords_nested_structure add the missing assignment for the RESI event using a safe pattern (e.g., resi = next(e for e in events if e["type"] == "RESI")) as suggested by RUF015; remove the orphan "return Individual(john[0], parser.parser)" sitting at class scope in TestAttributes and fix any remaining misplaced references to john; and restore the correct body for TestImagesAndMedia.test_get_images so it calls the image extraction helper (not get_notes). Ensure imports and fixtures referenced by these methods remain valid after cleanup. ``` </details> <!-- fingerprinting:phantom:medusa:nectarine:937c8735-1b8e-4cfd-9639-5f1b93a2103c --> <!-- This is an auto-generated comment by CodeRabbit --> ✅ Addressed in commits 747175f to 0ba00d0
copilot-pull-request-reviewer[bot] commented 2026-04-17 06:36:45 +02:00 (Migrated from github.com)
Review

The file defines TestIndividualBasicInfo twice, and this first john_doe fixture appears to contain an accidentally pasted triple-quoted block and never returns an Individual instance. Please remove the stray block and keep a single TestIndividualBasicInfo definition with a fixture that returns the intended individual, to avoid dead/overwritten test code and confusing fixture behavior.

The file defines `TestIndividualBasicInfo` twice, and this first `john_doe` fixture appears to contain an accidentally pasted triple-quoted block and never returns an `Individual` instance. Please remove the stray block and keep a single `TestIndividualBasicInfo` definition with a fixture that returns the intended individual, to avoid dead/overwritten test code and confusing fixture behavior.
class TestIndividualBasicInfo:
"""Tests for basic individual information extraction."""
@@ -101,554 +102,6 @@ class TestIndividualBasicInfo:
assert person.get_gender() == 'U'
class TestBirthAndDeath:
"""Tests for birth and death information extraction."""
@pytest.fixture
def john_doe(self, sample_gedcom_file):
"""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())]
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'
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'
def test_get_birth_info_missing(self, sample_gedcom_file):
"""Test birth info when not present."""
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/
0 TRLR
"""
temp_file = sample_gedcom_file.parent / "no_birth.ged"
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'] == ''
class TestEvents:
"""Tests for event extraction."""
@pytest.fixture
def john_doe(self, sample_gedcom_file):
"""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())]
return Individual(john[0], parser.parser)
def test_get_events(self, john_doe):
"""Test event extraction."""
events = john_doe.get_events()
# Should include BIRT, DEAT, and OCCU
assert len(events) >= 3
# Find occupation event
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'
def test_get_events_with_all_types(self, temp_dir):
"""Test extraction of various event types."""
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 BIRT
2 DATE 1980
1 DEAT
2 DATE 2050
1 OCCU Teacher
2 DATE 2000
1 EDUC University
2 DATE 1998
1 RESI
2 PLAC New York
1 BURI
2 PLAC Cemetery
0 TRLR
"""
temp_file = temp_dir / "events.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()
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
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 = [e for e in events if e["type"] == "RESI"][0]
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 = [e for e in events if e["type"] == "RESI"][0]
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 = [e for e in events if e["type"] == "RESI"][0]
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()
event_types = [e['type'] for e in events]
class TestFamilyRelationships:
"""Tests for family relationship extraction."""
@pytest.fixture
def parsed_gedcom(self, sample_gedcom_file):
"""Get parsed GEDCOM with family relationships."""
return GedcomParser(sample_gedcom_file)
def test_get_parents(self, parsed_gedcom):
"""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_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)
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_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)
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_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)
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_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
class TestImagesAndMedia:
"""Tests for image and media extraction."""
def test_get_images(self, sample_gedcom_file):
"""Test image extraction."""
parser = GedcomParser(sample_gedcom_file)
individuals = parser.get_individuals()
john = [ind for ind in individuals if 'John' in str(ind.get_name())]
john_obj = Individual(john[0], parser.parser)
images = john_obj.get_images()
assert len(images) >= 1
image = images[0]
assert image['file'] == 'john_photo.jpg'
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."""
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/
0 TRLR
"""
temp_file = temp_dir / "no_images.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
class TestNotes:
"""Tests for notes extraction."""
def test_get_notes_with_reference(self, sample_gedcom_file):
"""Test note extraction via reference."""
parser = GedcomParser(sample_gedcom_file)
individuals = parser.get_individuals()
john = [ind for ind in individuals if 'John' in str(ind.get_name())]
john_obj = Individual(john[0], parser.parser)
notes = john_obj.get_notes()
assert len(notes) >= 1
assert 'test note' in notes[0].lower()
assert 'great engineer' in notes[0].lower()
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
2 VERS 5.5.1
1 CHAR UTF-8
0 @I1@ INDI
1 NAME Test /Person/
0 TRLR
"""
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)
notes = person.get_notes()
assert len(notes) == 0
class TestStories:
"""Tests for custom story tag extraction."""
def test_get_stories(self, temp_dir, sample_gedcom_with_stories):
"""Test story extraction from custom _STO tags."""
temp_file = temp_dir / "stories.ged"
temp_file.write_text(sample_gedcom_with_stories, encoding='utf-8')
parser = GedcomParser(temp_file)
individuals = parser.get_individuals()
person = Individual(individuals[0], parser.parser)
stories = person.get_stories()
# Story extraction is complex and depends on exact GEDCOM structure
# The test data may not match the exact format the code expects
# We just verify the method runs without error
assert isinstance(stories, list)
def test_get_stories_empty(self, temp_dir):
"""Test story extraction when no stories are present."""
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/
0 TRLR
"""
temp_file = temp_dir / "no_stories.ged"
temp_file.write_text(gedcom_content, encoding='utf-8')
parser = GedcomParser(temp_file)
individuals = parser.get_individuals()
person = Individual(individuals[0], parser.parser)
stories = person.get_stories()
assert len(stories) == 0
class TestAttributes:
"""Tests for physical attribute extraction."""
def test_get_attributes(self, temp_dir, sample_gedcom_with_attributes):
"""Test physical attribute extraction."""
temp_file = temp_dir / "attributes.ged"
temp_file.write_text(sample_gedcom_with_attributes, encoding="utf-8")
parser = GedcomParser(temp_file)
individuals = parser.get_individuals()
person = Individual(individuals[0], parser.parser)
attrs = person.get_attributes()
assert attrs["eyes"] == "Blue"
assert attrs["hair"] == "Blonde"
assert attrs["heig"] == "170 cm"
def test_get_attributes_empty(self, temp_dir):
"""Test attribute extraction when no attributes are present."""
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/
0 TRLR
"""
temp_file = temp_dir / "no_attrs.ged"
temp_file.write_text(gedcom_content, encoding="utf-8")
parser = GedcomParser(temp_file)
individuals = parser.get_individuals()
person = Individual(individuals[0], parser.parser)
attrs = person.get_attributes()
assert len(attrs) == 0
def test_get_id(self, john_doe):
"""Test ID extraction without @ symbols."""
id_value = john_doe.get_id()
assert id_value == "I1"
assert "@" not in id_value
def test_get_names(self, john_doe):
"""Test name extraction as tuple."""
first, last = john_doe.get_names()
assert first == "John"
assert last == "Doe"
def test_get_full_name(self, john_doe):
"""Test full name formatting."""
full_name = john_doe.get_full_name()
assert full_name == "John Doe"
def test_get_file_name_with_birth_year(self, john_doe):
"""Test filename generation with birth year."""
filename = john_doe.get_file_name()
assert "Doe John" in filename
assert "1950" in filename
def test_get_file_name_without_birth_year(self, sample_gedcom_file):
"""Test filename generation without birth year."""
# Create a person without birth year
gedcom_content = """0 HEAD
1 SOUR TestApp
1 GEDC
2 VERS 5.5.1
1 CHAR UTF-8
0 @I1@ INDI
1 NAME NoYear /Person/
1 SEX M
0 TRLR
"""
temp_file = sample_gedcom_file.parent / "no_year.ged"
temp_file.write_text(gedcom_content, encoding="utf-8")
parser = GedcomParser(temp_file)
individuals = parser.get_individuals()
person = Individual(individuals[0], parser.parser)
filename = person.get_file_name()
assert "Person NoYear" in filename # Preserves original GEDCOM capitalization
# Should not contain a year
assert not any(char.isdigit() for char in filename)
def test_get_gender(self, john_doe):
"""Test gender extraction."""
assert john_doe.get_gender() == "M"
def test_get_gender_default_unknown(self, sample_gedcom_file):
"""Test that missing gender defaults to 'U'."""
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/
0 TRLR
"""
temp_file = sample_gedcom_file.parent / "no_gender.ged"
temp_file.write_text(gedcom_content, encoding="utf-8")
parser = GedcomParser(temp_file)
individuals = parser.get_individuals()
person = Individual(individuals[0], parser.parser)
assert person.get_gender() == "U"
class TestBirthAndDeath:
"""Tests for birth and death information extraction."""
@@ -699,6 +152,7 @@ class TestBirthAndDeath:
assert birth["year"] == ""
class TestEvents:
"""Tests for event extraction."""
@@ -755,7 +209,7 @@ class TestEvents:
person = Individual(individuals[0], parser.parser)
events = person.get_events()
event_types = [e["type"] for e in events]
event_types = [e['type'] for e in events]
assert "BIRT" in event_types
assert "DEAT" in event_types
@@ -764,6 +218,15 @@ class TestEvents:
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'] == ''
copilot-pull-request-reviewer[bot] commented 2026-04-17 06:22:28 +02:00 (Migrated from github.com)
Review

test_get_events_coords_nested_structure asserts on resi[...] but resi is never defined in this test (only events/event_types are). This will raise a NameError and fail the suite; extract the RESI event (as in the other coordinate tests) before asserting on its place/lat/long values, and drop the unused event_types variable if not needed.

`test_get_events_coords_nested_structure` asserts on `resi[...]` but `resi` is never defined in this test (only `events`/`event_types` are). This will raise a `NameError` and fail the suite; extract the RESI event (as in the other coordinate tests) before asserting on its `place/lat/long` values, and drop the unused `event_types` variable if not needed.
copilot-pull-request-reviewer[bot] commented 2026-04-17 06:36:45 +02:00 (Migrated from github.com)
Review

test_get_events_coords_nested_structure asserts on resi[...], but resi is never assigned in this test (only event_types is created). This will raise NameError if the test is executed. Assign resi the RESI event (as done in the other coordinate tests) or update the assertions accordingly.

        event_types = [e['type'] for e in events]
        resi = next(e for e in events if e['type'] == 'RESI')

        assert 'RESI' in event_types
`test_get_events_coords_nested_structure` asserts on `resi[...]`, but `resi` is never assigned in this test (only `event_types` is created). This will raise `NameError` if the test is executed. Assign `resi` the RESI event (as done in the other coordinate tests) or update the assertions accordingly. ```suggestion event_types = [e['type'] for e in events] resi = next(e for e in events if e['type'] == 'RESI') assert 'RESI' in event_types ```
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
@@ -788,7 +251,7 @@ class TestEvents:
person = Individual(individuals[0], parser.parser)
events = person.get_events()
resi = [e for e in events if e["type"] == "RESI"][0]
resi = next(e for e in events if e["type"] == "RESI")
assert resi["place"] == "Newplace"
assert resi["lat"] == "40.7128"
@@ -817,7 +280,7 @@ class TestEvents:
person = Individual(individuals[0], parser.parser)
events = person.get_events()
resi = [e for e in events if e["type"] == "RESI"][0]
resi = next(e for e in events if e["type"] == "RESI")
assert resi["place"] == "Somewhere"
assert resi["lat"] == "12.34"
@@ -846,7 +309,7 @@ class TestEvents:
person = Individual(individuals[0], parser.parser)
events = person.get_events()
resi = [e for e in events if e["type"] == "RESI"][0]
resi = next(e for e in events if e["type"] == "RESI")
assert resi["place"] == "Coastal"
assert resi["lat"] == ""
@@ -877,13 +340,14 @@ class TestEvents:
person = Individual(individuals[0], parser.parser)
events = person.get_events()
resi = [e for e in events if e["type"] == "RESI"][0]
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:
"""Tests for family relationship extraction."""
@@ -1005,6 +469,7 @@ class TestFamilyRelationships:
assert family_two["marriage_long"] == ""
class TestImagesAndMedia:
"""Tests for image and media extraction."""
@@ -1015,6 +480,72 @@ class TestImagesAndMedia:
john = [ind for ind in individuals if 'John' in str(ind.get_name())]
john_obj = Individual(john[0], parser.parser)
images = john_obj.get_images()
assert len(images) >= 1
image = images[0]
assert image['file'] == 'john_photo.jpg'
assert image['title'] == 'Photo of John'
assert image['format'] == 'jpeg'
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
2 VERS 5.5.1
1 CHAR UTF-8
0 @I1@ INDI
1 NAME Test /Person/
0 TRLR
"""
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)
notes = person.get_notes()
assert len(notes) == 0
class TestNotes:
"""Tests for notes extraction."""
def test_get_notes_with_reference(self, sample_gedcom_file):
"""Test note extraction via reference."""
parser = GedcomParser(sample_gedcom_file)
individuals = parser.get_individuals()
john = [ind for ind in individuals if 'John' in str(ind.get_name())]
john_obj = Individual(john[0], parser.parser)
notes = john_obj.get_notes()
assert len(notes) >= 1
assert 'test note' in notes[0].lower()
3
@@ -1067,6 +598,7 @@ class TestImagesAndMedia:
assert len(notes) == 0
class TestStories:
"""Tests for custom story tag extraction."""
@@ -1108,6 +640,7 @@ class TestStories:
assert len(stories) == 0
class TestAttributes:
"""Tests for physical attribute extraction."""