class US15TestCase(unittest.TestCase): def setUp(self): self.HugeFamily = Family('@hugefam@') for x in range(1, 16): # loops 15 times indi = Individual("@indi%d" % x) self.HugeFamily.apply_value("CHIL", "@indi%d") self.HugeFamily.add_child_ref(indi) self.ReasonableFamily = Family('@okayfam@') for x in range(1, 15): # loops 14 times indi = Individual("@okayindi%d" % x) self.ReasonableFamily.apply_value("CHIL", "@okayindi%d") self.ReasonableFamily.add_child_ref(indi) def test_huge_family(self): """Test a family that is above the limit of reasonableness (15 kids).""" warns = self.HugeFamily._Check_Excessive_Siblings() self.assertTrue(len(warns) == 1) self.assertTrue(warns[0].story == "US15") self.assertTrue('15' in warns[0].message) self.assertTrue('@hugefam@' in warns[0].message) self.assertTrue('large number of children' in warns[0].message) def test_reasonable_family(self): """Test a family that is below the limit of reasonableness (14 kids).""" warns = self.ReasonableFamily._Check_Excessive_Siblings() self.assertTrue(len(warns) == 0)
class US28TestCase(unittest.TestCase): def setUp(self): self.OkayIndi1 = Individual('@okay1@') self.OkayIndi2 = Individual('@okay2@') self.OkayIndi1.apply_value('BIRT', parse_date('1 JUN 1945')) self.OkayIndi2.apply_value('BIRT', parse_date('1 JUN 1945')) self.OkayIndi1.apply_value('NAME', 'Prince William') self.OkayIndi2.apply_value('NAME', 'Princess Kate') self.OkayFam = Family('@okayf@') self.OkayFam.apply_value('CHIL', '@okay1@') self.OkayFam.apply_value('CHIL', '@okay2@') def test_US28_SiblingsByAge_pt(self): '''Test warnings if''' SiblingsAges = US28_SiblingsByAge(self.OkayFam.children_id_list,{'@okay1@' : self.OkayIndi1,'@okay2@': self.OkayIndi2}, {'@okayf@' : self.OkayFam}) self.assertEqual(SiblingsAges['Prince William'], 73) self.assertTrue(SiblingsAges['Princess Kate'] == 73)
class US18TestCase(unittest.TestCase): def setUp(self): self.brother = Individual('@brother@') self.brother.apply_value('FAMS', '@siblingFamily@') self.sister = Individual('@sister@') self.sister.apply_value('FAMS', '@siblingFamily@') self.mother = Individual('@mother@') self.father = Individual('@father@') self.child1 = Individual('@child@') self.childSpouse = Individual('@child1spouse@') self.parentFamily = Family('@parentFamily@') self.parentFamily.add_spouse_ref('HUSB', self.father) self.parentFamily.add_spouse_ref('WIFE', self.mother) self.parentFamily.apply_value('CHIL', '@brother@') self.parentFamily.add_child_ref(self.brother) self.parentFamily.apply_value('CHIL', '@sister@') self.parentFamily.add_child_ref(self.sister) self.siblingFamily = Family('@siblingFamily@') self.siblingFamily.apply_value('HUSB', '@brother@') self.siblingFamily.add_spouse_ref('HUSB', self.brother) self.siblingFamily.apply_value('HUSB', '@sister@') self.siblingFamily.add_spouse_ref('WIFE', self.sister) self.siblingFamily.apply_value('CHIL', '@child@') self.siblingFamily.add_child_ref(self.child1) self.grandkidsFamily = Family('@grandkids@') self.grandkidsFamily.apply_value('HUSB', '@child@') self.grandkidsFamily.add_spouse_ref('HUSB', self.child1) self.grandkidsFamily.apply_value('WIFE', '@child1spouse@') self.grandkidsFamily.add_spouse_ref('WIFE', self.childSpouse) def test_sibling_married(self): """Test a family where siblings are married to each other""" warns = self.parentFamily._Check_Siblings_Married_to_Each_Other() self.assertTrue(len(warns) == 1) self.assertTrue(warns[0].story == "US18") self.assertTrue('is married to a sibling' in warns[0].message) def test_normal_family(self): """Test a family where family kids are married normally""" warns = self.siblingFamily._Check_Siblings_Married_to_Each_Other() self.assertTrue(len(warns) == 0)
class US08TestCase(unittest.TestCase): def shortDescription(self): '''Disable printing docstring on verbose''' return None def setUp(self): self.OkayIndi = Individual('@okay@') self.OkayIndi.apply_value('BIRT', parse_date('1 JAN 2001')) self.BadIndiMarr = Individual('@badmarriage@') self.BadIndiMarr.apply_value('BIRT', parse_date('30 DEC 2000')) self.NoIndiBirth = Individual('@nobirth@') self.BadIndiDiv = Individual('@baddivorce@') self.BadIndiDiv.apply_value('BIRT', parse_date('5 OCT 2001')) self.MarrFam = Family('@marriedf@') self.MarrFam.apply_value('MARR', parse_date('1 JAN 2001')) self.MarrFam.add_child_ref(self.OkayIndi) self.MarrFam.add_child_ref(self.BadIndiMarr) self.MarrFam.add_child_ref(self.NoIndiBirth) self.NoMarrFam = Family('@nomarriagef@') self.NoMarrFam.add_child_ref(self.OkayIndi) self.NoChildBirthFam = Family('@nochildbirthday@') self.NoChildBirthFam.add_child_ref(self.NoIndiBirth) self.NoDivFam = Family('@nodivorcef@') self.NoDivFam.add_child_ref(self.NoIndiBirth) self.DivFam = Family('@divorcedf@') self.DivFam.apply_value('DIV', parse_date('1 JAN 2001')) self.DivFam.add_child_ref(self.BadIndiDiv) def test_birth_before_marr(self): '''Test warnings if date of birth is before date of parents marriage''' warnings = self.MarrFam._Check_Children_Birth_After_Marriage() self.assertEqual(len(warnings), 1) self.assertTrue('@badmarriage@' in warnings[0].message and 'was born before Parents marriage date' in warnings[0].message) def test_no_marr(self): '''Test warnings if no date of marriage''' warnings = self.NoMarrFam._Check_Children_Birth_After_Marriage() self.assertEqual(len(warnings), 0) def test_no_birth(self): '''Test warnings if no date of birth''' warnings = self.NoChildBirthFam._Check_Children_Birth_After_Marriage() self.assertEqual(len(warnings), 0) def test_no_div(self): '''Test warnings if no date of divorce''' warnings = self.NoDivFam._Check_Children_Birth_After_Divorce() self.assertEqual(len(warnings), 0) def test_birth_after_div(self): '''Test warnings if date of birth is nine months after date of parents divorce''' warnings = self.DivFam._Check_Children_Birth_After_Divorce() self.assertEqual(len(warnings), 1) self.assertTrue('@baddivorce@' in warnings[0].message and 'was born nine months after Parents divorce date' in warnings[0].message) def test_full_path(self): '''Integration test for parser->objects->validation''' buff = StringIO('''0 @I1@ INDI 1 NAME CrankyFrank /Coffin/ 1 SEX M 1 BIRT 2 DATE 6 OCT 1986 1 FAMS @F1@ 0 @I2@ INDI 1 NAME SomethingSally /Coffin/ 1 SEX F 1 BIRT 2 DATE 30 DEC 1985 1 FAMS @F1@ 0 @F1@ FAM 1 MARR 2 DATE 1 JAN 1986 1 DIV 2 DATE 2 JAN 1986 1 CHIL @I1@ 1 CHIL @I2@ ''') (ind, fam, unused_warns) = parse_file(buff) warnings = collect_validation_warnings(ind, fam) count_of_us08_errors = 0 for warn in warnings: if warn.story == "US08": count_of_us08_errors += 1 self.assertEqual(count_of_us08_errors, 2)
class US01TestCase(unittest.TestCase): def shortDescription(self): """Disable printing docstring on verbose.""" return None def setUp(self): """Set up a bunch of Individuals and Families with various future date issues (and some that are Okay).""" self.OkayIndi = Individual("@okay@") self.OkayIndi.apply_value("BIRT", parse_date("1 JUN 1945")) self.OkayIndi.apply_value("DEAT", parse_date("6 JAN 1995")) self.BadBirth = Individual("@birth@") self.BadBirth.apply_value("BIRT", parse_date("1 JAN 2525")) self.BadDeath = Individual("@death@") self.BadDeath.apply_value("BIRT", parse_date("1 JUN 1945")) self.BadDeath.apply_value("DEAT", parse_date("1 JAN 4545")) self.OkayFam = Family("@okayf@") self.OkayFam.apply_value("MARR", parse_date("15 SEP 1960")) self.OkayFam.apply_value("DIV", parse_date("15 SEP 1970")) self.BadMarr = Family("@badmarr@") self.BadMarr.apply_value("MARR", parse_date("15 SEP 2960")) self.BadDiv = Family("@baddiv@") self.BadDiv.apply_value("DIV", parse_date("15 SEP 2970")) self.DoubleBadIndi = Individual("@doubleIndi@") self.DoubleBadIndi.apply_value("BIRT", parse_date("1 JUN 3945")) self.DoubleBadIndi.apply_value("DEAT", parse_date("1 JAN 4545")) self.DoubleBadFam = Family("@doubleFam@") self.DoubleBadFam.apply_value("MARR", parse_date("15 SEP 2960")) self.DoubleBadFam.apply_value("DIV", parse_date("15 SEP 2970")) def test_birth(self): """Test warnings for future births.""" warnings = self.BadBirth._Check_Dates_Before_Today() self.assertEqual(len(warnings), 1) self.assertTrue('@birth@' in warnings[0].message and "birth date" in warnings[0].message) def test_death(self): """Test warnings for future deaths.""" warnings = self.BadDeath._Check_Dates_Before_Today() self.assertEqual(len(warnings), 1) self.assertTrue('@death@' in warnings[0].message and "death date" in warnings[0].message) def test_okay_individual(self): """Test no warning case.""" warnings = self.OkayIndi._Check_Dates_Before_Today() self.assertEqual(len(warnings), 0) def test_marriage(self): """Test warnings for future marriages.""" warnings = self.BadMarr._Check_Dates_Before_Today() self.assertEqual(len(warnings), 1) self.assertTrue('@badmarr@' in warnings[0].message and "marriage date" in warnings[0].message) def test_divorce(self): """Test warnings for future divorces.""" warnings = self.BadDiv._Check_Dates_Before_Today() self.assertEqual(len(warnings), 1) self.assertTrue('@baddiv@' in warnings[0].message and "divorce date" in warnings[0].message) def test_double_warnings(self): """Test warnings for multiple issues.""" warnings = self.DoubleBadFam._Check_Dates_Before_Today() self.assertEqual(len(warnings), 2) warnings = self.DoubleBadIndi._Check_Dates_Before_Today() self.assertEqual(len(warnings), 2) def test_okay_family(self): """Test no warning case.""" warnings = self.OkayFam._Check_Dates_Before_Today() self.assertEqual(len(warnings), 0) def test_full_path(self): """Integration test for full parser->objects->validation data path.""" buff = StringIO("""0 @I1@ INDI 1 NAME CrankyFrank /Coffin/ 1 SEX M 1 BIRT 2 DATE 2 JAN 2940 1 FAMS @F1@ 0 @I2@ INDI 1 NAME MarvelousMay /Coffin/ 1 SEX F 1 BIRT 2 DATE 15 MAY 2941 1 FAMS @F1@ 0 @F1@ FAM 1 HUSB @I1@ 1 WIFE @I2@ 1 MARR 2 DATE 15 JUL 2972 1 DIV 2 DATE 15 JUL 2973""") (ind, fam, unused_warns) = parse_file(buff) warnings = collect_validation_warnings(ind, fam) count_of_us01_errors = 0 for warn in warnings: if warn.story == "US01": count_of_us01_errors += 1 self.assertEqual(count_of_us01_errors, 4)
class US05TestCase(unittest.TestCase): def shortDescription(self): '''Disable printing docstring on verbose''' return None def setUp(self): self.OkayIndi = Individual('@okay@') self.OkayFam = Family('@okayf@') self.OkayIndi.apply_value('DEAT', parse_date('6 JAN 1995')) self.OkayFam.apply_value('MARR', parse_date('1 JUN 1975')) self.OkayFam.apply_value('HUSB', '@okay@') self.OkayFam.add_spouse_ref('HUSB', self.OkayIndi) self.BadDeath = Individual('@death@') self.BadFam = Family('@badf@') self.BadDeath.apply_value('DEAT', parse_date('5 JAN 1995')) self.BadFam.apply_value('MARR', parse_date('6 JAN 1995')) self.BadFam.apply_value('HUSB', '@death@') self.BadFam.add_spouse_ref('HUSB', self.BadDeath) self.MissingDeath = Individual('@nodeath@') self.MissingDeathFam = Family('@badfnd@') self.MissingDeathFam.apply_value('MARR', parse_date('6 JAN 1995')) self.MissingDeathFam.apply_value('HUSB', '@nodeath@') self.MissingDeathFam.add_spouse_ref('HUSB', self.MissingDeath) self.MissingMarr = Individual('@nomarr@') self.MissingMarrFam = Family('@badfnm@') self.MissingMarr.apply_value('DEAT', parse_date('6 JAN 1995')) self.MissingMarrFam.apply_value('HUSB', '@nomarr@') self.MissingMarrFam.add_spouse_ref('HUSB', self.MissingMarr) def test_death_before_marr(self): '''Test warnings if date of death is before date of marriage''' warnings = _US05_Death_Before_Marriage( { '@okay@': self.OkayIndi, '@death@': self.BadDeath }, { '@okayf@': self.OkayFam, '@badf@': self.BadFam }) self.assertEqual(len(warnings), 1) self.assertTrue( '@death@' in warnings[0].message and 'death date before marriage date' in warnings[0].message) def test_no_death(self): '''Test warnings if no date of death''' warnings = _US05_Death_Before_Marriage( { '@okay@': self.OkayIndi, '@nodeath@': self.MissingDeath }, { '@okayf@': self.OkayFam, '@badfnd@': self.MissingDeathFam }) self.assertEqual(len(warnings), 0) def test_no_marriage(self): '''Test warnings if no date of marriage''' warnings = _US05_Death_Before_Marriage( { '@okay@': self.OkayIndi, '@nomarr@': self.MissingMarr }, { '@okayf@': self.OkayFam, '@badfnm@': self.MissingMarrFam }) self.assertEqual(len(warnings), 0) def test_okay_individual(self): '''Test warnings if date of birth is after date of death''' warnings = _US05_Death_Before_Marriage({'@okay@': self.OkayIndi}, {'@okayf@': self.OkayFam}) self.assertEqual(len(warnings), 0) def test_full_path(self): '''Integration test for parser->objects->validation''' buff = StringIO('''0 @I1@ INDI 1 NAME CrankyFrank /Coffin/ 1 SEX M 1 BIRT 2 DATE 3 MAR 1986 1 DEAT 2 DATE 3 MAR 1986 1 FAMS @F1@ 0 @I2@ INDI 1 NAME SomethingSally /Coffin/ 1 SEX F 1 BIRT 2 DATE 1 MAR 1986 1 DEAT 2 DATE 1 MAR 1986 1 FAMS @F1@ 0 @F1@ FAM 1 HUSB @I1@ 1 WIFE @I2@ 1 MARR 2 DATE 2 MAR 1986''') (ind, fam, unused_warns) = parse_file(buff) warnings = collect_validation_warnings(ind, fam) count_of_us05_errors = 0 for warn in warnings: if warn.story == "US05": count_of_us05_errors += 1 self.assertEqual(count_of_us05_errors, 1)
class US04TestCase(unittest.TestCase): def shortDescription(self): '''Disable printing docstring on verbose''' return None def setUp(self): self.OkayFam = Family('@okayf@') self.OkayFam.apply_value('MARR', parse_date('1 JUN 1975')) self.OkayFam.apply_value('DIV', parse_date('1 JUN 1975')) self.BadFam = Family('@badf@') self.BadFam.apply_value('MARR', parse_date('6 JAN 1995')) self.BadFam.apply_value('DIV', parse_date('5 JAN 1995')) self.MissingDivFam = Family('@badfnd@') self.MissingDivFam.apply_value('MARR', parse_date('6 JAN 1995')) self.MissingMarrFam = Family('@badfnm@') self.MissingMarrFam.apply_value('DIV', parse_date('6 JAN 1995')) def test_divorce_before_marr(self): '''Test warnings if date of marriage is after date of divorce''' warnings = self.BadFam._Check_Marriage_Before_Divorce() self.assertEqual(len(warnings), 1) self.assertTrue( '@badf@' in warnings[0].message and 'marriage date after divorce date' in warnings[0].message) def test_no_divorce(self): '''Test warnings if no date of divorce''' warnings = self.MissingDivFam._Check_Marriage_Before_Divorce() self.assertEqual(len(warnings), 0) def test_no_marriage(self): '''Test warnings if no date of marriage''' warnings = self.MissingMarrFam._Check_Marriage_Before_Divorce() self.assertEqual(len(warnings), 0) def test_okay_family(self): '''Test warnings if date of marriage is before date of divorce''' warnings = self.OkayFam._Check_Marriage_Before_Divorce() self.assertEqual(len(warnings), 0) def test_full_path(self): '''Integration test for parser->objects->validation''' buff = StringIO('''0 @F1@ FAM 1 MARR 2 DATE 3 MAR 1986 1 DIV 2 DATE 3 MAR 1986 0 @F2@ FAM 1 MARR 2 DATE 3 MAR 1986 1 DIV 2 DATE 2 MAR 1986''') (ind, fam, unused_warns) = parse_file(buff) warnings = collect_validation_warnings(ind, fam) count_of_us04_errors = 0 for warn in warnings: if warn.story == "US04": count_of_us04_errors += 1 self.assertEqual(count_of_us04_errors, 1)