(
testcase: DataDrivenTestCase, step: int, strip_prefix: str = ""
)
| 465 | |
| 466 | |
| 467 | def 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 | |
| 510 | def normalize_file_output(content: list[str], current_abs_path: str) -> list[str]: |
searching dependent graphs…