def test_US31_living_single(self): """ Tests US31. Ensures that List living singles are printed to the user. """ # single(age<30) is died g = GED_Repo([ os.path.join(os.getcwd(), "test_directory", "US31", "US31_died_less30_single.ged") ]) self.assertEqual(g.US31_living_single(), 'No unmarried individuals over 30.') # single(age<30) is live g = GED_Repo([ os.path.join(os.getcwd(), "test_directory", "US31", "US31_liv_less30_single.ged") ]) self.assertEqual(g.US31_living_single(), 'No unmarried individuals over 30.') # single(age>30) is live g = GED_Repo([ os.path.join(os.getcwd(), "test_directory", "US31", "US31_liv_over30_single.ged") ]) pt = PrettyTable() pt.field_names = [ 'Unmarried Individual ID', 'Unmarried Individual Name' ] pt.add_row(['@I1-US31-A@', 'Libo /Tim_us31/']) pt.sortby = 'Unmarried Individual ID' self.assertEqual(pt._rows, g.US31_living_single()._rows) pass
def test_US16_male_last_names(self): """ Tests US16. Ensures that all male family members have the same last name. """ self.maxDiff == None g = GED_Repo([ os.path.join(os.getcwd(), "test_directory", "US16", "US16_Males_Same_Last_Names.ged") ]) capturedOutput = io.StringIO() sys.stdout = capturedOutput g.US16_male_last_names() sys.stdout = sys.__stdout__ output_str1 = "" self.assertEqual(capturedOutput.getvalue(), output_str1) g = GED_Repo([ os.path.join(os.getcwd(), "test_directory", "US16", "US16_Males_Different_Last_Names.ged") ]) capturedOutput = io.StringIO() sys.stdout = capturedOutput g.US16_male_last_names() sys.stdout = sys.__stdout__ output_str1 = "US16: Male child: Child /DifferentLastnameUS16-1/ with ID: @I1@-US16-B@ on GEDCOM line: 3 has a differet last name than the family last name: LastnameUS16-1.\n" self.assertEqual(capturedOutput.getvalue(), output_str1)
def test_US37_survivors(self): """ Tests US37. Ensures that a list of multiple births is printed. """ # no deaths g = GED_Repo([ os.path.join(os.getcwd(), "test_directory", "US37", "US37_none.ged") ]) self.assertEqual(g.user_story_37(), 'No individuals have died in the past 30 days.') # triplets g = GED_Repo([ os.path.join(os.getcwd(), "test_directory", "US37", "US37_dead.ged") ]) pt = PrettyTable() pt.field_names = ['Family ID', 'Individual ID', 'Individual Name'] pt.add_row(['@F1-US37-B@', '@I2-US37-B@', 'Mother /US37-B/']) pt.add_row(['@F2-US37-B@', '@I3-US37-B@', 'Sibling1 /US37-B/']) pt.add_row(['@F1-US37-B@', '@I4-US37-B@', 'Sibling2 /US37-B/']) pt.add_row(['@F1-US37-B@', '@I5-US37-B@', 'Sibling3 /US37-B/']) pt.add_row(['@F2-US37-B@', '@I7-US37-B@', 'Baby /US37-B/']) pt.sortby = 'Family ID' self.assertEqual(sorted(pt._rows), sorted(g.user_story_37()._rows)) pass
def test_US32_multiple_births(self): """ Tests US32. Ensures that a list of multiple births is printed. """ # no multiple births g = GED_Repo([ os.path.join(os.getcwd(), "test_directory", "US32", "US32_none.ged") ]) self.assertEqual(g.user_story_32(), 'No instances of multiple births.') # triplets g = GED_Repo([ os.path.join(os.getcwd(), "test_directory", "US32", "US32_triplets.ged") ]) pt = PrettyTable() pt.field_names = [ 'Family ID', 'Individual ID', 'Individual Name', 'Individual Birthday' ] pt.add_row([ '@F1-US32-B@', '@I3-US32-B@', 'Sibling1 /US32-B/', datetime(2020, 2, 1, 0, 0).strftime("%m/%d/%Y") ]) pt.add_row([ '@F1-US32-B@', '@I4-US32-B@', 'Sibling2 /US32-B/', datetime(2020, 2, 1, 0, 0).strftime("%m/%d/%Y") ]) pt.add_row([ '@F1-US32-B@', '@I5-US32-B@', 'Sibling3 /US32-B/', datetime(2020, 2, 1, 0, 0).strftime("%m/%d/%Y") ]) pt.sortby = 'Family ID' self.assertEqual(sorted(pt._rows), sorted(g.user_story_32()._rows)) pass
def test_US38_upcoming_birthdays(self): """ Tests US38. Ensures that upcoming birthdays are printed to the user. """ # upcoming birthday g = GED_Repo([ os.path.join(os.getcwd(), "test_directory", "US38", "US38_Upcoming_Birthdays.ged") ]) populated_pt = PrettyTable() populated_pt.field_names = ["Name", "Birthday"] populated_pt.add_row(['Child /LastnameUS38-1/', '04/18/2000']) self.assertEqual( GED_Repo.US38_print_upcoming_birthdays( self, [['Child /LastnameUS38-1/', '04/18/2000']]), [['Child /LastnameUS38-1/', '04/18/2000']]) # empty pretty table for the last two tests empty_pt = PrettyTable() empty_pt.field_names = ["Name", "Birthday"] # no upcoming birthday g = GED_Repo([ os.path.join(os.getcwd(), "test_directory", "US38", "US38_No_Upcoming_Birthdays.ged") ]) self.assertEqual(GED_Repo.US38_print_upcoming_birthdays(self, []), []) # upcoming birthday, but person is dead so it does not count for this program g = GED_Repo([ os.path.join(os.getcwd(), "test_directory", "US38", "US38_Dead_Upcoming_Birthdays.ged") ]) self.assertEqual(GED_Repo.US38_print_upcoming_birthdays(self, []), [])
def test_US29_list_deceased(self): """ Tests US29. """ # deceased g = GED_Repo([os.path.join(os.getcwd(), "test_directory", "US29", "US29_Deceased.ged")]) self.assertEqual(g.US29_list_deceased()._rows, [['@I1@-US29-A@', 'Child /Lastname/']]) # no deceased g = GED_Repo([os.path.join(os.getcwd(), "test_directory", "US29", "US29_No_Deceased.ged")]) self.assertEqual(g.US29_list_deceased(), 'No deceased individuals.')
def main(): """ for running GED reader. """ file_list = [] # this will analyze all files in the input_files directory for folder in [ x for x in os.listdir(os.path.join(os.getcwd(), 'test_directory')) if os.path.isdir(os.path.join(os.getcwd(), 'test_directory', x)) ]: try: # print(f'Reading files in {folder}') file_list = file_list + [ os.path.join(os.getcwd(), 'test_directory', folder, f) for f in os.listdir( os.path.join(os.getcwd(), 'test_directory', folder)) if f.endswith('.ged') ] except ValueError as v: print(v) except FileNotFoundError as f: print(f) try: print(f'Analyzing final cumulative file data.') # print(file_list) g = GED_Repo(file_list) g.check_data() g.print_data() g.print_individuals() g.print_families() except ValueError as v: print(v) except FileNotFoundError as f: print(f)
def test_user_story_2_and_3(self): """ Tests that user_story_2 rejects illegitimate marriages before birthdays. """ # need following cases: # born before married # should pass, unsure how to check this # born after married g = GED_Repo([ os.path.join(os.getcwd(), 'test_directory', 'US02', 'US_02_03.ged') ]) capturedOutput = io.StringIO() sys.stdout = capturedOutput g.user_story_2() sys.stdout = sys.__stdout__ output_str1 = '''US02 - Natalie /Jones/ birthday after marriage date on line 41 US02 - Bob /Johnson/ birthday after marriage date on line 31 US02 - Mary /Miller/ birthday after marriage date on line 110''' c1 = Counter(capturedOutput.getvalue()) c2 = Counter(output_str1) us02_true = all(k in c1 and c1[k] >= c2[k] for k in c2) capturedOutput = io.StringIO() sys.stdout = capturedOutput g.user_story_3() sys.stdout = sys.__stdout__ output_str2 = '''US03 - Ella /Moore/ birthday after death date on line 87 US03 - Diana /Brown/ birthday after death date on line 121''' c3 = Counter(capturedOutput.getvalue()) c4 = Counter(output_str2) us03_true = all(k in c3 and c3[k] >= c4[k] for k in c4) self.assertTrue(us02_true and us03_true)
def test_check_user_story_35(self): """ Tests that user_story_35 list birth day in last 30 days. """ # need following cases: # birthday within 30days g = GED_Repo([os.path.join(os.getcwd(), 'test_directory', 'US35', 'US35_recent_births.ged')]) self.assertEqual(g.user_story_35()._rows, [['@I1-US35-A@', 'Emith /Ohou/', datetime(2020, 3, 30, 0, 0).strftime("%m/%d/%Y")]])
def test_user_story_22(self): """ Tests that functions prints out if there are duplicate IDs. """ # husband gender female and wife gender male (failure) g = GED_Repo([os.path.join(os.getcwd(), 'test_directory', 'US22', 'US22_unique_ids_test.ged')]) capturedOutput = io.StringIO() sys.stdout = capturedOutput for i in g.individuals.values(): g.add_individual(i) for f in g.families.values(): g.add_family(f) sys.stdout = sys.__stdout__ output_str1 = '''US22 - @I1-US22-A@ id has a duplicate in line number 12 US22 - @I3-US22-A@ id has a duplicate in line number 21 US22 - @I4-US22-A@ id has a duplicate in line number 30 US22 - @I5-US22-A@ id has a duplicate in line number 40 US22 - @I6-US22-A@ id has a duplicate in line number 49 US22 - @F1-US22-A@ id has a duplicate in line number 58 US22 - @F2-US22-A@ id has a duplicate in line number 62 US22 - @F3-US22-A@ id has a duplicate in line number 67\n''' self.assertEqual(capturedOutput.getvalue(), output_str1)
def test_user_story_13(self): """ Tests that US13 function rejects bad sibling birthdays. """ self.maxDiff = None # need following cases: # siblings born >8mo apart (good) g = GED_Repo([ os.path.join(os.getcwd(), 'test_directory', 'US13', 'US13_Sibling_Spacing_3.ged') ]) capturedOutput = io.StringIO() sys.stdout = capturedOutput g.user_story_13() sys.stdout = sys.__stdout__ output_str1 = '' self.assertEqual(capturedOutput.getvalue(), output_str1) # siblings born <2 days apart (good) g = GED_Repo([ os.path.join(os.getcwd(), 'test_directory', 'US13', 'US13_Sibling_Spacing_1.ged') ]) capturedOutput = io.StringIO() sys.stdout = capturedOutput g.user_story_13() sys.stdout = sys.__stdout__ output_str2 = '' self.assertEqual(capturedOutput.getvalue(), output_str2) # siblings born between 2days and 8mo apart (bad) g = GED_Repo([ os.path.join(os.getcwd(), 'test_directory', 'US13', 'US13_Sibling_Spacing_2.ged') ]) capturedOutput = io.StringIO() sys.stdout = capturedOutput g.user_story_13() sys.stdout = sys.__stdout__ output_arr3 = { 'US13 - Sibling1 /US13-B/ and Sibling2 /US13-B/ have birthdays that are too close together on lines 18 and 24', 'US13 - Sibling2 /US13-B/ and Sibling3 /US13-B/ have birthdays that are too close together on lines 24 and 30', 'US13 - Sibling1 /US13-B/ and Sibling3 /US13-B/ have birthdays that are too close together on lines 18 and 30' } self.assertEqual( set([x for x in capturedOutput.getvalue().split('\n') if x != '']), output_arr3)
def test_US30_living_married(self): """ Tests US30. Ensures that List living married are printed to the user. """ # Married couple are alive g = GED_Repo([ os.path.join(os.getcwd(), "test_directory", "US30", "US30_Living_couples.ged") ]) pt = PrettyTable() pt.field_names = [ 'Family ID', 'Living Husband Name', ' Living Wife Name' ] pt.add_row(['@F1-US30-B@', 'Jim /Joy_US30/', 'Smith /Jo_A/']) pt.sortby = 'Family ID' self.assertEqual(pt._rows, g.US30_living_married()._rows) # Married couple are not alive g = GED_Repo([ os.path.join(os.getcwd(), "test_directory", "US30", "US30_No_Living_couples.ged") ]) self.assertEqual(g.US30_living_married(), 'No living married couples.')
def test_user_story_15(self): """ Tests that Siblings should not marry one another """ g = GED_Repo([ os.path.join(os.getcwd(), 'test_directory', 'US18', 'US18_siblings_should_not_marry.ged') ]) capturedOutput = io.StringIO() sys.stdout = capturedOutput g.user_story_18() sys.stdout = sys.__stdout__ output_str1 = 'US18 - Martin /Johnson/ and Kristen /Johnson/ are siblings and are married on line 50\n' self.assertEqual(capturedOutput.getvalue(), output_str1)
def test_user_story_21(self): """ Tests that husband gender is male and wife gender female and prints out the cases if not""" g = GED_Repo([ os.path.join(os.getcwd(), 'test_directory', 'US21', 'US21_correct_gender_test.ged') ]) capturedOutput = io.StringIO() sys.stdout = capturedOutput g.user_story_21() sys.stdout = sys.__stdout__ output_str1 = 'US21 - Bella /Smith1/ gender is supposed to be female but is not on line 35\n' self.assertEqual(capturedOutput.getvalue(), output_str1)
def test_US34_Twice_age_diff(self): """ Tests US34. Ensures that List all couples who were married when the older spouse are printed to the user. """ # US34_test_married_diff g = GED_Repo([ os.path.join(os.getcwd(), "test_directory", "US34", "US34_test_married_diff.ged") ]) pt = PrettyTable() pt.field_names = ['Family ID', 'Twice age diff married spouse'] pt.add_row(['@F1_US34_A@', ('Limod /Desimy/', 'Simoy /Camd/')]) pt.sortby = 'Family ID' self.assertEqual(pt._rows, g.US34_Twice_age_diff()._rows)
def test_user_story_14(self): """ Tests that there are no more than 5 multiple births at the same time and prints out the cases if so""" g = GED_Repo([ os.path.join(os.getcwd(), 'test_directory', 'US14', 'US14_multiple_births.ged') ]) capturedOutput = io.StringIO() sys.stdout = capturedOutput g.user_story_14() sys.stdout = sys.__stdout__ output_str1 = '''US14 - @F1-US14-EK@ has more than 5 multiple childrens born in the same time.\n''' self.assertEqual(capturedOutput.getvalue(), output_str1)
def test_user_story_15(self): """ Tests that There should be fewer than 15 siblings in a family """ g = GED_Repo([ os.path.join(os.getcwd(), 'test_directory', 'US15', 'US15_less_than_15_siblings.ged') ]) capturedOutput = io.StringIO() sys.stdout = capturedOutput g.user_story_15() sys.stdout = sys.__stdout__ output_str1 = 'US15 - Bette /Mann5/ and Zepheniah /Mann5/ Family has 21 children on line 260\n' self.assertEqual(capturedOutput.getvalue(), output_str1)
def test_US33_orphans_list(self): """ Tests US33. Ensures that list all orphans. """ # I tested my US11 Test File as I know there are no orphans. g = GED_Repo([ os.path.join(os.getcwd(), "test_directory", "US11", "US11_no_bigamy.ged") ]) self.assertEqual(g.user_story_33(), 'No orphans.') # orphans g = GED_Repo([ os.path.join(os.getcwd(), "test_directory", "US33", "US33_orphans.ged") ]) pt = PrettyTable() pt.field_names = ['ID', 'Name', 'Age'] pt.add_row(['@I1-US33-EK@', 'Blerta /Methasani/', 17]) pt.sortby = 'ID' self.assertEqual(pt._rows, g.user_story_33()._rows) pass
def test_user_story_17(self): """ Tests that Parents should not marry any of their children """ g = GED_Repo([ os.path.join(os.getcwd(), 'test_directory', 'US17', 'US17_parents_should_not_marry_child.ged') ]) capturedOutput = io.StringIO() sys.stdout = capturedOutput g.user_story_17() sys.stdout = sys.__stdout__ output_str1 = 'US17 - Christine /Ponting/ and Brian /Ponting/ are married on line 52\n' self.assertEqual(capturedOutput.getvalue(), output_str1)
def test_user_story_19(self): """ Tests that first cousins should not get married """ g = GED_Repo([ os.path.join(os.getcwd(), 'test_directory', 'US19', 'US19_first_cousins_should_not_marry_each_other.ged') ]) capturedOutput = io.StringIO() sys.stdout = capturedOutput g.user_story_19() sys.stdout = sys.__stdout__ output_str1 = 'US19 - Family @F5-US19-A@ is where first cousins are married\n' self.assertEqual(capturedOutput.getvalue(), output_str1)
def test_user_story_4(self): """ Tests that Marriage should occur before divorce of spouses, and divorce can only occur after marriage and rejects illegitimate data """ g = GED_Repo([ os.path.join(os.getcwd(), 'test_directory', 'US04', 'US04_marriage_before_divorce.ged') ]) capturedOutput = io.StringIO() sys.stdout = capturedOutput g.user_story_4() sys.stdout = sys.__stdout__ output_str1 = 'US04 - Jodie /John/ and Jimmy /John/ married after divorce on line 22\n' self.assertEqual(capturedOutput.getvalue(), output_str1)
def test_check_bday4(self): """ Tests that check_bday rejects illegitimate birthdays by throwing a ValueError. """ # birthday after divorce (within 9mo) g = GED_Repo([ os.path.join(os.getcwd(), 'test_directory', 'US08', 'US08_Birth_After_Divorce_Good.ged') ]) capturedOutput = io.StringIO() sys.stdout = capturedOutput g.check_bday() sys.stdout = sys.__stdout__ output_str1 = '' self.assertEqual(capturedOutput.getvalue(), output_str1)
def test_check_bday3(self): """ Tests that check_bday rejects illegitimate birthdays by throwing a ValueError. """ # birthday during marriage (normal case) g = GED_Repo([ os.path.join(os.getcwd(), 'test_directory', 'US08', 'US08_Birth_After_Marriage.ged') ]) capturedOutput = io.StringIO() sys.stdout = capturedOutput g.check_bday() sys.stdout = sys.__stdout__ output_str1 = '' self.assertEqual(capturedOutput.getvalue(), output_str1)
def test_check_bday2(self): """ Tests that check_bday rejects illegitimate birthdays by throwing a ValueError. """ # birthday after divorce (after 9mo) g = GED_Repo([ os.path.join(os.getcwd(), 'test_directory', 'US08', 'US08_Birth_After_Divorce_Bad.ged') ]) capturedOutput = io.StringIO() sys.stdout = capturedOutput g.check_bday() sys.stdout = sys.__stdout__ output_str1 = 'US08 - John /Smith6/ birthday before marriage on line 21\n' self.assertEqual(capturedOutput.getvalue(), output_str1)
def test_check_user_story_01_4(self): """ Tests that user_story_01 rejects illegitimate divorce day by throwing a ValueError. """ # birthday after divorce (within 9mo) g = GED_Repo([ os.path.join(os.getcwd(), 'test_directory', 'US01', 'US01_divorce_after_today.ged') ]) capturedOutput = io.StringIO() sys.stdout = capturedOutput g.user_story_01() sys.stdout = sys.__stdout__ output_str1 = 'US01 - Jim /Jo3/ divorce after today on line 39\n' self.assertEqual(capturedOutput.getvalue(), output_str1)
def test_check_user_story_01_3(self): """ Tests that user_story_01 rejects illegitimate marriage day by throwing a ValueError. """ # marriage day before today g = GED_Repo([ os.path.join(os.getcwd(), 'test_directory', 'US01', 'US01_marriage_after_today.ged') ]) capturedOutput = io.StringIO() sys.stdout = capturedOutput g.user_story_01() sys.stdout = sys.__stdout__ output_str1 = 'US01 - Jaf /Jo4/ marriage after today on line 37\n' self.assertEqual(capturedOutput.getvalue(), output_str1)
def test_user_story_11(self): """ Tests that husbands and wifes are not married twice at the same time and prints out the cases if so""" g = GED_Repo([ os.path.join(os.getcwd(), 'test_directory', 'US11', 'US11_no_bigamy.ged') ]) capturedOutput = io.StringIO() sys.stdout = capturedOutput g.user_story_11() sys.stdout = sys.__stdout__ output_str1 = '''US11 - Bledar /Hasa/ married twice on the same time on line 53 US11 - Ela /Zili/ married twice on the same time on line 62\n''' self.assertEqual(capturedOutput.getvalue(), output_str1)
def test_set_age2(self): """ Tests that set_age rejects illegitimate ages by throwing a ValueError. """ # person under 150 (success) g = GED_Repo([ os.path.join(os.getcwd(), 'test_directory', 'US07', 'US07_Under_150.ged') ]) capturedOutput = io.StringIO() sys.stdout = capturedOutput g.check_bday() sys.stdout = sys.__stdout__ output_str1 = '' self.assertEqual(capturedOutput.getvalue(), output_str1)
def test_set_age1(self): """ Tests that set_age rejects illegitimate ages by throwing a ValueError. """ # person over 150 (failure) g = GED_Repo([ os.path.join(os.getcwd(), 'test_directory', 'US07', 'US07_Over_150.ged') ]) capturedOutput = io.StringIO() sys.stdout = capturedOutput g.user_story_07() sys.stdout = sys.__stdout__ output_str1 = 'US07 - Redmond /Mann3/ is age 159, which is over 150 years old, on line 24\n' self.assertEqual(capturedOutput.getvalue(), output_str1)
def test_user_story_10(self): """ Tests that check_bday rejects illegitimate Marriage days by throwing a ValueError. """ g = GED_Repo([ os.path.join(os.getcwd(), 'test_directory', 'US10', 'US10_Marriage_Before_14.ged') ]) capturedOutput = io.StringIO() sys.stdout = capturedOutput g.user_story_2() sys.stdout = sys.__stdout__ output_str1 = 'US10 - Jodie /Hooke/ was less than 14 years old at time of marriage on line 30\nUS10 - Captain /Hooke/ was less than 14 years old at time of marriage on line 21\n' self.assertEqual(capturedOutput.getvalue(), output_str1)