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

Method test_expression_diff

tests/test_black.py:294–318  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

292 black.assert_stable(source, actual, DEFAULT_MODE)
293
294 def test_expression_diff(self) -> None:
295 source, _ = read_data("cases", "expression.py")
296 expected, _ = read_data("cases", "expression.diff")
297 tmp_file = Path(black.dump_to_file(source))
298 diff_header = re.compile(
299 rf"{re.escape(str(tmp_file))}\t\d\d\d\d-\d\d-\d\d "
300 r"\d\d:\d\d:\d\d\.\d\d\d\d\d\d\+\d\d:\d\d"
301 )
302 try:
303 result = BlackRunner().invoke(
304 black.main, ["--diff", str(tmp_file), f"--config={EMPTY_CONFIG}"]
305 )
306 self.assertEqual(result.exit_code, 0)
307 finally:
308 os.unlink(tmp_file)
309 actual = result.stdout
310 actual = diff_header.sub(DETERMINISTIC_HEADER, actual)
311 if expected != actual:
312 dump = black.dump_to_file(actual)
313 msg = (
314 "Expected diff isn't equal to the actual. If you made changes to"
315 " expression.py and this is an anticipated difference, overwrite"
316 f" tests/data/cases/expression.diff with {dump}"
317 )
318 self.assertEqual(expected, actual, msg)
319
320 def test_expression_diff_with_color(self) -> None:
321 source, _ = read_data("cases", "expression.py")

Callers

nothing calls this directly

Calls 2

read_dataFunction · 0.90
BlackRunnerClass · 0.85

Tested by

no test coverage detected