unittest.py

changeset 123
0557709c25ec
parent 122
116a81996832
child 126
16dae12ac0f0
equal deleted inserted replaced
122:116a81996832 123:0557709c25ec
89 ) 89 )
90 return { 90 return {
91 'passed': problems == expected_problems, 91 'passed': problems == expected_problems,
92 'unexpected': set.difference(problems, expected_problems), 92 'unexpected': set.difference(problems, expected_problems),
93 'missing': set.difference(expected_problems, problems), 93 'missing': set.difference(expected_problems, problems),
94 'problem_types': problem_types,
94 } 95 }
95 96
96 def format_problem_tuple(problem_tuple): 97 def format_problem_tuple(problem_tuple):
97 return problem_tuple[0] + ':' + str(problem_tuple[1]) 98 return problem_tuple[0] + ':' + str(problem_tuple[1])
98 99
99 def run_unit_test_suite(): 100 def run_unit_test_suite():
100 config = load_config() 101 config = load_config()
101 test_suite = load_tests() 102 test_suite = load_tests()
102 num_tested = 0 103 num_tested = 0
103 num_passed = 0 104 num_passed = 0
105 all_problem_types = all_problem_type_names(test_suite)
106 problem_types_tested = set()
104 print('Running unit test suite.') 107 print('Running unit test suite.')
105 for unit_test_path in unit_test_discovery(): 108 for unit_test_path in unit_test_discovery():
106 try: 109 try:
107 unit_test_report = run_unit_test( 110 unit_test_report = run_unit_test(
108 unit_test_path, 111 unit_test_path,
121 name = unit_test_path.name, 124 name = unit_test_path.name,
122 verdict = ('FAILED', 'PASSED')[unit_test_report['passed']], 125 verdict = ('FAILED', 'PASSED')[unit_test_report['passed']],
123 )) 126 ))
124 num_tested += 1 127 num_tested += 1
125 num_passed += int(unit_test_report['passed']) 128 num_passed += int(unit_test_report['passed'])
129 set.update(problem_types_tested, unit_test_report['problem_types'])
126 if not unit_test_report['passed']: 130 if not unit_test_report['passed']:
127 def format_problem_list(key): 131 def format_problem_list(key):
128 return str.join( 132 return str.join(
129 ' ', 133 ' ',
130 map(format_problem_tuple, unit_test_report[key]) 134 map(format_problem_tuple, unit_test_report[key])
134 print(str.format( 138 print(str.format(
135 '{num_tested} tests run, {num_passed} tests passed.', 139 '{num_tested} tests run, {num_passed} tests passed.',
136 num_tested = num_tested, 140 num_tested = num_tested,
137 num_passed = num_passed, 141 num_passed = num_passed,
138 )) 142 ))
143 untested_problem_types = set.difference(all_problem_types, problem_types_tested)
144 if untested_problem_types:
145 print('The following problem types were not tested:')
146 for problem_type in sorted(untested_problem_types):
147 print('\t' + problem_type)
139 if __name__ == '__main__': 148 if __name__ == '__main__':
140 run_unit_test_suite() 149 run_unit_test_suite()

mercurial