MCPcopy
hub / github.com/numpy/numpy / run_mypy

Function run_mypy

numpy/typing/tests/test_typing.py:72–114  ·  view source on GitHub ↗

Clears the cache and run mypy before running any of the typing tests. The mypy results are cached in `OUTPUT_MYPY` for further use. The cache refresh can be skipped using NUMPY_TYPING_TEST_CLEAR_CACHE=0 pytest numpy/typing/tests

()

Source from the content-addressed store, hash-verified

70
71@pytest.fixture(scope="module", autouse=True)
72def run_mypy() -> None:
73 """Clears the cache and run mypy before running any of the typing tests.
74
75 The mypy results are cached in `OUTPUT_MYPY` for further use.
76
77 The cache refresh can be skipped using
78
79 NUMPY_TYPING_TEST_CLEAR_CACHE=0 pytest numpy/typing/tests
80 """
81 if (
82 os.path.isdir(CACHE_DIR)
83 and bool(os.environ.get("NUMPY_TYPING_TEST_CLEAR_CACHE", True))
84 ):
85 shutil.rmtree(CACHE_DIR)
86
87 split_pattern = re.compile(r"(\s+)?\^(\~+)?")
88 for directory in (PASS_DIR, REVEAL_DIR, FAIL_DIR, MISC_DIR):
89 # Run mypy
90 stdout, stderr, exit_code = api.run([
91 "--config-file",
92 MYPY_INI,
93 "--cache-dir",
94 CACHE_DIR,
95 directory,
96 ])
97 if stderr:
98 pytest.fail(f"Unexpected mypy standard error\n\n{stderr}", False)
99 elif exit_code not in {0, 1}:
100 pytest.fail(f"Unexpected mypy exit code: {exit_code}\n\n{stdout}", False)
101
102 str_concat = ""
103 filename: str | None = None
104 for i in stdout.split("\n"):
105 if "note:" in i:
106 continue
107 if filename is None:
108 filename = _key_func(i)
109
110 str_concat += f"{i}\n"
111 if split_pattern.match(i) is not None:
112 OUTPUT_MYPY[filename].append(str_concat)
113 str_concat = ""
114 filename = None
115
116
117def get_test_cases(*directories: str) -> list["ParameterSet"]:

Callers

nothing calls this directly

Calls 6

_key_funcFunction · 0.85
splitMethod · 0.80
getMethod · 0.45
compileMethod · 0.45
runMethod · 0.45
failMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…