From 33e24f8eb633d25758c787c4efd5d645458c352f Mon Sep 17 00:00:00 2001 From: Frank Harkins Date: Tue, 27 Feb 2024 16:50:28 +0000 Subject: [PATCH] Add option to hide advice Useful for repos that have their lint scripts all under one command --- squeaky/__init__.py | 12 +++++++----- test/test.py | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/squeaky/__init__.py b/squeaky/__init__.py index ef51299..7d74e11 100644 --- a/squeaky/__init__.py +++ b/squeaky/__init__.py @@ -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: @@ -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) diff --git a/test/test.py b/test/test.py index 21b7678..a208c0d 100644 --- a/test/test.py +++ b/test/test.py @@ -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)