Perform stability and equivalence checks. Raise AssertionError if source and destination contents are not equivalent, or if a second pass of the formatter would format the content differently.
(
src_contents: str,
dst_contents: str,
*,
mode: Mode,
lines: Collection[tuple[int, int]] = (),
)
| 1073 | |
| 1074 | |
| 1075 | def check_stability_and_equivalence( |
| 1076 | src_contents: str, |
| 1077 | dst_contents: str, |
| 1078 | *, |
| 1079 | mode: Mode, |
| 1080 | lines: Collection[tuple[int, int]] = (), |
| 1081 | ) -> None: |
| 1082 | """Perform stability and equivalence checks. |
| 1083 | |
| 1084 | Raise AssertionError if source and destination contents are not |
| 1085 | equivalent, or if a second pass of the formatter would format the |
| 1086 | content differently. |
| 1087 | """ |
| 1088 | try: |
| 1089 | assert_equivalent(src_contents, dst_contents) |
| 1090 | except SourceASTParseError: |
| 1091 | raise |
| 1092 | except ASTSafetyError: |
| 1093 | if _target_versions_exceed_runtime(mode.target_versions): |
| 1094 | raise ASTSafetyError( |
| 1095 | "failed to verify equivalence of the formatted output:" |
| 1096 | f" {_version_mismatch_message(mode.target_versions)}" |
| 1097 | ) from None |
| 1098 | raise |
| 1099 | assert_stable(src_contents, dst_contents, mode=mode, lines=lines) |
| 1100 | |
| 1101 | |
| 1102 | def format_file_contents( |
no test coverage detected