1 #!/usr/bin/env python3 |
1 #!/usr/bin/env python3 |
2 from ldcheck import appname, version, version_string |
2 from ldcheck import appname, version, version_string |
3 from ldcheck import load_config, find_ldconfig_ldr_paths |
|
4 from ldcheck import script_directory |
3 from ldcheck import script_directory |
5 from pathlib import Path |
4 from pathlib import Path |
6 from parse import read_ldraw |
5 from parse import read_ldraw |
7 from testsuite import load_tests, check_model, problem_text, all_problem_type_names |
6 from testsuite import load_tests, check_model, problem_text, all_problem_type_names |
8 |
7 |
19 |
18 |
20 def parse_expectation(text): |
19 def parse_expectation(text): |
21 problem_type, line_no_str = str.split(text, ':') |
20 problem_type, line_no_str = str.split(text, ':') |
22 return problem_type, int(line_no_str) |
21 return problem_type, int(line_no_str) |
23 |
22 |
24 def load_unit_test(unit_test_path, *, name, ldraw_directories): |
23 def load_unit_test(unit_test_path, *, name, context): |
25 with open(unit_test_path, 'rb') as device: |
24 with open(unit_test_path, 'rb') as device: |
26 import re |
25 import re |
27 problem_types = set() |
26 problem_types = set() |
28 expecting = None |
27 expecting = None |
29 while True: |
28 while True: |
54 'problem_types': problem_types, |
53 'problem_types': problem_types, |
55 'expecting': expecting, |
54 'expecting': expecting, |
56 'model': read_ldraw( |
55 'model': read_ldraw( |
57 device, |
56 device, |
58 name = name, |
57 name = name, |
59 ldraw_directories = ldraw_directories |
58 context = context |
60 ), |
59 ), |
61 } |
60 } |
62 |
61 |
63 def parse_problem(problem): |
62 def parse_problem(problem): |
64 return problem.problem_class.name, problem.line_number |
63 return problem.problem_class.name, problem.line_number |
65 |
64 |
66 def run_unit_test(unit_test_path, *, config, test_suite): |
65 def run_unit_test(unit_test_path, *, context, test_suite): |
67 from os.path import basename |
66 from os.path import basename |
68 unit_test = load_unit_test( |
67 unit_test = load_unit_test( |
69 unit_test_path, |
68 unit_test_path, |
70 name = basename(unit_test_path), |
69 name = basename(unit_test_path), |
71 ldraw_directories = config['libraries'], |
70 context = context, |
72 ) |
71 ) |
73 bad_problems = set.difference( |
72 bad_problems = set.difference( |
74 unit_test['problem_types'], |
73 unit_test['problem_types'], |
75 all_problem_type_names(test_suite) |
74 all_problem_type_names(test_suite) |
76 ) |
75 ) |
104 def run_unit_test_suite(): |
103 def run_unit_test_suite(): |
105 from argparse import ArgumentParser |
104 from argparse import ArgumentParser |
106 parser = ArgumentParser() |
105 parser = ArgumentParser() |
107 parser.add_argument('-d', '--debug', action = 'store_true') |
106 parser.add_argument('-d', '--debug', action = 'store_true') |
108 args = parser.parse_args() |
107 args = parser.parse_args() |
109 config = load_config() |
108 from ldcheck import LDrawContext |
|
109 context = LDrawContext() |
110 test_suite = load_tests() |
110 test_suite = load_tests() |
111 num_tested = 0 |
111 num_tested = 0 |
112 num_passed = 0 |
112 num_passed = 0 |
113 all_problem_types = all_problem_type_names(test_suite) |
113 all_problem_types = all_problem_type_names(test_suite) |
114 problem_types_tested = set() |
114 problem_types_tested = set() |
115 print('Running unit test suite.') |
115 print('Running unit test suite.') |
116 for unit_test_path in unit_test_discovery(): |
116 for unit_test_path in unit_test_discovery(): |
117 try: |
117 try: |
118 unit_test_report = run_unit_test( |
118 unit_test_report = run_unit_test( |
119 unit_test_path, |
119 unit_test_path, |
120 config = config, |
120 context = context, |
121 test_suite = test_suite |
121 test_suite = test_suite |
122 ) |
122 ) |
123 except Exception as error: |
123 except Exception as error: |
124 if args.debug: |
124 if args.debug: |
125 raise |
125 raise |