testsuite.py

changeset 29
db6ca177c6c4
parent 19
9169bad392c4
child 32
75f44d3063da
equal deleted inserted replaced
28:5933250813a3 29:db6ca177c6c4
82 = line_numbers[problem['object']] 82 = line_numbers[problem['object']]
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 problem_text(problem, test_suite):
88 message = test_suite['messages'][problem['name']]
89 if callable(message):
90 message = message(**problem['args'])
91 return message
92
93 def format_report_html(report, model, test_suite):
94 result = []
95 for problem in report:
96 ldraw_code = model.body[problem['body-index']].textual_representation()
97 message = str.format(
98 '<li class="{problem_type}">{model_name}:{line_number}:'
99 '{problem_type}: {message}<br />{ldraw_code}</li>',
100 model_name = model.name,
101 line_number = problem['line-number'],
102 problem_type = problem['type'],
103 message = problem_text(problem, test_suite),
104 ldraw_code = ldraw_code,
105 )
106 result.append((problem['line-number'], message))
107 return '\n'.join(
108 problem[1]
109 for problem in sorted(result)
110 )
111
87 def format_report(report, model, test_suite): 112 def format_report(report, model, test_suite):
88 import colorama 113 import colorama
89 colorama.init() 114 colorama.init()
90 result = [] 115 result = []
91 for problem in report: 116 for problem in report:
92 problem_text = test_suite['messages'][problem['name']]
93 if callable(problem_text):
94 problem_text = problem_text(**problem['args'])
95 if problem['type'] == 'error': 117 if problem['type'] == 'error':
96 text_colour = colorama.Fore.LIGHTRED_EX 118 text_colour = colorama.Fore.LIGHTRED_EX
97 elif problem['type'] == 'warning': 119 elif problem['type'] == 'warning':
98 text_colour = colorama.Fore.LIGHTYELLOW_EX 120 text_colour = colorama.Fore.LIGHTYELLOW_EX
99 else: 121 else:
104 '{colour_reset}\n\t{ldraw_code}', 126 '{colour_reset}\n\t{ldraw_code}',
105 text_colour = text_colour, 127 text_colour = text_colour,
106 model_name = model.name, 128 model_name = model.name,
107 line_number = problem['line-number'], 129 line_number = problem['line-number'],
108 problem_type = problem['type'], 130 problem_type = problem['type'],
109 message = problem_text, 131 message = problem_text(problem, test_suite),
110 colour_reset = colorama.Fore.RESET, 132 colour_reset = colorama.Fore.RESET,
111 ldraw_code = ldraw_code, 133 ldraw_code = ldraw_code,
112 ) 134 )
113 result.append((problem['line-number'], message)) 135 result.append((problem['line-number'], message))
114 return '\n'.join( 136 return '\n'.join(

mercurial