diff --git a/src/individual.py b/src/individual.py index ca71f44..746a0d1 100644 --- a/src/individual.py +++ b/src/individual.py @@ -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: @@ -408,12 +408,18 @@ class Individual: if tag == "LATI" and not lati: lati = 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 - if lati and longi: - return lati, longi - + # 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 diff --git a/src/markdown_generator.py b/src/markdown_generator.py index fba321d..45cf4f7 100644 --- a/src/markdown_generator.py +++ b/src/markdown_generator.py @@ -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,20 +152,20 @@ 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_coords = self._coordinate_values(birth) - if birth_coords: - f.write(f"Birth coordinates: {', '.join(birth_coords)}\n") + # 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") # Death details if death["date"]: 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_coords = self._coordinate_values(death) - if death_coords: - f.write(f"Death coordinates: {', '.join(death_coords)}\n") + # 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") # Physical attributes attrs = individual.get_attributes() @@ -217,12 +219,13 @@ 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 coords: + f.write(f"- **Coordinates**: {', '.join(coords)}\n") if event["details"]: f.write(f"- **Details**: {event['details']}\n") @@ -261,12 +264,10 @@ 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" - ) - if mcoords: - f.write(f"* Marriage coordinates: {', '.join(mcoords)}\n") + # 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") # Write children if they exist if family["children"]: diff --git a/tests/test_individual.py b/tests/test_individual.py index 992ae52..d6ef5e4 100644 --- a/tests/test_individual.py +++ b/tests/test_individual.py @@ -17,6 +17,7 @@ from gedcom_parser import GedcomParser from individual import Individual + 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'] == '' + + 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() @@ -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."""