Refactors Individual class for parser access
Simplifies Individual class initialization by directly passing the parser instance instead of the GedcomParser object. This change streamlines the code and avoids unnecessary object attribute access. Also, it ensures name formatting preserves the original capitalization.
This commit is contained in:
5 files changed
+72
-83
No files matched your search
@@ -40,7 +40,7 @@ class TestIndexGeneration:
|
||||
"""Get individuals from sample GEDCOM."""
|
||||
parser = GedcomParser(sample_gedcom_file)
|
||||
elements = parser.get_individuals()
|
||||
return [Individual(elem, parser) for elem in elements]
|
||||
return [Individual(elem, parser.parser) for elem in elements]
|
||||
|
||||
def test_generate_index(self, output_dir, individuals):
|
||||
"""Test basic index generation."""
|
||||
@@ -104,7 +104,7 @@ class TestAlphabeticalSorting:
|
||||
|
||||
parser = GedcomParser(temp_file)
|
||||
elements = parser.get_individuals()
|
||||
return [Individual(elem, parser) for elem in elements]
|
||||
return [Individual(elem, parser.parser) for elem in elements]
|
||||
|
||||
def test_sorting_by_last_name(self, output_dir, mixed_individuals):
|
||||
"""Test that individuals are sorted by last name."""
|
||||
@@ -163,7 +163,7 @@ class TestLetterGrouping:
|
||||
|
||||
parser = GedcomParser(temp_file)
|
||||
elements = parser.get_individuals()
|
||||
return [Individual(elem, parser) for elem in elements]
|
||||
return [Individual(elem, parser.parser) for elem in elements]
|
||||
|
||||
def test_letter_headers(self, output_dir, varied_individuals):
|
||||
"""Test that letter headers are created for each initial."""
|
||||
@@ -210,7 +210,7 @@ class TestLetterGrouping:
|
||||
|
||||
parser = GedcomParser(temp_file)
|
||||
elements = parser.get_individuals()
|
||||
individuals = [Individual(elem, parser) for elem in elements]
|
||||
individuals = [Individual(elem, parser.parser) for elem in elements]
|
||||
|
||||
generator = IndexGenerator(output_dir)
|
||||
index_path = generator.generate_index(individuals)
|
||||
@@ -228,7 +228,7 @@ class TestWikiLinkFormatting:
|
||||
"""Get individuals with birth/death dates."""
|
||||
parser = GedcomParser(sample_gedcom_file)
|
||||
elements = parser.get_individuals()
|
||||
return [Individual(elem, parser) for elem in elements]
|
||||
return [Individual(elem, parser.parser) for elem in elements]
|
||||
|
||||
def test_wiki_links_without_subdirs(self, output_dir, individuals_with_dates):
|
||||
"""Test WikiLink format without subdirectories."""
|
||||
@@ -257,7 +257,7 @@ class TestLifeSpanFormatting:
|
||||
"""Get individuals with birth/death dates."""
|
||||
parser = GedcomParser(sample_gedcom_file)
|
||||
elements = parser.get_individuals()
|
||||
return [Individual(elem, parser) for elem in elements]
|
||||
return [Individual(elem, parser.parser) for elem in elements]
|
||||
|
||||
def test_life_span_with_both_dates(self, output_dir, individuals_with_dates):
|
||||
"""Test life span when both birth and death dates are available."""
|
||||
@@ -286,7 +286,7 @@ class TestLifeSpanFormatting:
|
||||
|
||||
parser = GedcomParser(temp_file)
|
||||
elements = parser.get_individuals()
|
||||
individuals = [Individual(elem, parser) for elem in elements]
|
||||
individuals = [Individual(elem, parser.parser) for elem in elements]
|
||||
|
||||
generator = IndexGenerator(output_dir)
|
||||
index_path = generator.generate_index(individuals)
|
||||
@@ -311,7 +311,7 @@ class TestLifeSpanFormatting:
|
||||
|
||||
parser = GedcomParser(temp_file)
|
||||
elements = parser.get_individuals()
|
||||
individuals = [Individual(elem, parser) for elem in elements]
|
||||
individuals = [Individual(elem, parser.parser) for elem in elements]
|
||||
|
||||
generator = IndexGenerator(output_dir)
|
||||
index_path = generator.generate_index(individuals)
|
||||
@@ -343,7 +343,7 @@ class TestLifeSpanFormatting:
|
||||
|
||||
parser = GedcomParser(temp_file)
|
||||
elements = parser.get_individuals()
|
||||
individuals = [Individual(elem, parser) for elem in elements]
|
||||
individuals = [Individual(elem, parser.parser) for elem in elements]
|
||||
|
||||
generator = IndexGenerator(output_dir)
|
||||
index_path = generator.generate_index(individuals)
|
||||
@@ -361,7 +361,7 @@ class TestIndexStatistics:
|
||||
"""Test that total individual count is displayed."""
|
||||
parser = GedcomParser(sample_gedcom_file)
|
||||
elements = parser.get_individuals()
|
||||
individuals = [Individual(elem, parser) for elem in elements]
|
||||
individuals = [Individual(elem, parser.parser) for elem in elements]
|
||||
|
||||
generator = IndexGenerator(output_dir)
|
||||
index_path = generator.generate_index(individuals)
|
||||
|
||||
+21
-21
@@ -26,7 +26,7 @@ class TestIndividualBasicInfo:
|
||||
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)
|
||||
return Individual(john[0], parser.parser)
|
||||
|
||||
def test_get_id(self, john_doe):
|
||||
"""Test ID extraction without @ symbols."""
|
||||
@@ -69,10 +69,10 @@ class TestIndividualBasicInfo:
|
||||
|
||||
parser = GedcomParser(temp_file)
|
||||
individuals = parser.get_individuals()
|
||||
person = Individual(individuals[0], parser)
|
||||
person = Individual(individuals[0], parser.parser)
|
||||
|
||||
filename = person.get_file_name()
|
||||
assert 'Person Noyear' in filename
|
||||
assert 'Person NoYear' in filename # Preserves original GEDCOM capitalization
|
||||
# Should not contain a year
|
||||
assert not any(char.isdigit() for char in filename)
|
||||
|
||||
@@ -96,7 +96,7 @@ class TestIndividualBasicInfo:
|
||||
|
||||
parser = GedcomParser(temp_file)
|
||||
individuals = parser.get_individuals()
|
||||
person = Individual(individuals[0], parser)
|
||||
person = Individual(individuals[0], parser.parser)
|
||||
|
||||
assert person.get_gender() == 'U'
|
||||
|
||||
@@ -110,7 +110,7 @@ class TestBirthAndDeath:
|
||||
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)
|
||||
return Individual(john[0], parser.parser)
|
||||
|
||||
def test_get_birth_info(self, john_doe):
|
||||
"""Test birth information extraction."""
|
||||
@@ -141,7 +141,7 @@ class TestBirthAndDeath:
|
||||
|
||||
parser = GedcomParser(temp_file)
|
||||
individuals = parser.get_individuals()
|
||||
person = Individual(individuals[0], parser)
|
||||
person = Individual(individuals[0], parser.parser)
|
||||
|
||||
birth = person.get_birth_info()
|
||||
assert birth['date'] == ''
|
||||
@@ -158,7 +158,7 @@ class TestEvents:
|
||||
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)
|
||||
return Individual(john[0], parser.parser)
|
||||
|
||||
def test_get_events(self, john_doe):
|
||||
"""Test event extraction."""
|
||||
@@ -202,7 +202,7 @@ class TestEvents:
|
||||
|
||||
parser = GedcomParser(temp_file)
|
||||
individuals = parser.get_individuals()
|
||||
person = Individual(individuals[0], parser)
|
||||
person = Individual(individuals[0], parser.parser)
|
||||
|
||||
events = person.get_events()
|
||||
event_types = [e['type'] for e in events]
|
||||
@@ -228,7 +228,7 @@ class TestFamilyRelationships:
|
||||
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)
|
||||
alice_obj = Individual(alice[0], parsed_gedcom.parser)
|
||||
|
||||
parents = alice_obj.get_parents()
|
||||
assert len(parents) == 2
|
||||
@@ -242,7 +242,7 @@ class TestFamilyRelationships:
|
||||
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)
|
||||
john_obj = Individual(john[0], parsed_gedcom.parser)
|
||||
|
||||
children = john_obj.get_children()
|
||||
assert len(children) >= 1
|
||||
@@ -255,7 +255,7 @@ class TestFamilyRelationships:
|
||||
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)
|
||||
john_obj = Individual(john[0], parsed_gedcom.parser)
|
||||
|
||||
partners = john_obj.get_partners()
|
||||
assert len(partners) >= 1
|
||||
@@ -267,7 +267,7 @@ class TestFamilyRelationships:
|
||||
"""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)
|
||||
john_obj = Individual(john[0], parsed_gedcom.parser)
|
||||
|
||||
families = john_obj.get_families()
|
||||
assert len(families) >= 1
|
||||
@@ -288,7 +288,7 @@ class TestImagesAndMedia:
|
||||
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)
|
||||
john_obj = Individual(john[0], parser.parser)
|
||||
|
||||
images = john_obj.get_images()
|
||||
assert len(images) >= 1
|
||||
@@ -314,7 +314,7 @@ class TestImagesAndMedia:
|
||||
|
||||
parser = GedcomParser(temp_file)
|
||||
individuals = parser.get_individuals()
|
||||
person = Individual(individuals[0], parser)
|
||||
person = Individual(individuals[0], parser.parser)
|
||||
|
||||
images = person.get_images()
|
||||
assert len(images) == 0
|
||||
@@ -328,7 +328,7 @@ class TestNotes:
|
||||
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)
|
||||
john_obj = Individual(john[0], parser.parser)
|
||||
|
||||
notes = john_obj.get_notes()
|
||||
assert len(notes) >= 1
|
||||
@@ -353,7 +353,7 @@ class TestNotes:
|
||||
|
||||
parser = GedcomParser(temp_file)
|
||||
individuals = parser.get_individuals()
|
||||
person = Individual(individuals[0], parser)
|
||||
person = Individual(individuals[0], parser.parser)
|
||||
|
||||
notes = person.get_notes()
|
||||
assert len(notes) >= 1
|
||||
@@ -376,7 +376,7 @@ class TestNotes:
|
||||
|
||||
parser = GedcomParser(temp_file)
|
||||
individuals = parser.get_individuals()
|
||||
person = Individual(individuals[0], parser)
|
||||
person = Individual(individuals[0], parser.parser)
|
||||
|
||||
notes = person.get_notes()
|
||||
assert len(notes) == 0
|
||||
@@ -392,7 +392,7 @@ class TestStories:
|
||||
|
||||
parser = GedcomParser(temp_file)
|
||||
individuals = parser.get_individuals()
|
||||
person = Individual(individuals[0], parser)
|
||||
person = Individual(individuals[0], parser.parser)
|
||||
|
||||
stories = person.get_stories()
|
||||
|
||||
@@ -417,7 +417,7 @@ class TestStories:
|
||||
|
||||
parser = GedcomParser(temp_file)
|
||||
individuals = parser.get_individuals()
|
||||
person = Individual(individuals[0], parser)
|
||||
person = Individual(individuals[0], parser.parser)
|
||||
|
||||
stories = person.get_stories()
|
||||
assert len(stories) == 0
|
||||
@@ -433,7 +433,7 @@ class TestAttributes:
|
||||
|
||||
parser = GedcomParser(temp_file)
|
||||
individuals = parser.get_individuals()
|
||||
person = Individual(individuals[0], parser)
|
||||
person = Individual(individuals[0], parser.parser)
|
||||
|
||||
attrs = person.get_attributes()
|
||||
assert attrs['eyes'] == 'Blue'
|
||||
@@ -456,7 +456,7 @@ class TestAttributes:
|
||||
|
||||
parser = GedcomParser(temp_file)
|
||||
individuals = parser.get_individuals()
|
||||
person = Individual(individuals[0], parser)
|
||||
person = Individual(individuals[0], parser.parser)
|
||||
|
||||
attrs = person.get_attributes()
|
||||
assert len(attrs) == 0
|
||||
@@ -67,7 +67,7 @@ class TestNoteGeneration:
|
||||
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)
|
||||
return Individual(john[0], parser.parser)
|
||||
|
||||
def test_generate_note(self, generator, john_doe):
|
||||
"""Test basic note generation."""
|
||||
@@ -93,7 +93,7 @@ class TestNoteGeneration:
|
||||
"""Test generating notes for all individuals."""
|
||||
parser = GedcomParser(sample_gedcom_file)
|
||||
individual_elements = parser.get_individuals()
|
||||
individuals = [Individual(elem, parser) for elem in individual_elements]
|
||||
individuals = [Individual(elem, parser.parser) for elem in individual_elements]
|
||||
|
||||
paths = generator.generate_all(individuals)
|
||||
|
||||
@@ -116,7 +116,7 @@ class TestMetadataFormatting:
|
||||
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)
|
||||
return Individual(john[0], parser.parser)
|
||||
|
||||
def test_visible_metadata(self, generator, john_doe):
|
||||
"""Test visible metadata format [key:: value]."""
|
||||
@@ -162,7 +162,7 @@ class TestWikiLinks:
|
||||
individual_elements = parser.get_individuals()
|
||||
|
||||
# Generate all notes first
|
||||
individuals = [Individual(elem, parser) for elem in individual_elements]
|
||||
individuals = [Individual(elem, parser.parser) for elem in individual_elements]
|
||||
generator.generate_all(individuals)
|
||||
|
||||
# Check John's note for WikiLinks to Jane and Alice
|
||||
@@ -178,7 +178,7 @@ class TestWikiLinks:
|
||||
"""Test WikiLinks to parents."""
|
||||
parser = GedcomParser(sample_gedcom_file)
|
||||
individual_elements = parser.get_individuals()
|
||||
individuals = [Individual(elem, parser) for elem in individual_elements]
|
||||
individuals = [Individual(elem, parser.parser) for elem in individual_elements]
|
||||
|
||||
generator.generate_all(individuals)
|
||||
|
||||
@@ -206,7 +206,7 @@ class TestEventFormatting:
|
||||
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)
|
||||
john_obj = Individual(john[0], parser.parser)
|
||||
|
||||
file_path = generator.generate_note(john_obj)
|
||||
content = file_path.read_text()
|
||||
@@ -221,7 +221,7 @@ class TestEventFormatting:
|
||||
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)
|
||||
john_obj = Individual(john[0], parser.parser)
|
||||
|
||||
file_path = generator.generate_note(john_obj)
|
||||
content = file_path.read_text()
|
||||
@@ -246,7 +246,7 @@ class TestImageHandling:
|
||||
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)
|
||||
john_obj = Individual(john[0], parser.parser)
|
||||
|
||||
file_path = generator.generate_note(john_obj)
|
||||
content = file_path.read_text()
|
||||
@@ -262,7 +262,7 @@ class TestImageHandling:
|
||||
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)
|
||||
john_obj = Individual(john[0], parser.parser)
|
||||
|
||||
file_path = generator.generate_note(john_obj)
|
||||
content = file_path.read_text()
|
||||
@@ -293,7 +293,7 @@ class TestStoryGeneration:
|
||||
|
||||
parser = GedcomParser(temp_file)
|
||||
individuals = parser.get_individuals()
|
||||
person = Individual(individuals[0], parser)
|
||||
person = Individual(individuals[0], parser.parser)
|
||||
|
||||
# Generate note (should also generate story files if stories are found)
|
||||
generator.generate_note(person)
|
||||
@@ -309,7 +309,7 @@ class TestStoryGeneration:
|
||||
|
||||
parser = GedcomParser(temp_file)
|
||||
individuals = parser.get_individuals()
|
||||
person = Individual(individuals[0], parser)
|
||||
person = Individual(individuals[0], parser.parser)
|
||||
|
||||
file_path = generator.generate_note(person)
|
||||
content = file_path.read_text()
|
||||
@@ -326,7 +326,7 @@ class TestStoryGeneration:
|
||||
|
||||
parser = GedcomParser(temp_file)
|
||||
individuals = parser.get_individuals()
|
||||
person = Individual(individuals[0], parser)
|
||||
person = Individual(individuals[0], parser.parser)
|
||||
|
||||
# Generate twice
|
||||
generator.generate_note(person)
|
||||
@@ -358,7 +358,7 @@ class TestFamilyFormatting:
|
||||
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)
|
||||
john_obj = Individual(john[0], parser.parser)
|
||||
|
||||
file_path = generator.generate_note(john_obj)
|
||||
content = file_path.read_text()
|
||||
@@ -404,7 +404,7 @@ class TestFamilyFormatting:
|
||||
|
||||
parser = GedcomParser(temp_file)
|
||||
individuals = parser.get_individuals()
|
||||
person = Individual(individuals[0], parser)
|
||||
person = Individual(individuals[0], parser.parser)
|
||||
|
||||
file_path = generator.generate_note(person)
|
||||
content = file_path.read_text()
|
||||
|
||||
Reference in new issue
Block a user