except re.error:
err(f"Invalid regular expression for exclude given: {exclude!r}")
ctx.exit(2)
- report = Report(check=check, quiet=quiet, verbose=verbose)
+ report = Report(check=check, diff=diff, quiet=quiet, verbose=verbose)
root = find_project_root(src)
sources: Set[Path] = set()
path_empty(src, quiet, verbose, ctx)
"""Provides a reformatting counter. Can be rendered with `str(report)`."""
check: bool = False
+ diff: bool = False
quiet: bool = False
verbose: bool = False
change_count: int = 0
def done(self, src: Path, changed: Changed) -> None:
"""Increment the counter for successful reformatting. Write out a message."""
if changed is Changed.YES:
- reformatted = "would reformat" if self.check else "reformatted"
+ reformatted = "would reformat" if self.check or self.diff else "reformatted"
if self.verbose or not self.quiet:
out(f"{reformatted} {src}")
self.change_count += 1
Use `click.unstyle` to remove colors.
"""
- if self.check:
+ if self.check or self.diff:
reformatted = "would be reformatted"
unchanged = "would be left unchanged"
failed = "would fail to reformat"
"2 files would be reformatted, 3 files would be left unchanged, "
"2 files would fail to reformat.",
)
+ report.check = False
+ report.diff = True
+ self.assertEqual(
+ unstyle(str(report)),
+ "2 files would be reformatted, 3 files would be left unchanged, "
+ "2 files would fail to reformat.",
+ )
def test_report_quiet(self) -> None:
report = black.Report(quiet=True)
"2 files would be reformatted, 3 files would be left unchanged, "
"2 files would fail to reformat.",
)
+ report.check = False
+ report.diff = True
+ self.assertEqual(
+ unstyle(str(report)),
+ "2 files would be reformatted, 3 files would be left unchanged, "
+ "2 files would fail to reformat.",
+ )
def test_report_normal(self) -> None:
report = black.Report()
"2 files would be reformatted, 3 files would be left unchanged, "
"2 files would fail to reformat.",
)
+ report.check = False
+ report.diff = True
+ self.assertEqual(
+ unstyle(str(report)),
+ "2 files would be reformatted, 3 files would be left unchanged, "
+ "2 files would fail to reformat.",
+ )
def test_lib2to3_parse(self) -> None:
with self.assertRaises(black.InvalidInput):