-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathunitTest.py
62 lines (49 loc) · 2.96 KB
/
unitTest.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
import unittest
import parser_gedcom
import gedcom
import datetime
import HTMLTestRunner
parsed_data = gedcom.parse("sample.ged")
fam = parser.for_families(parsed_data)
ind = parser.for_individuals(parsed_data)
#Implemnted test cases for user story 07
class TestMarriageBeforeDeath_US05(unittest.TestCase):
def test_marriageBeforeDeath_US05_marriage_availibility(self):
self.assertIsNotNone(fam[0]['marriage'], "ERROR: Family: US05: Marriage " + str(fam[0]['marriage']) + " Marriage Date cannot be None.")
def test_marriageBeforeDeath_US05_MarriageDateType(self):
self.assertEqual(type(fam[0]['marriage']), datetime.datetime, "ERROR: Family: US07: Marriage date " + str(fam[0]['marriage']) + " Marriage date is of wrong type.")
def test_marriageBeforeDeath_US05_ReturnsFalse(self):
self.assertFalse(parser.marriageBeforeDeath_US05(fam, ind), "ERROR: Family: US05: Returns False Function can't return False.")
def test_marriageBeforeDeath_US05_ageIsString(self):
self.assertNotEquals(type(ind[0]['age']), str, "ERROR: Individual: US07: Age " + str(ind[0]['age']) + " Age can't be float.")
def test_marriageBeforeDeath_US05_ReturnsNone(self):
self.assertIsNone(parser.marriageBeforeDeath_US05(fam, ind), "ERROR: Family: US05: Returns None Function can't return None.")
#Implemnted test cases for user story 07
class TestAgeLessThan150_US7(unittest.TestCase):
def test_ageLessThan150_US7_ageIsNone(self):
self.assertIsNotNone(ind[0]['age'], "ERROR: Individual: US07: Age " + str(ind[0]['age']) + " Age cannot be None.")
def test_ageLessThan150_US7_isInteger(self):
self.assertEqual(type(ind[0]['age']),int, "ERROR: Individual: US07: Age " + str(ind[0]['age']) + "Age is not an Integer.")
def test_ageLessThan150_US7_ageIsNegative(self):
self.assertGreater(ind[0]['age'], 0, "ERROR: Individual: US07: Age " + str(ind[0]['age']) + " Age can't be negative.")
def test_ageLessThan150_US7_ageIsFloat(self):
self.assertNotEquals(type(ind[0]['age']), float, "ERROR: Individual: US07: Age " + str(ind[0]['age']) + " Age can't be float.")
def test_ageLessThan150_US7_ReturnsFalse(self):
self.assertFalse(parser.ageLessThan150_US7(ind), "ERROR: Individual: US07: Returns False, Function can't return False.")
# Reporting
test_classes_to_run = [TestMarriageBeforeDeath_US05, TestAgeLessThan150_US7] # Include test cases here
loader = unittest.TestLoader()
suites_list = []
for test_class in test_classes_to_run:
suite = loader.loadTestsFromTestCase(test_class)
suites_list.append(suite)
big_suite = unittest.TestSuite(suites_list)
runner = unittest.TextTestRunner(verbosity=2).run(big_suite)
outfile = open("Report.html", "w")
runner = HTMLTestRunner.HTMLTestRunner(
stream=outfile,
title='User Stories UnitTest Report',
description='This demonstrates the report output by ssw555BB2017Spring Team'
)
runner.run(big_suite)
outfile.close()