testsuite.py

changeset 29
db6ca177c6c4
parent 19
9169bad392c4
child 32
75f44d3063da
--- a/testsuite.py	Tue Jan 23 14:09:44 2018 +0200
+++ b/testsuite.py	Tue Jan 23 14:09:52 2018 +0200
@@ -84,14 +84,36 @@
             report.append(problem)
     return report
 
+def problem_text(problem, test_suite):
+    message = test_suite['messages'][problem['name']]
+    if callable(message):
+        message = message(**problem['args'])
+    return message
+
+def format_report_html(report, model, test_suite):
+    result = []
+    for problem in report:
+        ldraw_code = model.body[problem['body-index']].textual_representation()
+        message = str.format(
+            '<li class="{problem_type}">{model_name}:{line_number}:'
+            '{problem_type}: {message}<br />{ldraw_code}</li>',
+            model_name = model.name,
+            line_number = problem['line-number'],
+            problem_type = problem['type'],
+            message = problem_text(problem, test_suite),
+            ldraw_code = ldraw_code,
+        )
+        result.append((problem['line-number'], message))
+    return '\n'.join(
+        problem[1]
+        for problem in sorted(result)
+    )
+
 def format_report(report, model, test_suite):
     import colorama
     colorama.init()
     result = []
     for problem in report:
-        problem_text = test_suite['messages'][problem['name']]
-        if callable(problem_text):
-            problem_text = problem_text(**problem['args'])
         if problem['type'] == 'error':
             text_colour = colorama.Fore.LIGHTRED_EX
         elif problem['type'] == 'warning':
@@ -106,7 +128,7 @@
             model_name = model.name,
             line_number = problem['line-number'],
             problem_type = problem['type'],
-            message = problem_text,
+            message = problem_text(problem, test_suite),
             colour_reset = colorama.Fore.RESET,
             ldraw_code = ldraw_code,
         )

mercurial