Sat, 22 Jun 2019 23:38:51 +0300
complain about missing BFC declarations
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 * |
4 | from os.path import dirname | |
5 | from pathlib import Path | |
6 | from configparser import ConfigParser | |
54
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
7 | import math |
24 | 8 | ini_path = Path(dirname(__file__)) / 'library-standards.ini' |
9 | library_standards = ConfigParser() | |
10 | ||
37
e46fa477007b
Fix operation under Python 3.4
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
11 | with ini_path.open() as file: |
24 | 12 | library_standards.read_file(file) |
23 | 13 | |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
14 | @problem_type('zero-determinant', |
64
1c0884f5506e
changed severity names to be better understood
Teemu Piippo <teemu@hecknology.net>
parents:
62
diff
changeset
|
15 | severity = 'hold', |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
16 | 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
|
17 | ) |
23 | 18 | def determinant_test(model): |
26
7c263b864371
Added command line option to list all checks.
Santeri Piippo
parents:
24
diff
changeset
|
19 | ''' |
7c263b864371
Added command line option to list all checks.
Santeri Piippo
parents:
24
diff
changeset
|
20 | 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
|
21 | zero. |
7c263b864371
Added command line option to list all checks.
Santeri Piippo
parents:
24
diff
changeset
|
22 | ''' |
24 | 23 | yield from ( |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
24 | report_problem('zero-determinant', bad_object = subfile_reference) |
23 | 25 | for subfile_reference in model.subfile_references |
26 | if abs(subfile_reference.matrix.determinant() - 0) < 1e-15 | |
24 | 27 | ) |
28 | ||
29 | def scaling_description(scaling, axes = 'xyz'): | |
30 | ''' | |
31 | Returns a pretty description of a scaling vector. The axes parameter | |
32 | controls what axes are printed and can be used to filter away | |
33 | uninteresting values. | |
34 | ''' | |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
35 | 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
|
36 | return scaling |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
37 | else: |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
38 | return ', '.join( |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
39 | 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
|
40 | 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
|
41 | ) |
24 | 42 | |
43 | def check_scaling(scaling, axes): | |
44 | ''' Returns whether all given axes on the given scaling vector are 1. ''' | |
45 | return all( | |
46 | abs(getattr(scaling, axis) - 1) < 1e-5 | |
47 | for axis in axes | |
48 | ) | |
49 | ||
50 | # Restriction to checking function mapping. | |
51 | restriction_tests = { | |
52 | 'no scaling': lambda scaling: check_scaling(scaling, 'xyz'), | |
53 | 'y-scaling only': lambda scaling: check_scaling(scaling, 'xz'), | |
54 | 'stud3-like scaling': lambda scaling: all([ | |
55 | check_scaling(scaling, 'xz'), | |
56 | # check if y-scaling is 1 or -1 | |
57 | abs(abs(scaling.y) - 1) < 1e-5, | |
58 | ]), | |
59 | } | |
60 | ||
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
61 | @problem_type('illegal-scaling', |
64
1c0884f5506e
changed severity names to be better understood
Teemu Piippo <teemu@hecknology.net>
parents:
62
diff
changeset
|
62 | severity = 'hold', |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
63 | 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
|
64 | 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
|
65 | primitive, |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
66 | 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
|
67 | ), |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
68 | ) |
24 | 69 | def scaling_legality_test(model): |
26
7c263b864371
Added command line option to list all checks.
Santeri Piippo
parents:
24
diff
changeset
|
70 | ''' |
7c263b864371
Added command line option to list all checks.
Santeri Piippo
parents:
24
diff
changeset
|
71 | 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
|
72 | 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
|
73 | 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
|
74 | in the Y direction either. |
7c263b864371
Added command line option to list all checks.
Santeri Piippo
parents:
24
diff
changeset
|
75 | ''' |
24 | 76 | from fnmatch import fnmatch |
77 | scaling_restrictions = library_standards['scaling restrictions'] | |
78 | for subfile_reference in model.subfile_references: | |
79 | primitive = subfile_reference.subfile_path.lower() | |
80 | scaling = subfile_reference.matrix.scaling_vector() | |
81 | # Find all restrictions that apply to this subfile reference. | |
82 | restrictions = { | |
83 | restriction | |
84 | for pattern, restriction in scaling_restrictions.items() | |
85 | if fnmatch(primitive, pattern) | |
86 | } | |
87 | # Check restrictions against the subfile. If any restrictions were | |
88 | # found then the scaling vector must pass at least one of them. | |
89 | if restrictions and not any( | |
90 | restriction_tests[restriction](scaling) | |
91 | for restriction in restrictions | |
92 | ): | |
93 | interesting_axes = ''.join( | |
94 | axis | |
95 | for axis in 'xyz' | |
96 | if abs(getattr(scaling, axis) - 1) > 1e-5 | |
97 | ) | |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
98 | 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
|
99 | bad_object = subfile_reference, |
24 | 100 | primitive = primitive, |
101 | 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
|
102 | scaling = scaling, |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
103 | ) |
23 | 104 | |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
105 | @problem_type('cyclical-reference', |
64
1c0884f5506e
changed severity names to be better understood
Teemu Piippo <teemu@hecknology.net>
parents:
62
diff
changeset
|
106 | severity = 'hold', |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
107 | message = lambda chain: |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
108 | 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
|
109 | **locals(), |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
110 | ), |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
111 | ) |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
112 | @problem_type('bad-subfile', |
64
1c0884f5506e
changed severity names to be better understood
Teemu Piippo <teemu@hecknology.net>
parents:
62
diff
changeset
|
113 | severity = 'hold', |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
114 | 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
|
115 | 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
|
116 | **locals(), |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
117 | ), |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
118 | ) |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
119 | @problem_type('moved-file-used', |
64
1c0884f5506e
changed severity names to be better understood
Teemu Piippo <teemu@hecknology.net>
parents:
62
diff
changeset
|
120 | severity = 'hold', |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
121 | message = lambda moved_file, new_file: |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
122 | str.format('subfile "{moved_file}" has been moved to "{new_file}"', |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
123 | **locals(), |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
124 | ), |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
125 | ) |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
126 | @problem_type('unnecessary-scaling', |
64
1c0884f5506e
changed severity names to be better understood
Teemu Piippo <teemu@hecknology.net>
parents:
62
diff
changeset
|
127 | severity = 'warning', |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
128 | 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
|
129 | str.format( |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
130 | '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
|
131 | 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
|
132 | 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
|
133 | ), |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
134 | ) |
54
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
135 | 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
|
136 | ''' |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
137 | 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
|
138 | 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
|
139 | 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
|
140 | ''' |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
141 | import filecache |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
142 | 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
|
143 | failed_subfiles = set() |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
144 | for subfile_reference in model.subfile_references: |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
145 | 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
|
146 | 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
|
147 | # 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
|
148 | pass |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
149 | else: |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
150 | try: |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
151 | 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
|
152 | 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
|
153 | 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
|
154 | yield report_problem( |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
155 | 'cyclical-reference', |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
156 | 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
|
157 | chain = str(e), |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
158 | ) |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
159 | 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
|
160 | yield report_problem( |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
161 | 'bad-subfile', |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
162 | 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
|
163 | path = path, |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
164 | 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
|
165 | ) |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
166 | failed_subfiles.add(path) |
55
388df1fa18a2
fixed handling of invalid subfiles
Teemu Piippo <teemu@hecknology.net>
parents:
54
diff
changeset
|
167 | else: |
388df1fa18a2
fixed handling of invalid subfiles
Teemu Piippo <teemu@hecknology.net>
parents:
54
diff
changeset
|
168 | import re |
388df1fa18a2
fixed handling of invalid subfiles
Teemu Piippo <teemu@hecknology.net>
parents:
54
diff
changeset
|
169 | match = re.search(r'^\~Moved(?: to (\w+))?$', subfile.description) |
388df1fa18a2
fixed handling of invalid subfiles
Teemu Piippo <teemu@hecknology.net>
parents:
54
diff
changeset
|
170 | if match: |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
171 | yield report_problem( |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
172 | 'moved-file-used', |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
173 | bad_object = subfile_reference, |
55
388df1fa18a2
fixed handling of invalid subfiles
Teemu Piippo <teemu@hecknology.net>
parents:
54
diff
changeset
|
174 | 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
|
175 | 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
|
176 | ) |
55
388df1fa18a2
fixed handling of invalid subfiles
Teemu Piippo <teemu@hecknology.net>
parents:
54
diff
changeset
|
177 | scaling_vector = subfile_reference.matrix.scaling_vector() |
388df1fa18a2
fixed handling of invalid subfiles
Teemu Piippo <teemu@hecknology.net>
parents:
54
diff
changeset
|
178 | scaled_dimensions = { |
388df1fa18a2
fixed handling of invalid subfiles
Teemu Piippo <teemu@hecknology.net>
parents:
54
diff
changeset
|
179 | dimension |
388df1fa18a2
fixed handling of invalid subfiles
Teemu Piippo <teemu@hecknology.net>
parents:
54
diff
changeset
|
180 | for dimension in subfile.flatness |
388df1fa18a2
fixed handling of invalid subfiles
Teemu Piippo <teemu@hecknology.net>
parents:
54
diff
changeset
|
181 | if not math.isclose( |
388df1fa18a2
fixed handling of invalid subfiles
Teemu Piippo <teemu@hecknology.net>
parents:
54
diff
changeset
|
182 | getattr(scaling_vector, dimension), |
388df1fa18a2
fixed handling of invalid subfiles
Teemu Piippo <teemu@hecknology.net>
parents:
54
diff
changeset
|
183 | 1, |
388df1fa18a2
fixed handling of invalid subfiles
Teemu Piippo <teemu@hecknology.net>
parents:
54
diff
changeset
|
184 | abs_tol = 1.0e-05 |
388df1fa18a2
fixed handling of invalid subfiles
Teemu Piippo <teemu@hecknology.net>
parents:
54
diff
changeset
|
185 | ) |
388df1fa18a2
fixed handling of invalid subfiles
Teemu Piippo <teemu@hecknology.net>
parents:
54
diff
changeset
|
186 | } |
388df1fa18a2
fixed handling of invalid subfiles
Teemu Piippo <teemu@hecknology.net>
parents:
54
diff
changeset
|
187 | scaled_flat_dimensions = subfile.flatness & scaled_dimensions |
388df1fa18a2
fixed handling of invalid subfiles
Teemu Piippo <teemu@hecknology.net>
parents:
54
diff
changeset
|
188 | 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
|
189 | yield report_problem( |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
190 | 'unnecessary-scaling', |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
191 | bad_object = subfile_reference, |
55
388df1fa18a2
fixed handling of invalid subfiles
Teemu Piippo <teemu@hecknology.net>
parents:
54
diff
changeset
|
192 | scaled_flat_dimensions = scaled_flat_dimensions, |
388df1fa18a2
fixed handling of invalid subfiles
Teemu Piippo <teemu@hecknology.net>
parents:
54
diff
changeset
|
193 | scaling_vector = scaling_vector, |
388df1fa18a2
fixed handling of invalid subfiles
Teemu Piippo <teemu@hecknology.net>
parents:
54
diff
changeset
|
194 | ) |
54
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
195 | |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
196 | 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
|
197 | 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
|
198 | return dimensions |
54
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
199 | else: |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
200 | 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
|
201 | 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
|
202 | 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
|
203 | else: |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
204 | 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
|
205 | ', '.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
|
206 | sorted_dims[-1], |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
207 | ) |
54
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
208 | |
23 | 209 | manifest = { |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
210 | 'tests': [ |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
211 | determinant_test, |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
212 | scaling_legality_test, |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
213 | dependent_subfile_tests, |
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
214 | ], |
23 | 215 | } |