From dd68e951afc7c5205525e27021e33984fa25b580 Mon Sep 17 00:00:00 2001 From: Mikko Korpela Date: Sat, 30 Nov 2024 15:56:41 +0200 Subject: [PATCH] free order of args. --- src/pabot/arguments.py | 2 +- tests/test_pabot.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/pabot/arguments.py b/src/pabot/arguments.py index aca6ae07..0400214c 100644 --- a/src/pabot/arguments.py +++ b/src/pabot/arguments.py @@ -130,7 +130,7 @@ def _parse_pabot_args(args): # type: (List[str]) -> Tuple[List[str], Dict[str, i = end_index + 1 continue except ValueError: - raise DataError("--command requires --end-command") + raise DataError("--command requires matching --end-command") # Handle flag arguments if arg_name in flag_args: diff --git a/tests/test_pabot.py b/tests/test_pabot.py index ba8ccbbf..3033c2e0 100644 --- a/tests/test_pabot.py +++ b/tests/test_pabot.py @@ -1329,6 +1329,48 @@ def test_merge_one_run_with_and_without_legacyoutput(self): self.assertNotIn('schemaversion="4"', content) finally: shutil.rmtree(dtemp) + + def test_parse_args_mixed_order(self): + options, datasources, pabot_args, options_for_subprocesses = arguments.parse_args([ + "--legacyoutput", + "--processes", "12", + "--outputdir", "mydir", + "--verbose", + "--pabotlib", + "suite" + ]) + self.assertEqual(pabot_args["processes"], 12) + self.assertEqual(pabot_args["verbose"], True) + self.assertEqual(pabot_args["pabotlib"], True) + self.assertEqual(options["outputdir"], "mydir") + self.assertEqual(options["legacyoutput"], True) + self.assertEqual(datasources, ["suite"]) + + def test_parse_args_error_handling(self): + with self.assertRaises(DataError) as cm: + arguments.parse_args(["--processes"]) + self.assertIn("requires a value", str(cm.exception)) + + with self.assertRaises(DataError) as cm: + arguments.parse_args(["--processes", "invalid"]) + self.assertIn("Invalid value for --processes", str(cm.exception)) + + with self.assertRaises(DataError) as cm: + arguments.parse_args(["--command", "echo", "hello"]) + self.assertIn("requires matching --end-command", str(cm.exception)) + + def test_parse_args_command_with_pabot_args(self): + options, datasources, pabot_args, _ = arguments.parse_args([ + "--command", + "script.sh", + "--processes", + "5", + "--end-command", + "--verbose", + "suite" + ]) + self.assertEqual(pabot_args["command"], ["script.sh", "--processes", "5"]) + self.assertEqual(pabot_args["verbose"], True) if __name__ == "__main__":