MCPcopy Index your code
hub / github.com/python/mypy / setup

Method setup

mypy/test/data.py:349–383  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

347 raise
348
349 def setup(self) -> None:
350 parse_test_case(case=self)
351 self.old_cwd = os.getcwd()
352 self.tmpdir = tempfile.mkdtemp(prefix="mypy-test-")
353 os.chdir(self.tmpdir)
354 os.mkdir(test_temp_dir)
355
356 # Precalculate steps for find_steps()
357 steps: dict[int, list[FileOperation]] = {}
358
359 for path, content in self.files:
360 m = re.match(r".*\.([0-9]+)$", path)
361 if m:
362 # Skip writing subsequent incremental steps - rather
363 # store them as operations.
364 num = int(m.group(1))
365 assert num >= 2
366 target_path = re.sub(r"\.[0-9]+$", "", path)
367 module = module_from_path(target_path)
368 operation = UpdateFile(module, content, target_path)
369 steps.setdefault(num, []).append(operation)
370 else:
371 # Write the first incremental steps
372 dir = os.path.dirname(path)
373 os.makedirs(dir, exist_ok=True)
374 with open(path, "w", encoding="utf8") as f:
375 f.write(content)
376
377 for num, paths in self.deleted_paths.items():
378 assert num >= 2
379 for path in paths:
380 module = module_from_path(path)
381 steps.setdefault(num, []).append(DeleteFile(module, path))
382 max_step = max(steps) if steps else 2
383 self.steps = [steps.get(num, []) for num in range(2, max_step + 1)]
384
385 def teardown(self) -> None:
386 if self.old_cwd is not None:

Callers

nothing calls this directly

Calls 13

parse_test_caseFunction · 0.85
intClass · 0.85
module_from_pathFunction · 0.85
UpdateFileClass · 0.85
DeleteFileClass · 0.85
maxFunction · 0.85
rangeClass · 0.85
groupMethod · 0.80
appendMethod · 0.80
setdefaultMethod · 0.80
writeMethod · 0.45
itemsMethod · 0.45

Tested by

no test coverage detected