From 20193073f84383ff6ede5a1596a40b4c1155bd8f Mon Sep 17 00:00:00 2001 From: Devon Loehr Date: Tue, 4 Mar 2025 11:47:49 -0800 Subject: [PATCH] [git cl split] Make Emit and EmitWarning variadic This better matches the print function which they replace, and prevents errors from passing the wrong number of arguments. We also change printing in one function to be more user-friendly. Bug: 389069356 Change-Id: Ia41d256b441bffa063f5d0b5ab4eb20725aaeaf4 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6322690 Reviewed-by: Josip Sokcevic Commit-Queue: Devon Loehr --- split_cl.py | 13 ++++++++----- tests/split_cl_test.py | 3 ++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/split_cl.py b/split_cl.py index 23aafb6e2..a94fa36d5 100644 --- a/split_cl.py +++ b/split_cl.py @@ -30,12 +30,13 @@ CL_SPLIT_FORCE_LIMIT = 10 CL_SPLIT_TOP_REVIEWERS = 5 -def Emit(msg: str): +def Emit(*msg: str): """Wrapper for easier mocking during tests""" - print(msg) + print(*msg) -def EmitWarning(msg: str): - print("Warning: ", msg) + +def EmitWarning(*msg: str): + print("Warning: ", *msg) def HashList(lst: List[Any]) -> str: @@ -736,7 +737,9 @@ def ValidateSplitting(cl_infos: List[CLInfo], filename: str, if (unmentioned_files): EmitWarning( "the following files are not included in any CL in {filename}. " - "They will not be uploaded:\n", unmentioned_files) + "They will not be uploaded:") + for file in unmentioned_files: + Emit(file) def LoadSplittingFromFile(filename: str, diff --git a/tests/split_cl_test.py b/tests/split_cl_test.py index 24af2c744..602e7a1d1 100755 --- a/tests/split_cl_test.py +++ b/tests/split_cl_test.py @@ -488,7 +488,8 @@ class SplitClTest(unittest.TestCase): split_cl.ParseSplittings, lines) @mock.patch("split_cl.EmitWarning") - def testValidateBadFiles(self, mock_emit_warning): + @mock.patch("split_cl.Emit") + def testValidateBadFiles(self, _, mock_emit_warning): """ Make sure we reject invalid CL lists """ # Warn on an empty file split_cl.LoadSplittingFromFile(