fix: cache subject pointer; tidy up tests

Cache the subject pointer in Individual.get_families by calling self.element.get_pointer() once outside the loop to avoid repeated calls and add a clarifying comment. Clean up tests: remove a duplicated TestIndividualBasicInfo fixture/block comment, drop redundant assertions about residence coordinates, and remove an unnecessary return in TestAttributes.
This commit is contained in:
Jared Howland committed 2026-04-16 22:51:45 -06:00
1 parent 2108325252
commit 747175fcef
2 files changed
+2 -27

No files matched your search

+2 -1
View File
@@ -211,9 +211,10 @@ class Individual:
- children: List of Individual objects - children: List of Individual objects
""" """
families = [] families = []
# Cache the subject pointer once; it doesn't change across families.
self_pointer = self.element.get_pointer()
for family in self.gedcom.get_families(self.element): for family in self.gedcom.get_families(self.element):
# Get partner # Get partner
self_pointer = self.element.get_pointer()
partners = [ partners = [
Individual(parent, self.gedcom) Individual(parent, self.gedcom)
for parent in self.gedcom.get_family_members(family, "PARENTS") for parent in self.gedcom.get_family_members(family, "PARENTS")
-26
View File
@@ -17,26 +17,6 @@ from gedcom_parser import GedcomParser
from individual import Individual from individual import Individual
class TestIndividualBasicInfo:
"""Tests for basic individual 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()
"""
Tests for the Individual data model.
This module tests individual person data extraction including:
- Names and IDs
- Birth and death information
- Events and attributes
- Family relationships
- Images and notes
- Custom story tags
"""
class TestIndividualBasicInfo: class TestIndividualBasicInfo:
"""Tests for basic individual information extraction.""" """Tests for basic individual information extraction."""
@@ -350,10 +330,6 @@ class TestEvents:
events = person.get_events() events = person.get_events()
event_types = [e['type'] for e in events] event_types = [e['type'] for e in events]
assert resi['place'] == 'Deepplace'
assert resi['lat'] == '48.8566'
assert resi['long'] == '2.3522'
class TestFamilyRelationships: class TestFamilyRelationships:
"""Tests for family relationship extraction.""" """Tests for family relationship extraction."""
@@ -601,8 +577,6 @@ class TestAttributes:
attrs = person.get_attributes() attrs = person.get_attributes()
assert len(attrs) == 0 assert len(attrs) == 0
return Individual(john[0], parser.parser)
def test_get_id(self, john_doe): def test_get_id(self, john_doe):
"""Test ID extraction without @ symbols.""" """Test ID extraction without @ symbols."""
id_value = john_doe.get_id() id_value = john_doe.get_id()