Skip to content

Commit

Permalink
Added US20, get_spouse, get_children functions
Browse files Browse the repository at this point in the history
Prevents aunts and uncles from marrying their nephews and nieces. Also added functions to get the spouse of set of children of a given individual ID
  • Loading branch information
kgensheimer committed Oct 28, 2018
1 parent a29c90c commit e2ef1bb
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 0 deletions.
59 changes: 59 additions & 0 deletions Bad_GEDCOM_test_data.ged
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,46 @@
1 BIRT
2 DATE 19 OCT 1982
1 FAMS @F27@
0 NOTE US20: The following individuals make up a family that had a child married to their uncle
0 @I79@ INDI
1 NAME Grandpa /Pigsty/
1 SEX M
1 BIRT
2 DATE 19 OCT 1920
1 FAMS @F28@
0 @I80@ INDI
1 NAME Grandma /Pigsty/
1 SEX F
1 BIRT
2 DATE 30 OCT 1920
1 FAMS @F28@
0 @I81@ INDI
1 NAME Mother /Pigsty/
1 SEX F
1 BIRT
2 DATE 31 AUG 1947
1 FAMS @F29@
0 @I82@ INDI
1 NAME Father /Pigsty/
1 SEX M
1 BIRT
2 DATE 31 OCT 1947
1 FAMS @F29@
1 FAMC @F28@
0 @I83@ INDI
1 NAME Uncle /Pigsty/
1 SEX M
1 BIRT
2 DATE 5 MAR 1948
1 FAMC @F28@
1 FAMS @F30@
0 @I84@ INDI
1 NAME Niece /Pigsty/
1 SEX F
1 BIRT
2 DATE 5 MAR 1960
1 FAMC @F29@
1 FAMS @F30@
0 NOTE -----------------Start of the Families-------------------
0 @F1@ FAM
1 HUSB @I1@
Expand Down Expand Up @@ -691,3 +731,22 @@
1 WIFE @I78@
1 MARR
2 DATE 6 FEB 2004
0 NOTE US20: the following family has kid married to the uncle
0 @F28@ FAM
1 HUSB @I79@
1 WIFE @I80@
1 MARR
2 DATE 7 AUG 1945
1 CHIL @I82@
1 CHIL @I83@
0 @F29@ FAM
1 HUSB @I81@
1 WIFE @I82@
1 MARR
2 DATE 7 AUG 1967
1 CHIL @I84@
0 @F30@ FAM
1 HUSB @I83@
1 WIFE @I84@
1 MARR
2 DATE 7 AUG 1980
34 changes: 34 additions & 0 deletions GedcomProject.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ def __init__(self, ind_dict, fam_dict, errors, print_errors):
self.too_many_siblings() #US15
self.no_marriage_to_descendants()#US17
self.no_marriage_to_siblings() #US18
self.creepy_aunts_and_uncles() #US20
self.correct_gender_role() #US21
self.unique_names_and_bdays() #US23
self.unique_spouses_in_family() #US24
Expand Down Expand Up @@ -429,6 +430,39 @@ def no_marriage_to_siblings(self):
elif(tempWife in self.family[person.famc].chil and self.individuals[self.family[fam].wife] != person):
self.all_errors +=["US18: {} cannot be married to their sibling {}".format(person.name, self.individuals[self.family[fam].wife].name)]


def get_childrenID(self, indi_ID):
"""returns a list of children IDs of the given individual ID"""
childrenLst = []
#an indivual can remarry and therefore have multiple families, hence the loop
for family in self.individuals[indi_ID].fams:
if len(self.family[family].chil) != 0:
childrenLst += self.family[family].chil
return childrenLst

def get_spouse(self, indi_ID):
"""returns the current spouse of the given individual ID"""
for family in self.individuals[indi_ID].fams:
if self.family[family].div == None:
if self.individuals[indi_ID].sex == "M":
return self.family[family].wife
else:
return self.family[family].husb

def creepy_aunts_and_uncles(self):
"""US20: Ensures that aunts and uncles should not marry their nieces or nephews"""
#go through set of children from each family,
# then go through children of each sibling to make sure they are not married to the other siblings
for fam in self.family.values():
siblingIDs = fam.chil #set of sibling IDs
if len(siblingIDs) != 0: #if there are siblings
for sib in siblingIDs: #string for the sibling ID
for child in self.get_childrenID(sib):
if self.get_spouse(child) in siblingIDs:
self.all_errors += ["US20: {} is married to their aunt or uncle".format(self.individuals[child].name)]



def correct_gender_role(self):
"""US21: Husband in family should be male and wife in family should be female"""
for fam in self.family.values():
Expand Down
6 changes: 6 additions & 0 deletions Unit_Test_Proj.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ def test_no_marriage_to_siblings(self):
for error in list_of_known_errors:
self.assertIn(error, self.all_errors)

def test_creepy_aunts_and_uncles(self):
"""US20: Tests to ensure that aunts and uncles should not marry their nieces or nephews"""
list_of_known_errors = ["US20: Niece /Pigsty/ is married to their aunt or uncle"]
for error in list_of_known_errors:
self.assertIn(error, self.all_errors)

def test_correct_gender_role(self):
"""US21: Tests to ensure husband in family should be male and wife in family should be female"""
list_of_known_errors = ["US21: The husband in the Par family, (Martha /Par/), is a female!",
Expand Down

0 comments on commit e2ef1bb

Please sign in to comment.