Skip to content

Commit

Permalink
Make --verbose output on a single line (#272):
Browse files Browse the repository at this point in the history
  • Loading branch information
dosisod authored Jul 25, 2023
1 parent 19a4f23 commit bda97d7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
9 changes: 6 additions & 3 deletions refurb/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,12 @@ def load_checks(settings: Settings) -> defaultdict[type[Node], list[Check]]:
enabled_errors.add(str(ErrorCode.from_error(error)))

if settings.verbose:
print("Enabled checks:")
msg = (
", ".join(sorted(enabled_errors))
if enabled_errors
else "No checks enabled"
)

for code in sorted(enabled_errors):
print(code)
print(f"Enabled checks: {msg}\n")

return found
14 changes: 11 additions & 3 deletions test/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,14 +251,22 @@ def test_verbose_flag_prints_all_enabled_checks() -> None:
with patch("builtins.print") as p:
main(["test/data/err_100.py", "--verbose", "--enable-all"])

stdout = "\n".join(args[0][0] for args in p.call_args_list)

# Current number of checks at time of writing. This number doesn't need to
# be kept updated, it is only set to a known value to verify that it is
# doing what it should.
current_check_count = 76

assert p.call_count > current_check_count
for error_id in range(100, 100 + current_check_count):
assert f"FURB{error_id}" in stdout


def test_verbose_flag_prints_message_when_all_checks_disabled() -> None:
with patch("builtins.print") as p:
main(["test/data/err_100.py", "--verbose", "--disable-all"])

stdout = "\n".join(args[0][0] for args in p.call_args_list)

for error_id in range(100, 100 + current_check_count):
assert f"FURB{error_id}" in stdout
assert "FURB100" not in stdout
assert "No checks enabled" in stdout

0 comments on commit bda97d7

Please sign in to comment.