MCPcopy Create free account
hub / github.com/numpy/numpy / run_mypy

Function run_mypy

numpy/typing/tests/test_typing.py:90–132  ·  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

88
89@pytest.fixture(scope="module", autouse=True)
90def run_mypy() -> None:
91 """Clears the cache and run mypy before running any of the typing tests.
92
93 The mypy results are cached in `OUTPUT_MYPY` for further use.
94
95 The cache refresh can be skipped using
96
97 NUMPY_TYPING_TEST_CLEAR_CACHE=0 pytest numpy/typing/tests
98 """
99 if (
100 os.path.isdir(CACHE_DIR)
101 and bool(os.environ.get("NUMPY_TYPING_TEST_CLEAR_CACHE", True))
102 ):
103 shutil.rmtree(CACHE_DIR)
104
105 split_pattern = re.compile(r"(\s+)?\^(\~+)?")
106 for directory in (PASS_DIR, REVEAL_DIR, FAIL_DIR, MISC_DIR):
107 # Run mypy
108 stdout, stderr, exit_code = api.run([
109 "--config-file",
110 MYPY_INI,
111 "--cache-dir",
112 CACHE_DIR,
113 directory,
114 ])
115 if stderr:
116 pytest.fail(f"Unexpected mypy standard error\n\n{stderr}")
117 elif exit_code not in {0, 1}:
118 pytest.fail(f"Unexpected mypy exit code: {exit_code}\n\n{stdout}")
119
120 str_concat = ""
121 filename: str | None = None
122 for i in stdout.split("\n"):
123 if "note:" in i:
124 continue
125 if filename is None:
126 filename = _key_func(i)
127
128 str_concat += f"{i}\n"
129 if split_pattern.match(i) is not None:
130 OUTPUT_MYPY[filename].append(str_concat)
131 str_concat = ""
132 filename = None
133
134
135def get_test_cases(directory: str) -> Iterator[ParameterSet]:

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected