Thu, 26 Aug 2021 22:04:33 +0300
removed some alias tests that aren't mandated by the official header specification
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
1 | from testsuite import problem_type, report_problem |
54
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
2 | import testsuite |
24 | 3 | from geometry import * |
54
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
4 | import math |
89
d2b277cb948e
split more tests into new files
Teemu Piippo <teemu@hecknology.net>
parents:
85
diff
changeset
|
5 | from librarystandards import library_standards |
23 | 6 | |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
7 | @problem_type('zero-determinant', |
64
1c0884f5506e
changed severity names to be better understood
Teemu Piippo <teemu@hecknology.net>
parents:
62
diff
changeset
|
8 | severity = 'hold', |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
9 | message = 'matrix row or column all zero' |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
10 | ) |
23 | 11 | def determinant_test(model): |
26
7c263b864371
Added command line option to list all checks.
Santeri Piippo
parents:
24
diff
changeset
|
12 | ''' |
7c263b864371
Added command line option to list all checks.
Santeri Piippo
parents:
24
diff
changeset
|
13 | Checks all subfile references for matrices with rows or columns all |
7c263b864371
Added command line option to list all checks.
Santeri Piippo
parents:
24
diff
changeset
|
14 | zero. |
7c263b864371
Added command line option to list all checks.
Santeri Piippo
parents:
24
diff
changeset
|
15 | ''' |
24 | 16 | yield from ( |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
17 | report_problem('zero-determinant', bad_object = subfile_reference) |
23 | 18 | for subfile_reference in model.subfile_references |
104
1ad664f783d6
use a bigger threshold in the determinant test
Teemu Piippo <teemu@hecknology.net>
parents:
95
diff
changeset
|
19 | if abs(subfile_reference.matrix.determinant() - 0) < 1e-5 |
24 | 20 | ) |
21 | ||
22 | def scaling_description(scaling, axes = 'xyz'): | |
23 | ''' | |
24 | Returns a pretty description of a scaling vector. The axes parameter | |
25 | controls what axes are printed and can be used to filter away | |
26 | uninteresting values. | |
27 | ''' | |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
28 | if isinstance(scaling, str): |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
29 | return scaling |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
30 | else: |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
31 | return ', '.join( |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
32 | str.format('{} = {}', letter, getattr(scaling, letter)) |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
33 | for letter in axes |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
34 | ) |
24 | 35 | |
36 | def check_scaling(scaling, axes): | |
37 | ''' Returns whether all given axes on the given scaling vector are 1. ''' | |
38 | return all( | |
39 | abs(getattr(scaling, axis) - 1) < 1e-5 | |
40 | for axis in axes | |
41 | ) | |
42 | ||
43 | # Restriction to checking function mapping. | |
44 | restriction_tests = { | |
45 | 'no scaling': lambda scaling: check_scaling(scaling, 'xyz'), | |
46 | 'y-scaling only': lambda scaling: check_scaling(scaling, 'xz'), | |
47 | 'stud3-like scaling': lambda scaling: all([ | |
48 | check_scaling(scaling, 'xz'), | |
49 | # check if y-scaling is 1 or -1 | |
50 | abs(abs(scaling.y) - 1) < 1e-5, | |
51 | ]), | |
52 | } | |
53 | ||
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
54 | @problem_type('illegal-scaling', |
64
1c0884f5506e
changed severity names to be better understood
Teemu Piippo <teemu@hecknology.net>
parents:
62
diff
changeset
|
55 | severity = 'hold', |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
56 | message = lambda primitive, scaling, axes: |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
57 | str.format('scaling of unscalable primitive {} ({})', |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
58 | primitive, |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
59 | scaling_description(scaling, axes), |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
60 | ), |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
61 | ) |
24 | 62 | def scaling_legality_test(model): |
26
7c263b864371
Added command line option to list all checks.
Santeri Piippo
parents:
24
diff
changeset
|
63 | ''' |
7c263b864371
Added command line option to list all checks.
Santeri Piippo
parents:
24
diff
changeset
|
64 | Checks the part against primitive references with bad scaling. Some |
7c263b864371
Added command line option to list all checks.
Santeri Piippo
parents:
24
diff
changeset
|
65 | primitives (e.g. pegs) are not allowed to be scaled in the |
7c263b864371
Added command line option to list all checks.
Santeri Piippo
parents:
24
diff
changeset
|
66 | X or Z directions. Some (e.g. most studs) are not allowed to be scaled |
7c263b864371
Added command line option to list all checks.
Santeri Piippo
parents:
24
diff
changeset
|
67 | in the Y direction either. |
7c263b864371
Added command line option to list all checks.
Santeri Piippo
parents:
24
diff
changeset
|
68 | ''' |
24 | 69 | from fnmatch import fnmatch |
70 | scaling_restrictions = library_standards['scaling restrictions'] | |
71 | for subfile_reference in model.subfile_references: | |
72 | primitive = subfile_reference.subfile_path.lower() | |
73 | scaling = subfile_reference.matrix.scaling_vector() | |
74 | # Find all restrictions that apply to this subfile reference. | |
75 | restrictions = { | |
76 | restriction | |
77 | for pattern, restriction in scaling_restrictions.items() | |
78 | if fnmatch(primitive, pattern) | |
79 | } | |
80 | # Check restrictions against the subfile. If any restrictions were | |
81 | # found then the scaling vector must pass at least one of them. | |
82 | if restrictions and not any( | |
83 | restriction_tests[restriction](scaling) | |
84 | for restriction in restrictions | |
85 | ): | |
86 | interesting_axes = ''.join( | |
87 | axis | |
88 | for axis in 'xyz' | |
89 | if abs(getattr(scaling, axis) - 1) > 1e-5 | |
90 | ) | |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
91 | yield report_problem('illegal-scaling', |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
92 | bad_object = subfile_reference, |
24 | 93 | primitive = primitive, |
94 | axes = interesting_axes, | |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
95 | scaling = scaling, |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
96 | ) |
23 | 97 | |
80
2f81758d1537
added a test for unnecessary invertnext use
Teemu Piippo <teemu@hecknology.net>
parents:
79
diff
changeset
|
98 | def subfile_references_with_invertnext(model): |
2f81758d1537
added a test for unnecessary invertnext use
Teemu Piippo <teemu@hecknology.net>
parents:
79
diff
changeset
|
99 | import linetypes |
2f81758d1537
added a test for unnecessary invertnext use
Teemu Piippo <teemu@hecknology.net>
parents:
79
diff
changeset
|
100 | has_invertnext = False |
2f81758d1537
added a test for unnecessary invertnext use
Teemu Piippo <teemu@hecknology.net>
parents:
79
diff
changeset
|
101 | for element in model.body: |
2f81758d1537
added a test for unnecessary invertnext use
Teemu Piippo <teemu@hecknology.net>
parents:
79
diff
changeset
|
102 | if isinstance(element, linetypes.MetaCommand) \ |
2f81758d1537
added a test for unnecessary invertnext use
Teemu Piippo <teemu@hecknology.net>
parents:
79
diff
changeset
|
103 | and element.text == 'BFC INVERTNEXT': |
2f81758d1537
added a test for unnecessary invertnext use
Teemu Piippo <teemu@hecknology.net>
parents:
79
diff
changeset
|
104 | has_invertnext = True |
2f81758d1537
added a test for unnecessary invertnext use
Teemu Piippo <teemu@hecknology.net>
parents:
79
diff
changeset
|
105 | else: |
2f81758d1537
added a test for unnecessary invertnext use
Teemu Piippo <teemu@hecknology.net>
parents:
79
diff
changeset
|
106 | if isinstance(element, linetypes.SubfileReference): |
2f81758d1537
added a test for unnecessary invertnext use
Teemu Piippo <teemu@hecknology.net>
parents:
79
diff
changeset
|
107 | yield element, has_invertnext |
2f81758d1537
added a test for unnecessary invertnext use
Teemu Piippo <teemu@hecknology.net>
parents:
79
diff
changeset
|
108 | has_invertnext = False |
2f81758d1537
added a test for unnecessary invertnext use
Teemu Piippo <teemu@hecknology.net>
parents:
79
diff
changeset
|
109 | |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
110 | @problem_type('cyclical-reference', |
64
1c0884f5506e
changed severity names to be better understood
Teemu Piippo <teemu@hecknology.net>
parents:
62
diff
changeset
|
111 | severity = 'hold', |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
112 | message = lambda chain: |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
113 | str.format('cyclical subfile dependency: {chain}', |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
114 | **locals(), |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
115 | ), |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
116 | ) |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
117 | @problem_type('bad-subfile', |
111 | 118 | severity = 'warning', |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
119 | message = lambda path, problem_text: |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
120 | str.format('cannot process subfile "{path}": {problem_text}', |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
121 | **locals(), |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
122 | ), |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
123 | ) |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
124 | @problem_type('moved-file-used', |
64
1c0884f5506e
changed severity names to be better understood
Teemu Piippo <teemu@hecknology.net>
parents:
62
diff
changeset
|
125 | severity = 'hold', |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
126 | message = lambda moved_file, new_file: |
85
4438502fd3e0
fixed the use of moved-to-files check not working if there were non-alphanumerics in the filename
Teemu Piippo <teemu@hecknology.net>
parents:
83
diff
changeset
|
127 | str.format('subfile "{moved_file}" has been moved to "{new_file}.dat"', |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
128 | **locals(), |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
129 | ), |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
130 | ) |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
131 | @problem_type('unnecessary-scaling', |
64
1c0884f5506e
changed severity names to be better understood
Teemu Piippo <teemu@hecknology.net>
parents:
62
diff
changeset
|
132 | severity = 'warning', |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
133 | message = lambda scaled_flat_dimensions, scaling_vector: |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
134 | str.format( |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
135 | 'subfile unnecessarily scaled in the {dims} ({scaling})', |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
136 | dims = dimensions_description(scaled_flat_dimensions), |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
137 | scaling = scaling_description(scaling_vector), |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
138 | ), |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
139 | ) |
80
2f81758d1537
added a test for unnecessary invertnext use
Teemu Piippo <teemu@hecknology.net>
parents:
79
diff
changeset
|
140 | @problem_type('unnecessary-invertnext', |
2f81758d1537
added a test for unnecessary invertnext use
Teemu Piippo <teemu@hecknology.net>
parents:
79
diff
changeset
|
141 | severity = 'warning', |
2f81758d1537
added a test for unnecessary invertnext use
Teemu Piippo <teemu@hecknology.net>
parents:
79
diff
changeset
|
142 | message = 'flat subfile unnecessarily inverted using BFC INVERTNEXT' |
2f81758d1537
added a test for unnecessary invertnext use
Teemu Piippo <teemu@hecknology.net>
parents:
79
diff
changeset
|
143 | ) |
92
b8d72909d593
improved the mirrored stud check to catch cases where a subfile that contains studs is mirrored
Teemu Piippo <teemu@hecknology.net>
parents:
89
diff
changeset
|
144 | @problem_type('mirrored-studs', |
b8d72909d593
improved the mirrored stud check to catch cases where a subfile that contains studs is mirrored
Teemu Piippo <teemu@hecknology.net>
parents:
89
diff
changeset
|
145 | severity = 'warning', |
b8d72909d593
improved the mirrored stud check to catch cases where a subfile that contains studs is mirrored
Teemu Piippo <teemu@hecknology.net>
parents:
89
diff
changeset
|
146 | message = lambda primitive: str.format( |
b8d72909d593
improved the mirrored stud check to catch cases where a subfile that contains studs is mirrored
Teemu Piippo <teemu@hecknology.net>
parents:
89
diff
changeset
|
147 | '"{primitive}" should not be mirrored', |
b8d72909d593
improved the mirrored stud check to catch cases where a subfile that contains studs is mirrored
Teemu Piippo <teemu@hecknology.net>
parents:
89
diff
changeset
|
148 | primitive = primitive, |
b8d72909d593
improved the mirrored stud check to catch cases where a subfile that contains studs is mirrored
Teemu Piippo <teemu@hecknology.net>
parents:
89
diff
changeset
|
149 | ) |
b8d72909d593
improved the mirrored stud check to catch cases where a subfile that contains studs is mirrored
Teemu Piippo <teemu@hecknology.net>
parents:
89
diff
changeset
|
150 | ) |
b8d72909d593
improved the mirrored stud check to catch cases where a subfile that contains studs is mirrored
Teemu Piippo <teemu@hecknology.net>
parents:
89
diff
changeset
|
151 | @problem_type('mirrored-studs-indirect', |
b8d72909d593
improved the mirrored stud check to catch cases where a subfile that contains studs is mirrored
Teemu Piippo <teemu@hecknology.net>
parents:
89
diff
changeset
|
152 | severity = 'warning', |
b8d72909d593
improved the mirrored stud check to catch cases where a subfile that contains studs is mirrored
Teemu Piippo <teemu@hecknology.net>
parents:
89
diff
changeset
|
153 | message = lambda primitive: str.format( |
b8d72909d593
improved the mirrored stud check to catch cases where a subfile that contains studs is mirrored
Teemu Piippo <teemu@hecknology.net>
parents:
89
diff
changeset
|
154 | '"{primitive}" should not be mirrored because it contains studs', |
b8d72909d593
improved the mirrored stud check to catch cases where a subfile that contains studs is mirrored
Teemu Piippo <teemu@hecknology.net>
parents:
89
diff
changeset
|
155 | primitive = primitive, |
b8d72909d593
improved the mirrored stud check to catch cases where a subfile that contains studs is mirrored
Teemu Piippo <teemu@hecknology.net>
parents:
89
diff
changeset
|
156 | ) |
b8d72909d593
improved the mirrored stud check to catch cases where a subfile that contains studs is mirrored
Teemu Piippo <teemu@hecknology.net>
parents:
89
diff
changeset
|
157 | ) |
54
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
158 | def dependent_subfile_tests(model): |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
159 | ''' |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
160 | Tests subfile references for such qualities that are dependent on the |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
161 | actual contents of the subfiles. Checks whether moved-to files are used. |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
162 | Checks whether flat subfiles are scaled in the flat direction. |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
163 | ''' |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
164 | import filecache |
145
fde18c4d6784
refactoring: moved context-dependant data to new class LDrawContext. ldcheck no longer writes the config file, and looks for it in sensible locations like ~/.config and /etc. LDraw libraries can now be specified on the command line.
Teemu Piippo <teemu@hecknology.net>
parents:
111
diff
changeset
|
165 | cache = filecache.SubfileCache(context = model.context) |
95
a3536e51f6bc
fixed the cyclical dependency handling
Teemu Piippo <teemu@hecknology.net>
parents:
92
diff
changeset
|
166 | if model.header.valid: |
a3536e51f6bc
fixed the cyclical dependency handling
Teemu Piippo <teemu@hecknology.net>
parents:
92
diff
changeset
|
167 | cache.reference_stack.append(model.header.name) |
54
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
168 | failed_subfiles = set() |
80
2f81758d1537
added a test for unnecessary invertnext use
Teemu Piippo <teemu@hecknology.net>
parents:
79
diff
changeset
|
169 | for subfile_reference, has_invertnext in subfile_references_with_invertnext(model): |
54
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
170 | path = subfile_reference.subfile_path.lower() |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
171 | if path in failed_subfiles: |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
172 | # Already proven to be a bad apple, don't complain twice |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
173 | pass |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
174 | else: |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
175 | try: |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
176 | subfile = cache.prepare_file(path) |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
177 | except filecache.CyclicalReferenceError as e: |
95
a3536e51f6bc
fixed the cyclical dependency handling
Teemu Piippo <teemu@hecknology.net>
parents:
92
diff
changeset
|
178 | subfile = None |
54
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
179 | failed_subfiles.add(path) |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
180 | yield report_problem( |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
181 | 'cyclical-reference', |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
182 | bad_object = subfile_reference, |
54
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
183 | chain = str(e), |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
184 | ) |
95
a3536e51f6bc
fixed the cyclical dependency handling
Teemu Piippo <teemu@hecknology.net>
parents:
92
diff
changeset
|
185 | if subfile and not subfile.valid: |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
186 | yield report_problem( |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
187 | 'bad-subfile', |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
188 | bad_object = subfile_reference, |
54
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
189 | path = path, |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
190 | problem_text = subfile.problem, |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
191 | ) |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
192 | failed_subfiles.add(path) |
95
a3536e51f6bc
fixed the cyclical dependency handling
Teemu Piippo <teemu@hecknology.net>
parents:
92
diff
changeset
|
193 | elif subfile: |
80
2f81758d1537
added a test for unnecessary invertnext use
Teemu Piippo <teemu@hecknology.net>
parents:
79
diff
changeset
|
194 | # Test for use of moved-to files |
55
388df1fa18a2
fixed handling of invalid subfiles
Teemu Piippo <teemu@hecknology.net>
parents:
54
diff
changeset
|
195 | import re |
85
4438502fd3e0
fixed the use of moved-to-files check not working if there were non-alphanumerics in the filename
Teemu Piippo <teemu@hecknology.net>
parents:
83
diff
changeset
|
196 | match = re.search(r'^\~Moved(?: to (.+))?$', subfile.description) |
55
388df1fa18a2
fixed handling of invalid subfiles
Teemu Piippo <teemu@hecknology.net>
parents:
54
diff
changeset
|
197 | if match: |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
198 | yield report_problem( |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
199 | 'moved-file-used', |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
200 | bad_object = subfile_reference, |
55
388df1fa18a2
fixed handling of invalid subfiles
Teemu Piippo <teemu@hecknology.net>
parents:
54
diff
changeset
|
201 | moved_file = path, |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
202 | new_file = match.group(1), |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
203 | ) |
80
2f81758d1537
added a test for unnecessary invertnext use
Teemu Piippo <teemu@hecknology.net>
parents:
79
diff
changeset
|
204 | # Test for scaling in flat direction |
55
388df1fa18a2
fixed handling of invalid subfiles
Teemu Piippo <teemu@hecknology.net>
parents:
54
diff
changeset
|
205 | scaling_vector = subfile_reference.matrix.scaling_vector() |
388df1fa18a2
fixed handling of invalid subfiles
Teemu Piippo <teemu@hecknology.net>
parents:
54
diff
changeset
|
206 | scaled_dimensions = { |
388df1fa18a2
fixed handling of invalid subfiles
Teemu Piippo <teemu@hecknology.net>
parents:
54
diff
changeset
|
207 | dimension |
388df1fa18a2
fixed handling of invalid subfiles
Teemu Piippo <teemu@hecknology.net>
parents:
54
diff
changeset
|
208 | for dimension in subfile.flatness |
388df1fa18a2
fixed handling of invalid subfiles
Teemu Piippo <teemu@hecknology.net>
parents:
54
diff
changeset
|
209 | if not math.isclose( |
388df1fa18a2
fixed handling of invalid subfiles
Teemu Piippo <teemu@hecknology.net>
parents:
54
diff
changeset
|
210 | getattr(scaling_vector, dimension), |
388df1fa18a2
fixed handling of invalid subfiles
Teemu Piippo <teemu@hecknology.net>
parents:
54
diff
changeset
|
211 | 1, |
388df1fa18a2
fixed handling of invalid subfiles
Teemu Piippo <teemu@hecknology.net>
parents:
54
diff
changeset
|
212 | abs_tol = 1.0e-05 |
388df1fa18a2
fixed handling of invalid subfiles
Teemu Piippo <teemu@hecknology.net>
parents:
54
diff
changeset
|
213 | ) |
388df1fa18a2
fixed handling of invalid subfiles
Teemu Piippo <teemu@hecknology.net>
parents:
54
diff
changeset
|
214 | } |
388df1fa18a2
fixed handling of invalid subfiles
Teemu Piippo <teemu@hecknology.net>
parents:
54
diff
changeset
|
215 | scaled_flat_dimensions = subfile.flatness & scaled_dimensions |
388df1fa18a2
fixed handling of invalid subfiles
Teemu Piippo <teemu@hecknology.net>
parents:
54
diff
changeset
|
216 | if scaled_flat_dimensions: |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
217 | yield report_problem( |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
218 | 'unnecessary-scaling', |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
219 | bad_object = subfile_reference, |
55
388df1fa18a2
fixed handling of invalid subfiles
Teemu Piippo <teemu@hecknology.net>
parents:
54
diff
changeset
|
220 | scaled_flat_dimensions = scaled_flat_dimensions, |
388df1fa18a2
fixed handling of invalid subfiles
Teemu Piippo <teemu@hecknology.net>
parents:
54
diff
changeset
|
221 | scaling_vector = scaling_vector, |
388df1fa18a2
fixed handling of invalid subfiles
Teemu Piippo <teemu@hecknology.net>
parents:
54
diff
changeset
|
222 | ) |
80
2f81758d1537
added a test for unnecessary invertnext use
Teemu Piippo <teemu@hecknology.net>
parents:
79
diff
changeset
|
223 | # Test whether a flat subfile is inverted using invertnext |
2f81758d1537
added a test for unnecessary invertnext use
Teemu Piippo <teemu@hecknology.net>
parents:
79
diff
changeset
|
224 | if has_invertnext and subfile.flatness: |
2f81758d1537
added a test for unnecessary invertnext use
Teemu Piippo <teemu@hecknology.net>
parents:
79
diff
changeset
|
225 | yield report_problem( |
2f81758d1537
added a test for unnecessary invertnext use
Teemu Piippo <teemu@hecknology.net>
parents:
79
diff
changeset
|
226 | 'unnecessary-invertnext', |
2f81758d1537
added a test for unnecessary invertnext use
Teemu Piippo <teemu@hecknology.net>
parents:
79
diff
changeset
|
227 | bad_object = subfile_reference, |
2f81758d1537
added a test for unnecessary invertnext use
Teemu Piippo <teemu@hecknology.net>
parents:
79
diff
changeset
|
228 | ) |
92
b8d72909d593
improved the mirrored stud check to catch cases where a subfile that contains studs is mirrored
Teemu Piippo <teemu@hecknology.net>
parents:
89
diff
changeset
|
229 | from filecache import is_logo_stud_name |
b8d72909d593
improved the mirrored stud check to catch cases where a subfile that contains studs is mirrored
Teemu Piippo <teemu@hecknology.net>
parents:
89
diff
changeset
|
230 | # Test whether any stud subfile is mirrored. |
b8d72909d593
improved the mirrored stud check to catch cases where a subfile that contains studs is mirrored
Teemu Piippo <teemu@hecknology.net>
parents:
89
diff
changeset
|
231 | if is_logo_stud_name(subfile_reference.subfile_path) \ |
b8d72909d593
improved the mirrored stud check to catch cases where a subfile that contains studs is mirrored
Teemu Piippo <teemu@hecknology.net>
parents:
89
diff
changeset
|
232 | and subfile_reference.matrix.is_mirrored(): |
b8d72909d593
improved the mirrored stud check to catch cases where a subfile that contains studs is mirrored
Teemu Piippo <teemu@hecknology.net>
parents:
89
diff
changeset
|
233 | yield report_problem( |
b8d72909d593
improved the mirrored stud check to catch cases where a subfile that contains studs is mirrored
Teemu Piippo <teemu@hecknology.net>
parents:
89
diff
changeset
|
234 | 'mirrored-studs', |
b8d72909d593
improved the mirrored stud check to catch cases where a subfile that contains studs is mirrored
Teemu Piippo <teemu@hecknology.net>
parents:
89
diff
changeset
|
235 | bad_object = subfile_reference, |
b8d72909d593
improved the mirrored stud check to catch cases where a subfile that contains studs is mirrored
Teemu Piippo <teemu@hecknology.net>
parents:
89
diff
changeset
|
236 | primitive = subfile_reference.subfile_path, |
b8d72909d593
improved the mirrored stud check to catch cases where a subfile that contains studs is mirrored
Teemu Piippo <teemu@hecknology.net>
parents:
89
diff
changeset
|
237 | ) |
b8d72909d593
improved the mirrored stud check to catch cases where a subfile that contains studs is mirrored
Teemu Piippo <teemu@hecknology.net>
parents:
89
diff
changeset
|
238 | elif subfile.has_studs and subfile_reference.matrix.is_mirrored(): |
b8d72909d593
improved the mirrored stud check to catch cases where a subfile that contains studs is mirrored
Teemu Piippo <teemu@hecknology.net>
parents:
89
diff
changeset
|
239 | yield report_problem( |
b8d72909d593
improved the mirrored stud check to catch cases where a subfile that contains studs is mirrored
Teemu Piippo <teemu@hecknology.net>
parents:
89
diff
changeset
|
240 | 'mirrored-studs-indirect', |
b8d72909d593
improved the mirrored stud check to catch cases where a subfile that contains studs is mirrored
Teemu Piippo <teemu@hecknology.net>
parents:
89
diff
changeset
|
241 | bad_object = subfile_reference, |
b8d72909d593
improved the mirrored stud check to catch cases where a subfile that contains studs is mirrored
Teemu Piippo <teemu@hecknology.net>
parents:
89
diff
changeset
|
242 | primitive = subfile_reference.subfile_path, |
b8d72909d593
improved the mirrored stud check to catch cases where a subfile that contains studs is mirrored
Teemu Piippo <teemu@hecknology.net>
parents:
89
diff
changeset
|
243 | ) |
54
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
244 | |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
245 | def dimensions_description(dimensions): |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
246 | if isinstance(dimensions, str): |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
247 | return dimensions |
54
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
248 | else: |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
249 | sorted_dims = sorted(dimensions) |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
250 | if len(sorted_dims) == 1: |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
251 | return sorted_dims[0] + ' dimension' |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
252 | else: |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
253 | return str.format('{} and {} dimensions', |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
254 | ', '.join(sorted_dims[:-1]), |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
255 | sorted_dims[-1], |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
256 | ) |
54
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
257 | |
23 | 258 | manifest = { |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
259 | 'tests': [ |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
260 | determinant_test, |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
261 | scaling_legality_test, |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
262 | dependent_subfile_tests, |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
263 | ], |
23 | 264 | } |