testsuite.py

changeset 18
672ebc45685a
parent 17
327da5d00360
child 19
9169bad392c4
equal deleted inserted replaced
17:327da5d00360 18:672ebc45685a
83 del problem['object'] 83 del problem['object']
84 report.append(problem) 84 report.append(problem)
85 return report 85 return report
86 86
87 def format_report(report, model, test_suite): 87 def format_report(report, model, test_suite):
88 import colorama
89 colorama.init()
88 result = [] 90 result = []
89 for problem in report: 91 for problem in report:
90 problem_text = test_suite['messages'][problem['name']] 92 problem_text = test_suite['messages'][problem['name']]
91 if callable(problem_text): 93 if callable(problem_text):
92 problem_text = problem_text(**problem['args']) 94 problem_text = problem_text(**problem['args'])
95 if problem['type'] == 'error':
96 text_colour = colorama.Fore.LIGHTRED_EX
97 elif problem['type'] == 'warning':
98 text_colour = colorama.Fore.LIGHTYELLOW_EX
99 else:
100 text_colour = ''
93 message = str.format( 101 message = str.format(
94 'Line {}: {}\n\t{}', 102 '{text_colour}{model_name}:{line_number}: {problem_type}: {message}'
95 problem['line-number'], 103 '{colour_reset}\n\t{trouble_source}',
96 problem_text, 104 text_colour = text_colour,
97 model.body[problem['body-index']].original_code 105 model_name = model.name,
106 line_number = problem['line-number'],
107 problem_type = problem['type'],
108 message = problem_text,
109 colour_reset = colorama.Fore.RESET,
110 trouble_source = model.body[problem['body-index']].original_code,
98 ) 111 )
99 result.append((problem['line-number'], message)) 112 result.append((problem['line-number'], message))
100 return '\n'.join( 113 return '\n'.join(
101 problem[1] 114 problem[1]
102 for problem in sorted(result) 115 for problem in sorted(result)

mercurial