Skip to content

Commit

Permalink
Add option to hide advice
Browse files Browse the repository at this point in the history
Useful for repos that have their lint scripts all under one command
  • Loading branch information
frankharkins committed Feb 27, 2024
1 parent 79616fa commit 33e24f8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
12 changes: 7 additions & 5 deletions squeaky/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def squeaky_cli():
"""
switches, filepaths = parse_args(sys.argv)
check = "--check" in switches
no_advice = "--no-advice" in switches

num_unclean = 0
for path in filepaths:
Expand All @@ -77,11 +78,12 @@ def squeaky_cli():
if num_unclean > 0:
print("━" * 35)
if check:
print(
f"Problems in {num_unclean} notebook"
f"{'s' if num_unclean != 1 else ''}; to fix, run"
"\n\n squeaky path/to/notebook.ipynb\n"
)
if not no_advice:
print(
f"Problems in {num_unclean} notebook"
f"{'s' if num_unclean != 1 else ''}; to fix, run"
"\n\n squeaky path/to/notebook.ipynb\n"
)
sys.exit(2)
print(f"Modified {num_unclean} notebook{'s' if num_unclean != 1 else ''}")
print("━" * 35)
Expand Down
14 changes: 14 additions & 0 deletions test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,20 @@ def test_command_modifies(self):
)
examples.reset()

@patch("sys.stdout", new_callable=StringIO)
@patch(
"sys.argv",
["squeaky", str(examples.dirty_tempfile_path), "--check", "--no-advice"],
)
def test_no_advice_flag_works(self, mock_stdout):
with self.assertRaises(SystemExit) as context:
squeaky_cli()
self.assertEqual(
mock_stdout.getvalue().strip().split("\n")[-1],
"━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━",
)
examples.reset()


if __name__ == "__main__":
unittest.main(buffer=True)
Expand Down

0 comments on commit 33e24f8

Please sign in to comment.