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

Function test_repo

misc/incremental_checker.py:307–391  ·  view source on GitHub ↗

Tests incremental mode against the repo specified in `target_repo_url`. This algorithm runs in five main stages: 1. Clones `target_repo_url` into the `temp_repo_path` folder locally, checking out the specified `branch` if applicable. 2. Examines the repo's history to get the

(
    target_repo_url: str,
    temp_repo_path: str,
    target_file_path: str | None,
    mypy_path: str,
    incremental_cache_path: str,
    mypy_cache_path: str,
    range_type: str,
    range_start: str,
    branch: str,
    params: Namespace,
)

Source from the content-addressed store, hash-verified

305
306
307def test_repo(
308 target_repo_url: str,
309 temp_repo_path: str,
310 target_file_path: str | None,
311 mypy_path: str,
312 incremental_cache_path: str,
313 mypy_cache_path: str,
314 range_type: str,
315 range_start: str,
316 branch: str,
317 params: Namespace,
318) -> None:
319 """Tests incremental mode against the repo specified in `target_repo_url`.
320
321 This algorithm runs in five main stages:
322
323 1. Clones `target_repo_url` into the `temp_repo_path` folder locally,
324 checking out the specified `branch` if applicable.
325 2. Examines the repo's history to get the list of all commits to
326 to test incremental mode on.
327 3. Runs mypy WITHOUT incremental mode against the `target_file_path` (which is
328 assumed to be located inside the `temp_repo_path`), testing each commit
329 discovered in stage two.
330 - If the results of running mypy WITHOUT incremental mode on a
331 particular commit are already cached inside the `incremental_cache_path`,
332 skip that commit to save time.
333 - Cache the results after finishing.
334 4. Rewind back to the first commit, and run mypy WITH incremental mode
335 against the `target_file_path` commit-by-commit, and compare to the expected
336 results found in stage 3.
337 5. Delete all unnecessary temp files.
338 """
339 # Stage 1: Clone repo and get ready to being testing
340 ensure_environment_is_ready(mypy_path, temp_repo_path, mypy_cache_path)
341 initialize_repo(target_repo_url, temp_repo_path, branch)
342
343 # Stage 2: Get all commits we want to test
344 if range_type == "last":
345 start_commit = get_nth_commit(temp_repo_path, int(range_start))[0]
346 elif range_type == "commit":
347 start_commit = range_start
348 else:
349 raise RuntimeError(f"Invalid option: {range_type}")
350 commits = get_commits_starting_at(temp_repo_path, start_commit)
351 if params.limit:
352 commits = commits[: params.limit]
353 if params.sample:
354 seed = params.seed or base64.urlsafe_b64encode(os.urandom(15)).decode("ascii")
355 random.seed(seed)
356 commits = random.sample(commits, params.sample)
357 print("Sampled down to %d commits using random seed %s" % (len(commits), seed))
358
359 # Stage 3: Find and cache expected results for each commit (without incremental mode)
360 cache = load_cache(incremental_cache_path)
361 set_expected(
362 commits,
363 cache,
364 temp_repo_path,

Callers 1

mainFunction · 0.85

Calls 15

initialize_repoFunction · 0.85
get_nth_commitFunction · 0.85
intClass · 0.85
RuntimeErrorClass · 0.85
get_commits_starting_atFunction · 0.85
printFunction · 0.85
lenFunction · 0.85
load_cacheFunction · 0.85
set_expectedFunction · 0.85
save_cacheFunction · 0.85
start_daemonFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…