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

Function check_test_output_files

mypy/test/helpers.py:467–507  ·  view source on GitHub ↗
(
    testcase: DataDrivenTestCase, step: int, strip_prefix: str = ""
)

Source from the content-addressed store, hash-verified

465
466
467def check_test_output_files(
468 testcase: DataDrivenTestCase, step: int, strip_prefix: str = ""
469) -> None:
470 for path, expected_content in testcase.output_files:
471 path = path.removeprefix(strip_prefix)
472 if not os.path.exists(path):
473 raise AssertionError(
474 "Expected file {} was not produced by test case{}".format(
475 path, " on step %d" % step if testcase.output2 else ""
476 )
477 )
478 with open(path, encoding="utf8") as output_file:
479 actual_output_content = output_file.read()
480
481 if isinstance(expected_content, Pattern):
482 if expected_content.fullmatch(actual_output_content) is not None:
483 continue
484 raise AssertionError(
485 "Output file {} did not match its expected output pattern\n---\n{}\n---".format(
486 path, actual_output_content
487 )
488 )
489
490 normalized_output = normalize_file_output(
491 actual_output_content.splitlines(), os.path.abspath(test_temp_dir)
492 )
493 # We always normalize things like timestamp, but only handle operating-system
494 # specific things if requested.
495 if testcase.normalize_output:
496 if testcase.suite.native_sep and os.path.sep == "\\":
497 normalized_output = [fix_cobertura_filename(line) for line in normalized_output]
498 normalized_output = normalize_error_messages(normalized_output)
499 if os.path.basename(testcase.file) == "reports.test":
500 normalized_output = normalize_report_meta(normalized_output)
501 assert_string_arrays_equal(
502 expected_content.splitlines(),
503 normalized_output,
504 "Output file {} did not match its expected output{}".format(
505 path, " on step %d" % step if testcase.output2 else ""
506 ),
507 )
508
509
510def normalize_file_output(content: list[str], current_abs_path: str) -> list[str]:

Callers 2

run_case_onceMethod · 0.90
test_python_cmdlineFunction · 0.90

Calls 11

fix_cobertura_filenameFunction · 0.90
isinstanceFunction · 0.85
normalize_file_outputFunction · 0.85
normalize_error_messagesFunction · 0.85
normalize_report_metaFunction · 0.85
removeprefixMethod · 0.80
existsMethod · 0.80
splitlinesMethod · 0.80
formatMethod · 0.45
readMethod · 0.45

Tested by 2

run_case_onceMethod · 0.72
test_python_cmdlineFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…