tests/subfiles.py

changeset 95
a3536e51f6bc
parent 92
b8d72909d593
child 104
1ad664f783d6
equal deleted inserted replaced
94:109fb7cf658f 95:a3536e51f6bc
161 actual contents of the subfiles. Checks whether moved-to files are used. 161 actual contents of the subfiles. Checks whether moved-to files are used.
162 Checks whether flat subfiles are scaled in the flat direction. 162 Checks whether flat subfiles are scaled in the flat direction.
163 ''' 163 '''
164 import filecache 164 import filecache
165 cache = filecache.SubfileCache(model.ldraw_directories) 165 cache = filecache.SubfileCache(model.ldraw_directories)
166 if model.header.valid:
167 cache.reference_stack.append(model.header.name)
166 failed_subfiles = set() 168 failed_subfiles = set()
167 for subfile_reference, has_invertnext in subfile_references_with_invertnext(model): 169 for subfile_reference, has_invertnext in subfile_references_with_invertnext(model):
168 path = subfile_reference.subfile_path.lower() 170 path = subfile_reference.subfile_path.lower()
169 if path in failed_subfiles: 171 if path in failed_subfiles:
170 # Already proven to be a bad apple, don't complain twice 172 # Already proven to be a bad apple, don't complain twice
171 pass 173 pass
172 else: 174 else:
173 try: 175 try:
174 subfile = cache.prepare_file(path) 176 subfile = cache.prepare_file(path)
175 except filecache.CyclicalReferenceError as e: 177 except filecache.CyclicalReferenceError as e:
178 subfile = None
176 failed_subfiles.add(path) 179 failed_subfiles.add(path)
177 yield report_problem( 180 yield report_problem(
178 'cyclical-reference', 181 'cyclical-reference',
179 bad_object = subfile_reference, 182 bad_object = subfile_reference,
180 chain = str(e), 183 chain = str(e),
181 ) 184 )
182 if not subfile.valid: 185 if subfile and not subfile.valid:
183 yield report_problem( 186 yield report_problem(
184 'bad-subfile', 187 'bad-subfile',
185 bad_object = subfile_reference, 188 bad_object = subfile_reference,
186 path = path, 189 path = path,
187 problem_text = subfile.problem, 190 problem_text = subfile.problem,
188 ) 191 )
189 failed_subfiles.add(path) 192 failed_subfiles.add(path)
190 else: 193 elif subfile:
191 # Test for use of moved-to files 194 # Test for use of moved-to files
192 import re 195 import re
193 match = re.search(r'^\~Moved(?: to (.+))?$', subfile.description) 196 match = re.search(r'^\~Moved(?: to (.+))?$', subfile.description)
194 if match: 197 if match:
195 yield report_problem( 198 yield report_problem(

mercurial