Skip to content

Commit

Permalink
free order of args.
Browse files Browse the repository at this point in the history
  • Loading branch information
mkorpela committed Nov 30, 2024
1 parent c6d3342 commit dd68e95
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/pabot/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
42 changes: 42 additions & 0 deletions tests/test_pabot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__":
Expand Down

0 comments on commit dd68e95

Please sign in to comment.