From a6312198e548b43a536e8202751b030ef701529d Mon Sep 17 00:00:00 2001 From: Renato Alves Date: Fri, 3 Jul 2015 22:30:24 +0100 Subject: [PATCH] Test: t.runError can now also be called by passing a single string to be split --- test/basetest/task.py | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/test/basetest/task.py b/test/basetest/task.py index c5db7a9c9..df73d699b 100644 --- a/test/basetest/task.py +++ b/test/basetest/task.py @@ -157,6 +157,25 @@ class Task(object): return json.loads(out) + @staticmethod + def _split_string_args_if_string(args): + """Helper function to parse and split into arguments a single string + argument. The string is literally the same as if written in the shell. + """ + # Enable nicer-looking calls by allowing plain strings + try: + # Python 2.x + if isinstance(args, basestring): + import shlex + args = shlex.split(args) + except NameError: + # Python 3.x + if isinstance(args, str): + import shlex + args = shlex.split(args) + + return args + def runSuccess(self, args=(), input=None, merge_streams=False, timeout=5): """Invoke task with given arguments and fail if exit code != 0 @@ -179,18 +198,7 @@ class Task(object): # Create a copy of the command command = self._command[:] - # Enable nicer-looking calls by allowing plain strings - try: - # Python 2.x - if isinstance(args, basestring): - import shlex - args = shlex.split(args) - except NameError: - # Python 3.x - if isinstance(args, str): - import shlex - args = shlex.split(args) - + args = self._split_string_args_if_string(args) command.extend(args) output = run_cmd_wait_nofail(command, input, @@ -223,6 +231,8 @@ class Task(object): """ # Create a copy of the command command = self._command[:] + + args = self._split_string_args_if_string(args) command.extend(args) output = run_cmd_wait_nofail(command, input,