Skip to content

Commit 824fa86

Browse files
committed
Precalculate testcase steps in setup
1 parent 0a83048 commit 824fa86

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

mypy/test/data.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,25 @@ def setup(self) -> None:
276276
with open(path, 'w', encoding='utf8') as f:
277277
f.write(content)
278278

279+
# Precalculate steps for find_steps()
280+
steps: Dict[int, List[FileOperation]] = {}
281+
for path, _ in self.files:
282+
m = re.match(r'.*\.([0-9]+)$', path)
283+
if m:
284+
num = int(m.group(1))
285+
assert num >= 2
286+
target_path = re.sub(r'\.[0-9]+$', '', path)
287+
module = module_from_path(target_path)
288+
operation = UpdateFile(module, path, target_path)
289+
steps.setdefault(num, []).append(operation)
290+
for num, paths in self.deleted_paths.items():
291+
assert num >= 2
292+
for path in paths:
293+
module = module_from_path(path)
294+
steps.setdefault(num, []).append(DeleteFile(module, path))
295+
max_step = max(steps) if steps else 2
296+
self.steps = [steps.get(num, []) for num in range(2, max_step + 1)]
297+
279298
def teardown(self) -> None:
280299
assert self.old_cwd is not None and self.tmpdir is not None, \
281300
"test was not properly set up"
@@ -312,23 +331,7 @@ def find_steps(self) -> List[List[FileOperation]]:
312331
313332
Defaults to having two steps if there aern't any operations.
314333
"""
315-
steps: Dict[int, List[FileOperation]] = {}
316-
for path, _ in self.files:
317-
m = re.match(r'.*\.([0-9]+)$', path)
318-
if m:
319-
num = int(m.group(1))
320-
assert num >= 2
321-
target_path = re.sub(r'\.[0-9]+$', '', path)
322-
module = module_from_path(target_path)
323-
operation = UpdateFile(module, path, target_path)
324-
steps.setdefault(num, []).append(operation)
325-
for num, paths in self.deleted_paths.items():
326-
assert num >= 2
327-
for path in paths:
328-
module = module_from_path(path)
329-
steps.setdefault(num, []).append(DeleteFile(module, path))
330-
max_step = max(steps) if steps else 2
331-
return [steps.get(num, []) for num in range(2, max_step + 1)]
334+
return self.steps
332335

333336

334337
def module_from_path(path: str) -> str:

0 commit comments

Comments
 (0)