Runs incremental mode on all `commits` to verify the output matches the expected output. This function runs mypy on the `target_file_path` inside the `temp_repo_path`. The expected output must be stored inside of the given `cache`.
(
commits: list[tuple[str, str]],
cache: JsonDict,
temp_repo_path: str,
target_file_path: str | None,
mypy_cache_path: str,
*,
mypy_script: str | None = None,
daemon: bool = False,
exit_on_error: bool = False,
)
| 242 | |
| 243 | |
| 244 | def test_incremental( |
| 245 | commits: list[tuple[str, str]], |
| 246 | cache: JsonDict, |
| 247 | temp_repo_path: str, |
| 248 | target_file_path: str | None, |
| 249 | mypy_cache_path: str, |
| 250 | *, |
| 251 | mypy_script: str | None = None, |
| 252 | daemon: bool = False, |
| 253 | exit_on_error: bool = False, |
| 254 | ) -> None: |
| 255 | """Runs incremental mode on all `commits` to verify the output matches the expected output. |
| 256 | |
| 257 | This function runs mypy on the `target_file_path` inside the `temp_repo_path`. The |
| 258 | expected output must be stored inside of the given `cache`. |
| 259 | """ |
| 260 | print("Note: first commit is evaluated twice to warm up cache") |
| 261 | commits = [commits[0]] + commits |
| 262 | overall_stats: dict[str, float] = {} |
| 263 | for commit_id, message in commits: |
| 264 | print(f'Now testing commit {commit_id}: "{message}"') |
| 265 | execute(["git", "-C", temp_repo_path, "checkout", commit_id]) |
| 266 | runtime, output, stats = run_mypy( |
| 267 | target_file_path, mypy_cache_path, mypy_script, incremental=True, daemon=daemon |
| 268 | ) |
| 269 | relevant_stats = combine_stats(overall_stats, stats) |
| 270 | expected_runtime: float = cache[commit_id]["runtime"] |
| 271 | expected_output: str = cache[commit_id]["output"] |
| 272 | if output != expected_output: |
| 273 | print(" Output does not match expected result!") |
| 274 | print(f" Expected output ({expected_runtime:.3f} sec):") |
| 275 | print_offset(expected_output, 8) |
| 276 | print(f" Actual output: ({runtime:.3f} sec):") |
| 277 | print_offset(output, 8) |
| 278 | if exit_on_error: |
| 279 | break |
| 280 | else: |
| 281 | print(" Output matches expected result!") |
| 282 | print(f" Incremental: {runtime:.3f} sec") |
| 283 | print(f" Original: {expected_runtime:.3f} sec") |
| 284 | if relevant_stats: |
| 285 | print(f" Stats: {relevant_stats}") |
| 286 | if overall_stats: |
| 287 | print("Overall stats:", overall_stats) |
| 288 | |
| 289 | |
| 290 | def combine_stats(overall_stats: dict[str, float], new_stats: dict[str, Any]) -> dict[str, float]: |
no test coverage detected
searching dependent graphs…