MCPcopy
hub / github.com/psf/black / check_stability_and_equivalence

Function check_stability_and_equivalence

src/black/__init__.py:1075–1099  ·  view source on GitHub ↗

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]] = (),
)

Source from the content-addressed store, hash-verified

1073
1074
1075def 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
1102def format_file_contents(

Callers 2

format_file_contentsFunction · 0.85
format_cellFunction · 0.85

Calls 5

ASTSafetyErrorClass · 0.90
assert_equivalentFunction · 0.85
assert_stableFunction · 0.85

Tested by

no test coverage detected