Skip to content

Commit

Permalink
Reformat black's own source after the formatting changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
yilei committed Aug 23, 2022
1 parent ada5513 commit 25f7e49
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 49 deletions.
6 changes: 4 additions & 2 deletions src/black/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,8 +498,10 @@ def main( # noqa: C901
user_level_config = str(find_user_pyproject_toml())
if config == user_level_config:
out(
"Using configuration from user-level config at "
f"'{user_level_config}'.",
(
"Using configuration from user-level config at "
f"'{user_level_config}'."
),
fg="blue",
)
elif config_source in (
Expand Down
6 changes: 4 additions & 2 deletions src/black/mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,10 @@ class Mode:
def __post_init__(self) -> None:
if self.experimental_string_processing:
warn(
"`experimental string processing` has been included in `preview`"
" and deprecated. Use `preview` instead.",
(
"`experimental string processing` has been included in `preview`"
" and deprecated. Use `preview` instead."
),
Deprecated,
)

Expand Down
8 changes: 5 additions & 3 deletions src/black/parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@
# Either our python version is too low, or we're on pypy
if sys.version_info < (3, 7) or (sys.version_info < (3, 8) and not _IS_PYPY):
print(
"The typed_ast package is required but not installed.\n"
"You can upgrade to Python 3.8+ or install typed_ast with\n"
"`python3 -m pip install typed-ast`.",
(
"The typed_ast package is required but not installed.\n"
"You can upgrade to Python 3.8+ or install typed_ast with\n"
"`python3 -m pip install typed-ast`."
),
file=sys.stderr,
)
sys.exit(1)
Expand Down
126 changes: 84 additions & 42 deletions tests/test_black.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,8 +466,10 @@ def err(msg: str, **kwargs: Any) -> None:
self.assertEqual(err_lines[-1], "error: cannot format e1: boom")
self.assertEqual(
unstyle(str(report)),
"1 file reformatted, 2 files left unchanged, 1 file failed to"
" reformat.",
(
"1 file reformatted, 2 files left unchanged, 1 file failed to"
" reformat."
),
)
self.assertEqual(report.return_code, 123)
report.done(Path("f3"), black.Changed.YES)
Expand All @@ -476,8 +478,10 @@ def err(msg: str, **kwargs: Any) -> None:
self.assertEqual(out_lines[-1], "reformatted f3")
self.assertEqual(
unstyle(str(report)),
"2 files reformatted, 2 files left unchanged, 1 file failed to"
" reformat.",
(
"2 files reformatted, 2 files left unchanged, 1 file failed to"
" reformat."
),
)
self.assertEqual(report.return_code, 123)
report.failed(Path("e2"), "boom")
Expand All @@ -486,8 +490,10 @@ def err(msg: str, **kwargs: Any) -> None:
self.assertEqual(err_lines[-1], "error: cannot format e2: boom")
self.assertEqual(
unstyle(str(report)),
"2 files reformatted, 2 files left unchanged, 2 files failed to"
" reformat.",
(
"2 files reformatted, 2 files left unchanged, 2 files failed to"
" reformat."
),
)
self.assertEqual(report.return_code, 123)
report.path_ignored(Path("wat"), "no match")
Expand All @@ -496,8 +502,10 @@ def err(msg: str, **kwargs: Any) -> None:
self.assertEqual(out_lines[-1], "wat ignored: no match")
self.assertEqual(
unstyle(str(report)),
"2 files reformatted, 2 files left unchanged, 2 files failed to"
" reformat.",
(
"2 files reformatted, 2 files left unchanged, 2 files failed to"
" reformat."
),
)
self.assertEqual(report.return_code, 123)
report.done(Path("f4"), black.Changed.NO)
Expand All @@ -506,22 +514,28 @@ def err(msg: str, **kwargs: Any) -> None:
self.assertEqual(out_lines[-1], "f4 already well formatted, good job.")
self.assertEqual(
unstyle(str(report)),
"2 files reformatted, 3 files left unchanged, 2 files failed to"
" reformat.",
(
"2 files reformatted, 3 files left unchanged, 2 files failed to"
" reformat."
),
)
self.assertEqual(report.return_code, 123)
report.check = True
self.assertEqual(
unstyle(str(report)),
"2 files would be reformatted, 3 files would be left unchanged, 2 files"
" 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.",
(
"2 files would be reformatted, 3 files would be left unchanged, 2"
" files would fail to reformat."
),
)

def test_report_quiet(self) -> None:
Expand Down Expand Up @@ -563,17 +577,21 @@ def err(msg: str, **kwargs: Any) -> None:
self.assertEqual(err_lines[-1], "error: cannot format e1: boom")
self.assertEqual(
unstyle(str(report)),
"1 file reformatted, 2 files left unchanged, 1 file failed to"
" reformat.",
(
"1 file reformatted, 2 files left unchanged, 1 file failed to"
" reformat."
),
)
self.assertEqual(report.return_code, 123)
report.done(Path("f3"), black.Changed.YES)
self.assertEqual(len(out_lines), 0)
self.assertEqual(len(err_lines), 1)
self.assertEqual(
unstyle(str(report)),
"2 files reformatted, 2 files left unchanged, 1 file failed to"
" reformat.",
(
"2 files reformatted, 2 files left unchanged, 1 file failed to"
" reformat."
),
)
self.assertEqual(report.return_code, 123)
report.failed(Path("e2"), "boom")
Expand All @@ -582,40 +600,50 @@ def err(msg: str, **kwargs: Any) -> None:
self.assertEqual(err_lines[-1], "error: cannot format e2: boom")
self.assertEqual(
unstyle(str(report)),
"2 files reformatted, 2 files left unchanged, 2 files failed to"
" reformat.",
(
"2 files reformatted, 2 files left unchanged, 2 files failed to"
" reformat."
),
)
self.assertEqual(report.return_code, 123)
report.path_ignored(Path("wat"), "no match")
self.assertEqual(len(out_lines), 0)
self.assertEqual(len(err_lines), 2)
self.assertEqual(
unstyle(str(report)),
"2 files reformatted, 2 files left unchanged, 2 files failed to"
" reformat.",
(
"2 files reformatted, 2 files left unchanged, 2 files failed to"
" reformat."
),
)
self.assertEqual(report.return_code, 123)
report.done(Path("f4"), black.Changed.NO)
self.assertEqual(len(out_lines), 0)
self.assertEqual(len(err_lines), 2)
self.assertEqual(
unstyle(str(report)),
"2 files reformatted, 3 files left unchanged, 2 files failed to"
" reformat.",
(
"2 files reformatted, 3 files left unchanged, 2 files failed to"
" reformat."
),
)
self.assertEqual(report.return_code, 123)
report.check = True
self.assertEqual(
unstyle(str(report)),
"2 files would be reformatted, 3 files would be left unchanged, 2 files"
" 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.",
(
"2 files would be reformatted, 3 files would be left unchanged, 2"
" files would fail to reformat."
),
)

def test_report_normal(self) -> None:
Expand Down Expand Up @@ -659,8 +687,10 @@ def err(msg: str, **kwargs: Any) -> None:
self.assertEqual(err_lines[-1], "error: cannot format e1: boom")
self.assertEqual(
unstyle(str(report)),
"1 file reformatted, 2 files left unchanged, 1 file failed to"
" reformat.",
(
"1 file reformatted, 2 files left unchanged, 1 file failed to"
" reformat."
),
)
self.assertEqual(report.return_code, 123)
report.done(Path("f3"), black.Changed.YES)
Expand All @@ -669,8 +699,10 @@ def err(msg: str, **kwargs: Any) -> None:
self.assertEqual(out_lines[-1], "reformatted f3")
self.assertEqual(
unstyle(str(report)),
"2 files reformatted, 2 files left unchanged, 1 file failed to"
" reformat.",
(
"2 files reformatted, 2 files left unchanged, 1 file failed to"
" reformat."
),
)
self.assertEqual(report.return_code, 123)
report.failed(Path("e2"), "boom")
Expand All @@ -679,40 +711,50 @@ def err(msg: str, **kwargs: Any) -> None:
self.assertEqual(err_lines[-1], "error: cannot format e2: boom")
self.assertEqual(
unstyle(str(report)),
"2 files reformatted, 2 files left unchanged, 2 files failed to"
" reformat.",
(
"2 files reformatted, 2 files left unchanged, 2 files failed to"
" reformat."
),
)
self.assertEqual(report.return_code, 123)
report.path_ignored(Path("wat"), "no match")
self.assertEqual(len(out_lines), 2)
self.assertEqual(len(err_lines), 2)
self.assertEqual(
unstyle(str(report)),
"2 files reformatted, 2 files left unchanged, 2 files failed to"
" reformat.",
(
"2 files reformatted, 2 files left unchanged, 2 files failed to"
" reformat."
),
)
self.assertEqual(report.return_code, 123)
report.done(Path("f4"), black.Changed.NO)
self.assertEqual(len(out_lines), 2)
self.assertEqual(len(err_lines), 2)
self.assertEqual(
unstyle(str(report)),
"2 files reformatted, 3 files left unchanged, 2 files failed to"
" reformat.",
(
"2 files reformatted, 3 files left unchanged, 2 files failed to"
" reformat."
),
)
self.assertEqual(report.return_code, 123)
report.check = True
self.assertEqual(
unstyle(str(report)),
"2 files would be reformatted, 3 files would be left unchanged, 2 files"
" 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.",
(
"2 files would be reformatted, 3 files would be left unchanged, 2"
" files would fail to reformat."
),
)

def test_lib2to3_parse(self) -> None:
Expand Down

0 comments on commit 25f7e49

Please sign in to comment.