From 136900c23540be7e6f074510b32955522b95c1ed Mon Sep 17 00:00:00 2001 From: Chris Doman Date: Mon, 4 Dec 2023 11:18:54 +0000 Subject: [PATCH] Add unit test for print --- cloudgrep/search.py | 2 +- tests/test_unit.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/cloudgrep/search.py b/cloudgrep/search.py index ac12e31..9a6e95e 100644 --- a/cloudgrep/search.py +++ b/cloudgrep/search.py @@ -153,7 +153,7 @@ def search_file( with open(os.path.join(tempdir, filename)) as f: for line in f: if self.search_line( - "{key_name}/{filename}", + f"{key_name}/{filename}", search, hide_filenames, line, diff --git a/tests/test_unit.py b/tests/test_unit.py index bfaada2..22c70d3 100644 --- a/tests/test_unit.py +++ b/tests/test_unit.py @@ -42,6 +42,15 @@ def test_zip(self) -> None: found = Search().search_file(f"{BASE_PATH}/data/000000.zip", "000000.zip", "Running on machine", False, None) self.assertTrue(found) + def test_print_match(self) -> None: + # Test output of print_match function + + with patch("sys.stdout", new=StringIO()) as fake_out: + Search().search_file(f"{BASE_PATH}/data/000000.zip", "000000.zip", "Running on machine", False, None) + output = fake_out.getvalue().strip() + + self.assertIn("Running on machine", output) + @timeout_decorator.timeout(5) # Normally takes around 3 seconds to run in github actions @mock_s3 def test_e2e(self) -> None: