127 message = problem.problem_class.message |
127 message = problem.problem_class.message |
128 if callable(message): |
128 if callable(message): |
129 message = message(**problem.args) |
129 message = message(**problem.args) |
130 return message |
130 return message |
131 |
131 |
132 def format_report_html(report, model, test_suite): |
|
133 messages = [] |
|
134 for problem in report['problems']: |
|
135 ldraw_code = model.body[problem.body_index].textual_representation() |
|
136 message = str.format( |
|
137 '<li class="{problem_type}">{model_name}:{line_number}:' |
|
138 '{problem_type}: {message}<br />{ldraw_code}</li>', |
|
139 model_name = model.name, |
|
140 line_number = problem.line_number, |
|
141 problem_type = problem.severity, |
|
142 message = problem_text(problem, test_suite), |
|
143 ldraw_code = ldraw_code, |
|
144 ) |
|
145 messages.append(message) |
|
146 return '\n'.join(messages) |
|
147 |
|
148 def format_report(report, model, test_suite): |
|
149 import colorama |
|
150 colorama.init() |
|
151 messages = [] |
|
152 for problem in report['problems']: |
|
153 if problem.severity == 'hold': |
|
154 text_colour = colorama.Fore.LIGHTRED_EX |
|
155 elif problem.severity == 'warning': |
|
156 text_colour = colorama.Fore.LIGHTBLUE_EX |
|
157 else: |
|
158 text_colour = '' |
|
159 ldraw_code = model.body[problem.body_index].textual_representation() |
|
160 message = str.format( |
|
161 '{text_colour}{model_name}:{line_number}: {problem_type}: {message}' |
|
162 '{colour_reset}\n\t{ldraw_code}', |
|
163 text_colour = text_colour, |
|
164 model_name = model.name, |
|
165 line_number = problem.line_number, |
|
166 problem_type = problem.severity, |
|
167 message = problem_text(problem, test_suite), |
|
168 colour_reset = colorama.Fore.RESET, |
|
169 ldraw_code = ldraw_code, |
|
170 ) |
|
171 messages.append(message) |
|
172 return '\n'.join(messages) |
|
173 |
|
174 def iterate_problems(test_suite): |
132 def iterate_problems(test_suite): |
175 for test_function in test_suite['tests']: |
133 for test_function in test_suite['tests']: |
176 yield from test_function.ldcheck_problem_types.values() |
134 yield from test_function.ldcheck_problem_types.values() |
177 |
135 |
178 def all_problem_types(test_suite): |
136 def all_problem_types(test_suite): |
179 return sorted( |
137 return sorted( |
180 iterate_problems(test_suite), |
138 iterate_problems(test_suite), |
181 key = lambda problem_type: problem_type.name |
139 key = lambda problem_type: problem_type.name |
182 ) |
140 ) |
183 |
141 |
|
142 def all_problem_type_names(test_suite): |
|
143 return set( |
|
144 problem_type.name |
|
145 for problem_type in iterate_problems(test_suite) |
|
146 ) |
184 |
147 |
185 if __name__ == '__main__': |
148 if __name__ == '__main__': |
186 from pprint import pprint |
149 from pprint import pprint |
187 pprint(load_tests()) |
150 pprint(load_tests()) |