Mon, 24 Jun 2019 10:16:36 +0300
fixed the collinear test for polygons with identical vertices
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 |
19 | if abs(subfile_reference.matrix.determinant() - 0) < 1e-15 | |
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', |
64
1c0884f5506e
changed severity names to be better understood
Teemu Piippo <teemu@hecknology.net>
parents:
62
diff
changeset
|
118 | severity = 'hold', |
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 | ) |
54
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
144 | 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
|
145 | ''' |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
146 | 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
|
147 | 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
|
148 | 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
|
149 | ''' |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
150 | import filecache |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
151 | cache = filecache.SubfileCache(model.ldraw_directories) |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
152 | failed_subfiles = set() |
80
2f81758d1537
added a test for unnecessary invertnext use
Teemu Piippo <teemu@hecknology.net>
parents:
79
diff
changeset
|
153 | 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
|
154 | 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
|
155 | 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
|
156 | # 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
|
157 | pass |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
158 | else: |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
159 | try: |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
160 | 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
|
161 | except filecache.CyclicalReferenceError as e: |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
162 | 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
|
163 | yield report_problem( |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
164 | 'cyclical-reference', |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
165 | 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
|
166 | chain = str(e), |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
167 | ) |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
168 | if 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
|
169 | yield report_problem( |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
170 | 'bad-subfile', |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
171 | 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
|
172 | path = path, |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
173 | 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
|
174 | ) |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
175 | failed_subfiles.add(path) |
55
388df1fa18a2
fixed handling of invalid subfiles
Teemu Piippo <teemu@hecknology.net>
parents:
54
diff
changeset
|
176 | else: |
80
2f81758d1537
added a test for unnecessary invertnext use
Teemu Piippo <teemu@hecknology.net>
parents:
79
diff
changeset
|
177 | # Test for use of moved-to files |
55
388df1fa18a2
fixed handling of invalid subfiles
Teemu Piippo <teemu@hecknology.net>
parents:
54
diff
changeset
|
178 | 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
|
179 | match = re.search(r'^\~Moved(?: to (.+))?$', subfile.description) |
55
388df1fa18a2
fixed handling of invalid subfiles
Teemu Piippo <teemu@hecknology.net>
parents:
54
diff
changeset
|
180 | if match: |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
181 | yield report_problem( |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
182 | 'moved-file-used', |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
183 | bad_object = subfile_reference, |
55
388df1fa18a2
fixed handling of invalid subfiles
Teemu Piippo <teemu@hecknology.net>
parents:
54
diff
changeset
|
184 | 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
|
185 | 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
|
186 | ) |
80
2f81758d1537
added a test for unnecessary invertnext use
Teemu Piippo <teemu@hecknology.net>
parents:
79
diff
changeset
|
187 | # Test for scaling in flat direction |
55
388df1fa18a2
fixed handling of invalid subfiles
Teemu Piippo <teemu@hecknology.net>
parents:
54
diff
changeset
|
188 | scaling_vector = subfile_reference.matrix.scaling_vector() |
388df1fa18a2
fixed handling of invalid subfiles
Teemu Piippo <teemu@hecknology.net>
parents:
54
diff
changeset
|
189 | scaled_dimensions = { |
388df1fa18a2
fixed handling of invalid subfiles
Teemu Piippo <teemu@hecknology.net>
parents:
54
diff
changeset
|
190 | dimension |
388df1fa18a2
fixed handling of invalid subfiles
Teemu Piippo <teemu@hecknology.net>
parents:
54
diff
changeset
|
191 | for dimension in subfile.flatness |
388df1fa18a2
fixed handling of invalid subfiles
Teemu Piippo <teemu@hecknology.net>
parents:
54
diff
changeset
|
192 | if not math.isclose( |
388df1fa18a2
fixed handling of invalid subfiles
Teemu Piippo <teemu@hecknology.net>
parents:
54
diff
changeset
|
193 | getattr(scaling_vector, dimension), |
388df1fa18a2
fixed handling of invalid subfiles
Teemu Piippo <teemu@hecknology.net>
parents:
54
diff
changeset
|
194 | 1, |
388df1fa18a2
fixed handling of invalid subfiles
Teemu Piippo <teemu@hecknology.net>
parents:
54
diff
changeset
|
195 | abs_tol = 1.0e-05 |
388df1fa18a2
fixed handling of invalid subfiles
Teemu Piippo <teemu@hecknology.net>
parents:
54
diff
changeset
|
196 | ) |
388df1fa18a2
fixed handling of invalid subfiles
Teemu Piippo <teemu@hecknology.net>
parents:
54
diff
changeset
|
197 | } |
388df1fa18a2
fixed handling of invalid subfiles
Teemu Piippo <teemu@hecknology.net>
parents:
54
diff
changeset
|
198 | scaled_flat_dimensions = subfile.flatness & scaled_dimensions |
388df1fa18a2
fixed handling of invalid subfiles
Teemu Piippo <teemu@hecknology.net>
parents:
54
diff
changeset
|
199 | 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
|
200 | yield report_problem( |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
201 | 'unnecessary-scaling', |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
202 | bad_object = subfile_reference, |
55
388df1fa18a2
fixed handling of invalid subfiles
Teemu Piippo <teemu@hecknology.net>
parents:
54
diff
changeset
|
203 | scaled_flat_dimensions = scaled_flat_dimensions, |
388df1fa18a2
fixed handling of invalid subfiles
Teemu Piippo <teemu@hecknology.net>
parents:
54
diff
changeset
|
204 | scaling_vector = scaling_vector, |
388df1fa18a2
fixed handling of invalid subfiles
Teemu Piippo <teemu@hecknology.net>
parents:
54
diff
changeset
|
205 | ) |
80
2f81758d1537
added a test for unnecessary invertnext use
Teemu Piippo <teemu@hecknology.net>
parents:
79
diff
changeset
|
206 | # 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
|
207 | if has_invertnext and subfile.flatness: |
2f81758d1537
added a test for unnecessary invertnext use
Teemu Piippo <teemu@hecknology.net>
parents:
79
diff
changeset
|
208 | yield report_problem( |
2f81758d1537
added a test for unnecessary invertnext use
Teemu Piippo <teemu@hecknology.net>
parents:
79
diff
changeset
|
209 | 'unnecessary-invertnext', |
2f81758d1537
added a test for unnecessary invertnext use
Teemu Piippo <teemu@hecknology.net>
parents:
79
diff
changeset
|
210 | bad_object = subfile_reference, |
2f81758d1537
added a test for unnecessary invertnext use
Teemu Piippo <teemu@hecknology.net>
parents:
79
diff
changeset
|
211 | ) |
54
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
212 | |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
213 | 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
|
214 | 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
|
215 | return dimensions |
54
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
216 | else: |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
217 | 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
|
218 | 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
|
219 | 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
|
220 | else: |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
221 | 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
|
222 | ', '.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
|
223 | sorted_dims[-1], |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
224 | ) |
54
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
225 | |
23 | 226 | manifest = { |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
227 | 'tests': [ |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
228 | determinant_test, |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
229 | scaling_legality_test, |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
230 | dependent_subfile_tests, |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
231 | ], |
23 | 232 | } |