diff -r 02e7e1d73ebb -r 75f44d3063da testsuite.py --- a/testsuite.py Wed Jan 24 23:14:01 2018 +0200 +++ b/testsuite.py Wed Jan 31 14:34:23 2018 +0200 @@ -14,6 +14,9 @@ def error(bad_object, error_name, **args): return report_element(bad_object, 'error', error_name, args) +def notice(bad_object, error_name, **args): + return report_element(bad_object, 'notice', error_name, args) + def test_discovery(): ''' Finds all test modules and yields their names. @@ -67,22 +70,31 @@ warn(str.format('Module {} does not have a manifest', module_name)) return test_suite +def problem_key(problem): + problem_hierarchy = ['error', 'warning', 'notice'] + return (problem_hierarchy.index(problem['type']), problem['line-number']) + def check_model(model, test_suite = None): if not test_suite: test_suite = load_tests() - report = [] + problems = [] line_numbers = { element: (i, i + 1 + model.body_offset) for i, element in enumerate(model.body) } for test_name, test_function in test_suite['tests'].items(): - problems = test_function(model) - for problem in problems: + for problem in test_function(model): problem['body-index'], problem['line-number'] \ = line_numbers[problem['object']] del problem['object'] - report.append(problem) - return report + problems.append(problem) + return { + 'passed': not any( + problem['type'] == 'error' + for problem in problems + ), + 'problems': sorted(problems, key = problem_key), + } def problem_text(problem, test_suite): message = test_suite['messages'][problem['name']] @@ -91,8 +103,8 @@ return message def format_report_html(report, model, test_suite): - result = [] - for problem in report: + messages = [] + for problem in report['problems']: ldraw_code = model.body[problem['body-index']].textual_representation() message = str.format( '