From 7d9899dbd12b989d643aeb7e9efdb0cdcb72cffa Mon Sep 17 00:00:00 2001 From: "Yann E. MORIN" Date: Mon, 23 Dec 2024 08:27:17 +0100 Subject: [PATCH] utils/get-developers: use parser.error() rather than canned print+return parser.error() reports a nice error message, that also displays a short reminder of the available options. Adapt the test-suite accordingly: previously, the error string was an exact string in the stdout list, while it now is a substring in one of the strings in stderr. The exit code changes, too. Signed-off-by: Yann E. MORIN Cc: Julien Olivain Signed-off-by: Julien Olivain (cherry picked from commit 35f381b93e52895179569876b23a509c9a7e0225) Signed-off-by: Peter Korsgaard --- support/testing/tests/utils/test_get_developers.py | 12 ++++++------ utils/get-developers | 6 ++---- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/support/testing/tests/utils/test_get_developers.py b/support/testing/tests/utils/test_get_developers.py index ffc01f6ce7..3ec4edeadd 100644 --- a/support/testing/tests/utils/test_get_developers.py +++ b/support/testing/tests/utils/test_get_developers.py @@ -41,9 +41,9 @@ class TestGetDevelopers(unittest.TestCase): # no args, with syntax error in the file developers = b'text3\n' out, err, rc = call_get_developers("./utils/get-developers", [], self.WITH_EMPTY_PATH, topdir, developers) - self.assertIn("No action specified", out) - self.assertEqual(rc, 0) - self.assertEqual(len(err), 0) + self.assertIn("No action specified", "\n".join(err)) + self.assertEqual(rc, 2) + self.assertEqual(len(out), 0) # -v generating error, called from the main dir developers = b'text1\n' @@ -150,9 +150,9 @@ class TestGetDevelopers(unittest.TestCase): # no args, with syntax error in the file developers = b'text3\n' out, err, rc = call_get_developers("./utils/get-developers", [], self.WITH_EMPTY_PATH, topdir, developers) - self.assertIn("No action specified", out) - self.assertEqual(rc, 0) - self.assertEqual(len(err), 0) + self.assertIn("No action specified", "\n".join(err)) + self.assertEqual(rc, 2) + self.assertEqual(len(out), 0) # patchfile from topdir and from elsewhere abs_path = infra.filepath("tests/utils/test_get_developers/") diff --git a/utils/get-developers b/utils/get-developers index 33980366d6..8e5796beaf 100755 --- a/utils/get-developers +++ b/utils/get-developers @@ -40,11 +40,9 @@ def __main__(): if len(args.patches) != 0: action += 1 if action > 1: - print("Cannot do more than one action") - return + parser.error("Cannot do more than one action") if action == 0: - print("No action specified") - return + parser.error("No action specified") devs = getdeveloperlib.parse_developers(args.filename) if devs is None: