tests/subfiles.py

Sun, 23 Jun 2019 12:09:20 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Sun, 23 Jun 2019 12:09:20 +0300
changeset 77
d98502ae1f33
parent 64
1c0884f5506e
child 79
eb93feb6d3a3
permissions
-rw-r--r--

improved header extent scanning

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
f8080ffceaa9 added test for forbidden primitive scaling
Santeri Piippo
parents: 23
diff changeset
3 from geometry import *
f8080ffceaa9 added test for forbidden primitive scaling
Santeri Piippo
parents: 23
diff changeset
4 from os.path import dirname
f8080ffceaa9 added test for forbidden primitive scaling
Santeri Piippo
parents: 23
diff changeset
5 from pathlib import Path
f8080ffceaa9 added test for forbidden primitive scaling
Santeri Piippo
parents: 23
diff changeset
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
f8080ffceaa9 added test for forbidden primitive scaling
Santeri Piippo
parents: 23
diff changeset
8 ini_path = Path(dirname(__file__)) / 'library-standards.ini'
f8080ffceaa9 added test for forbidden primitive scaling
Santeri Piippo
parents: 23
diff changeset
9 library_standards = ConfigParser()
f8080ffceaa9 added test for forbidden primitive scaling
Santeri Piippo
parents: 23
diff changeset
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
f8080ffceaa9 added test for forbidden primitive scaling
Santeri Piippo
parents: 23
diff changeset
12 library_standards.read_file(file)
23
1b9645b7ddb0 added matrix all zero test
Santeri Piippo
parents:
diff changeset
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
1b9645b7ddb0 added matrix all zero test
Santeri Piippo
parents:
diff changeset
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
f8080ffceaa9 added test for forbidden primitive scaling
Santeri Piippo
parents: 23
diff changeset
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
1b9645b7ddb0 added matrix all zero test
Santeri Piippo
parents:
diff changeset
25 for subfile_reference in model.subfile_references
1b9645b7ddb0 added matrix all zero test
Santeri Piippo
parents:
diff changeset
26 if abs(subfile_reference.matrix.determinant() - 0) < 1e-15
24
f8080ffceaa9 added test for forbidden primitive scaling
Santeri Piippo
parents: 23
diff changeset
27 )
f8080ffceaa9 added test for forbidden primitive scaling
Santeri Piippo
parents: 23
diff changeset
28
f8080ffceaa9 added test for forbidden primitive scaling
Santeri Piippo
parents: 23
diff changeset
29 def scaling_description(scaling, axes = 'xyz'):
f8080ffceaa9 added test for forbidden primitive scaling
Santeri Piippo
parents: 23
diff changeset
30 '''
f8080ffceaa9 added test for forbidden primitive scaling
Santeri Piippo
parents: 23
diff changeset
31 Returns a pretty description of a scaling vector. The axes parameter
f8080ffceaa9 added test for forbidden primitive scaling
Santeri Piippo
parents: 23
diff changeset
32 controls what axes are printed and can be used to filter away
f8080ffceaa9 added test for forbidden primitive scaling
Santeri Piippo
parents: 23
diff changeset
33 uninteresting values.
f8080ffceaa9 added test for forbidden primitive scaling
Santeri Piippo
parents: 23
diff changeset
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
f8080ffceaa9 added test for forbidden primitive scaling
Santeri Piippo
parents: 23
diff changeset
42
f8080ffceaa9 added test for forbidden primitive scaling
Santeri Piippo
parents: 23
diff changeset
43 def check_scaling(scaling, axes):
f8080ffceaa9 added test for forbidden primitive scaling
Santeri Piippo
parents: 23
diff changeset
44 ''' Returns whether all given axes on the given scaling vector are 1. '''
f8080ffceaa9 added test for forbidden primitive scaling
Santeri Piippo
parents: 23
diff changeset
45 return all(
f8080ffceaa9 added test for forbidden primitive scaling
Santeri Piippo
parents: 23
diff changeset
46 abs(getattr(scaling, axis) - 1) < 1e-5
f8080ffceaa9 added test for forbidden primitive scaling
Santeri Piippo
parents: 23
diff changeset
47 for axis in axes
f8080ffceaa9 added test for forbidden primitive scaling
Santeri Piippo
parents: 23
diff changeset
48 )
f8080ffceaa9 added test for forbidden primitive scaling
Santeri Piippo
parents: 23
diff changeset
49
f8080ffceaa9 added test for forbidden primitive scaling
Santeri Piippo
parents: 23
diff changeset
50 # Restriction to checking function mapping.
f8080ffceaa9 added test for forbidden primitive scaling
Santeri Piippo
parents: 23
diff changeset
51 restriction_tests = {
f8080ffceaa9 added test for forbidden primitive scaling
Santeri Piippo
parents: 23
diff changeset
52 'no scaling': lambda scaling: check_scaling(scaling, 'xyz'),
f8080ffceaa9 added test for forbidden primitive scaling
Santeri Piippo
parents: 23
diff changeset
53 'y-scaling only': lambda scaling: check_scaling(scaling, 'xz'),
f8080ffceaa9 added test for forbidden primitive scaling
Santeri Piippo
parents: 23
diff changeset
54 'stud3-like scaling': lambda scaling: all([
f8080ffceaa9 added test for forbidden primitive scaling
Santeri Piippo
parents: 23
diff changeset
55 check_scaling(scaling, 'xz'),
f8080ffceaa9 added test for forbidden primitive scaling
Santeri Piippo
parents: 23
diff changeset
56 # check if y-scaling is 1 or -1
f8080ffceaa9 added test for forbidden primitive scaling
Santeri Piippo
parents: 23
diff changeset
57 abs(abs(scaling.y) - 1) < 1e-5,
f8080ffceaa9 added test for forbidden primitive scaling
Santeri Piippo
parents: 23
diff changeset
58 ]),
f8080ffceaa9 added test for forbidden primitive scaling
Santeri Piippo
parents: 23
diff changeset
59 }
f8080ffceaa9 added test for forbidden primitive scaling
Santeri Piippo
parents: 23
diff changeset
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
f8080ffceaa9 added test for forbidden primitive scaling
Santeri Piippo
parents: 23
diff changeset
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
f8080ffceaa9 added test for forbidden primitive scaling
Santeri Piippo
parents: 23
diff changeset
76 from fnmatch import fnmatch
f8080ffceaa9 added test for forbidden primitive scaling
Santeri Piippo
parents: 23
diff changeset
77 scaling_restrictions = library_standards['scaling restrictions']
f8080ffceaa9 added test for forbidden primitive scaling
Santeri Piippo
parents: 23
diff changeset
78 for subfile_reference in model.subfile_references:
f8080ffceaa9 added test for forbidden primitive scaling
Santeri Piippo
parents: 23
diff changeset
79 primitive = subfile_reference.subfile_path.lower()
f8080ffceaa9 added test for forbidden primitive scaling
Santeri Piippo
parents: 23
diff changeset
80 scaling = subfile_reference.matrix.scaling_vector()
f8080ffceaa9 added test for forbidden primitive scaling
Santeri Piippo
parents: 23
diff changeset
81 # Find all restrictions that apply to this subfile reference.
f8080ffceaa9 added test for forbidden primitive scaling
Santeri Piippo
parents: 23
diff changeset
82 restrictions = {
f8080ffceaa9 added test for forbidden primitive scaling
Santeri Piippo
parents: 23
diff changeset
83 restriction
f8080ffceaa9 added test for forbidden primitive scaling
Santeri Piippo
parents: 23
diff changeset
84 for pattern, restriction in scaling_restrictions.items()
f8080ffceaa9 added test for forbidden primitive scaling
Santeri Piippo
parents: 23
diff changeset
85 if fnmatch(primitive, pattern)
f8080ffceaa9 added test for forbidden primitive scaling
Santeri Piippo
parents: 23
diff changeset
86 }
f8080ffceaa9 added test for forbidden primitive scaling
Santeri Piippo
parents: 23
diff changeset
87 # Check restrictions against the subfile. If any restrictions were
f8080ffceaa9 added test for forbidden primitive scaling
Santeri Piippo
parents: 23
diff changeset
88 # found then the scaling vector must pass at least one of them.
f8080ffceaa9 added test for forbidden primitive scaling
Santeri Piippo
parents: 23
diff changeset
89 if restrictions and not any(
f8080ffceaa9 added test for forbidden primitive scaling
Santeri Piippo
parents: 23
diff changeset
90 restriction_tests[restriction](scaling)
f8080ffceaa9 added test for forbidden primitive scaling
Santeri Piippo
parents: 23
diff changeset
91 for restriction in restrictions
f8080ffceaa9 added test for forbidden primitive scaling
Santeri Piippo
parents: 23
diff changeset
92 ):
f8080ffceaa9 added test for forbidden primitive scaling
Santeri Piippo
parents: 23
diff changeset
93 interesting_axes = ''.join(
f8080ffceaa9 added test for forbidden primitive scaling
Santeri Piippo
parents: 23
diff changeset
94 axis
f8080ffceaa9 added test for forbidden primitive scaling
Santeri Piippo
parents: 23
diff changeset
95 for axis in 'xyz'
f8080ffceaa9 added test for forbidden primitive scaling
Santeri Piippo
parents: 23
diff changeset
96 if abs(getattr(scaling, axis) - 1) > 1e-5
f8080ffceaa9 added test for forbidden primitive scaling
Santeri Piippo
parents: 23
diff changeset
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
f8080ffceaa9 added test for forbidden primitive scaling
Santeri Piippo
parents: 23
diff changeset
100 primitive = primitive,
f8080ffceaa9 added test for forbidden primitive scaling
Santeri Piippo
parents: 23
diff changeset
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
1b9645b7ddb0 added matrix all zero test
Santeri Piippo
parents:
diff changeset
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
1b9645b7ddb0 added matrix all zero test
Santeri Piippo
parents:
diff changeset
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
1b9645b7ddb0 added matrix all zero test
Santeri Piippo
parents:
diff changeset
215 }

mercurial