16 from itertools
import chain
18 from robot.errors import (BreakLoop, ContinueLoop, DataError, ExecutionFailed,
19 ExecutionPassed, ExecutionStatus, PassExecution,
20 ReturnFromKeyword, UserKeywordExecutionFailed, VariableError)
22 from robot.utils import DotDict, getshortdoc, prepr, split_tags_from_doc
25 from .arguments
import DefaultValue
26 from .bodyrunner
import BodyRunner, KeywordRunner
27 from .statusreporter
import StatusReporter
28 from .timeouts
import KeywordTimeout
35 self.
namename = name
or handler.name
42 libname = self.
_handler_handler.libname
43 return f
'{libname}.{self.name}' if libname
else self.
namename
68 return self.
_handler_handler.arguments
70 def run(self, kw, context, run=True):
71 assignment = VariableAssignment(kw.assign)
72 result = self.
_get_result_get_result(kw, assignment, context.variables)
75 context.warn_on_invalid_private_call(self.
_handler_handler)
76 with assignment.assigner(context)
as assigner:
78 return_value = self.
_run_run(context, kw.args, result)
79 assigner.assign(return_value)
84 doc = variables.replace_string(handler.doc, ignore_errors=
True)
86 tags = variables.replace_list(handler.tags, ignore_errors=
True) + tags
87 return KeywordResult(kwname=self.
namename,
88 libname=handler.libname,
91 assign=tuple(assignment),
95 def _run(self, context, args, result):
98 context.output.message(message)
99 variables = context.variables
101 with context.user_keyword(self.
_handler_handler):
104 if timeout
is not None:
105 result.timeout = str(timeout)
106 with context.timeout(timeout):
107 exception, return_ = self.
_execute_execute(context)
108 if exception
and not exception.can_continue(context):
112 exception.return_value = return_value
117 timeout = self.
_handler_handler.timeout
124 positional, named = arguments
125 variables = context.variables
127 replace_defaults=
False)
135 for name, value
in chain(zip(spec.positional, args), kwonly):
136 if isinstance(value, DefaultValue):
137 value = value.resolve(variables)
138 variables[
'${%s}' % name] = value
139 if spec.var_positional:
140 variables[
'@{%s}' % spec.var_positional] = varargs
142 variables[
'&{%s}' % spec.var_named] = DotDict(kwargs)
148 return args[:positional], args[positional:]
153 for name, value
in all_kwargs:
155 target.append((name, value))
156 return kwonly, kwargs
167 args = [
'%s=%s' % (name,
prepr(variables[name]))
for name
in args]
168 return 'Arguments: [ %s ]' %
' | '.join(args)
172 if not (handler.body
or handler.return_value):
173 raise DataError(
"User keyword '%s' contains no keywords." % self.
namename)
174 if context.dry_run
and handler.tags.robot(
'no-dry-run'):
176 error = return_ = pass_ =
None
179 except ReturnFromKeyword
as exception:
181 error = exception.earlier_failures
182 except (BreakLoop, ContinueLoop)
as exception:
184 except ExecutionPassed
as exception:
186 error = exception.earlier_failures
188 error.continue_on_failure =
False
189 except ExecutionFailed
as exception:
191 with context.keyword_teardown(error):
193 if error
or td_error:
195 return error
or pass_, return_
198 ret = self.
_handler_handler.return_value
if not return_
else return_.return_value
203 ret = variables.replace_list(ret)
204 except DataError
as err:
205 raise VariableError(
'Replacing variables from keyword return '
206 'value failed: %s' % err.message)
207 if len(ret) != 1
or contains_list_var:
212 if not self.
_handler_handler.teardown:
215 name = context.variables.replace_string(self.
_handler_handler.teardown.name)
216 except DataError
as err:
220 if name.upper()
in (
'',
'NONE'):
224 except PassExecution:
226 except ExecutionStatus
as err:
231 assignment = VariableAssignment(kw.assign)
232 result = self.
_get_result_get_result(kw, assignment, context.variables)
234 assignment.validate_assignment()
235 self.
_dry_run_dry_run(context, kw.args, result)
240 context.output.message(message)
242 with context.user_keyword(self.
_handler_handler):
245 result.timeout = str(timeout)
246 error, _ = self.
_execute_execute(context)
262 embedded = [variables.replace_scalar(e)
for e
in self.
embedded_argsembedded_args]
263 return self.
_handler_handler.embedded.map(embedded)
266 variables = context.variables
267 for name, value
in embedded_args:
268 variables[
'${%s}' % name] = value
272 args = [f
'${{{arg}}}' for arg
in self.
_handler_handler.embedded.args]
276 result = UserKeywordRunner._get_result(self, kw, assignment, variables)
277 result.sourcename = self.
_handler_handler.name
Used for communicating failures in test execution.
Used when variable does not exist.
def _resolve_arguments(self, args, variables=None)
def __init__(self, handler, name)
def _get_result(self, kw, assignment, variables)
def _set_arguments(self, embedded_args, context)
def _trace_log_args_message(self, variables)
def _get_result(self, kw, assignment, variables)
def _get_return_value(self, variables, return_)
def _run(self, context, args, result)
def _set_variables(self, positional, kwargs, variables)
def _trace_log_args_message(self, variables)
def _resolve_arguments(self, arguments, variables=None)
def _get_timeout(self, variables=None)
def _run_teardown(self, context)
def _split_kwonly_and_kwargs(self, all_kwargs)
def _set_arguments(self, arguments, context)
def run(self, kw, context, run=True)
def __init__(self, handler, name=None)
def _dry_run(self, context, args, result)
def _execute(self, context)
arguments
:rtype: :py:class:robot.running.arguments.ArgumentSpec
def _format_trace_log_args_message(self, args, variables)
def _split_args_and_varargs(self, args)
def dry_run(self, kw, context)
def getshortdoc(doc_or_item, linesep='\n')
def split_tags_from_doc(doc)
def prepr(item, width=80)
def is_list_variable(string)