-
Notifications
You must be signed in to change notification settings - Fork 1
/
testcases02.py
69 lines (62 loc) · 2.07 KB
/
testcases02.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import io
import sys
import unittest
from datetime import datetime
from gedcom_parser import analyse_gedcom
class TestBirthBeforeDeath(unittest.TestCase):
def test_valid_birth_before_death(self):
# Valid case where birth date is before death date
gedcom = """
0 @I1@ INDI
1 NAME John /Doe/
1 BIRT
2 DATE 01 JAN 1900
1 DEAT
2 DATE 01 JAN 1980
"""
expected_output = "All individuals have a valid birth date before their death date.\n"
self.assertEqual(run_test_with_input(gedcom), expected_output)
def test_invalid_birth_after_death(self):
# Invalid case where birth date is after death date
gedcom = """
0 @I1@ INDI
1 NAME John /Doe/
1 BIRT
2 DATE 01 JAN 1980
1 DEAT
2 DATE 01 JAN 1900
"""
expected_output = "Error: Individual @I1@ has an invalid birth date after their death date.\n"
self.assertEqual(run_test_with_input(gedcom), expected_output)
def test_missing_birth_or_death_date(self):
# Invalid case where birth date or death date is missing
gedcom = """
0 @I1@ INDI
1 NAME John /Doe/
1 BIRT
2 DATE 01 JAN 1900
"""
expected_output = "Error: Individual @I1@ is missing a death date.\n"
self.assertEqual(run_test_with_input(gedcom), expected_output)
def test_valid_birth_missing_death_date(self):
# Valid case where death date is missing
gedcom = """
0 @I1@ INDI
1 NAME John /Doe/
1 BIRT
2 DATE 01 JAN 1900
"""
expected_output = "All individuals have a valid birth date before their death date.\n"
self.assertEqual(run_test_with_input(gedcom), expected_output)
def run_test_with_input(gedcom):
saved_stdout = sys.stdout
try:
out = io.StringIO()
sys.stdout = out
analyse_gedcom(io.StringIO(gedcom))
output = out.getvalue()
finally:
sys.stdout = saved_stdout
return output
if __name__ == '__main__':
unittest.main()