class UserKeywordHandler(object): type = "user" def __init__(self, keyword, libname): self.name = keyword.name self.keywords = Keywords(keyword.steps) self.return_value = keyword.return_.value self._libname = libname self.doc = self._doc = keyword.doc.value self._timeout = keyword.timeout self._keyword_args = keyword.args.value @property def longname(self): return "%s.%s" % (self._libname, self.name) if self._libname else self.name @property def shortdoc(self): return self.doc.splitlines()[0] if self.doc else "" def init_keyword(self, varz): self._errors = [] self.doc = varz.replace_meta("Documentation", self._doc, self._errors) self.timeout = KeywordTimeout(self._timeout.value, self._timeout.message) self.timeout.replace_variables(varz) def run(self, context, arguments): context.namespace.start_user_keyword(self) try: return self._run(context, arguments) finally: context.namespace.end_user_keyword() def _run(self, context, argument_values): args_spec = UserKeywordArguments(self._keyword_args, self.longname) variables = context.get_current_vars() if context.dry_run: return self._dry_run(context, variables, args_spec, argument_values) return self._variable_resolving_run(context, variables, args_spec, argument_values) def _dry_run(self, context, variables, args_spec, argument_values): resolved_arguments = args_spec.resolve_arguments_for_dry_run(argument_values) self._execute(context, variables, args_spec, resolved_arguments) return None def _variable_resolving_run(self, context, variables, args_spec, argument_values): resolved_arguments = args_spec.resolve(argument_values, variables) self._execute(context, variables, args_spec, resolved_arguments) return self._get_return_value(variables) def _execute(self, context, variables, args_spec, resolved_arguments): args_spec.set_variables(resolved_arguments, variables, context.output) self._verify_keyword_is_valid() self.timeout.start() self.keywords.run(context) def _verify_keyword_is_valid(self): if self._errors: raise DataError("User keyword initialization failed:\n%s" % "\n".join(self._errors)) if not (self.keywords or self.return_value): raise DataError("User keyword '%s' contains no keywords" % self.name) def _get_return_value(self, variables): if not self.return_value: return None try: ret = variables.replace_list(self.return_value) except DataError, err: raise DataError("Replacing variables from keyword return value " "failed: %s" % unicode(err)) if len(ret) != 1 or is_list_var(self.return_value[0]): return ret return ret[0]
def init_keyword(self, varz): self._errors = [] self.doc = varz.replace_meta("Documentation", self._doc, self._errors) self.timeout = KeywordTimeout(self._timeout.value, self._timeout.message) self.timeout.replace_variables(varz)
def init_keyword(self, varz): self._errors = [] self.doc = varz.replace_meta('Documentation', self._doc, self._errors) self.timeout = KeywordTimeout(self._timeout.value, self._timeout.message) self.timeout.replace_variables(varz)
class UserKeywordHandler(object): type = 'user' def __init__(self, keyword, libname): self.name = keyword.name self.keywords = Keywords(keyword.steps) self.return_value = keyword.return_.value self._libname = libname self.doc = self._doc = keyword.doc.value self._timeout = keyword.timeout self._keyword_args = keyword.args.value @property def longname(self): return '%s.%s' % (self._libname, self.name) if self._libname else self.name @property def shortdoc(self): return self.doc.splitlines()[0] if self.doc else '' def init_keyword(self, varz): self._errors = [] self.doc = varz.replace_meta('Documentation', self._doc, self._errors) self.timeout = KeywordTimeout(self._timeout.value, self._timeout.message) self.timeout.replace_variables(varz) def run(self, context, arguments): context.namespace.start_user_keyword(self) try: return self._run(context, arguments) finally: context.namespace.end_user_keyword() def _run(self, context, argument_values): args_spec = UserKeywordArguments(self._keyword_args, self.longname) variables = context.get_current_vars() if context.dry_run: return self._dry_run(context, variables, args_spec, argument_values) return self._variable_resolving_run(context, variables, args_spec, argument_values) def _dry_run(self, context, variables, args_spec, argument_values): resolved_arguments = args_spec.resolve_arguments_for_dry_run( argument_values) self._execute(context, variables, args_spec, resolved_arguments) return None def _variable_resolving_run(self, context, variables, args_spec, argument_values): resolved_arguments = args_spec.resolve(argument_values, variables) self._execute(context, variables, args_spec, resolved_arguments) return self._get_return_value(variables) def _execute(self, context, variables, args_spec, resolved_arguments): args_spec.set_variables(resolved_arguments, variables, context.output) self._verify_keyword_is_valid() self.timeout.start() self.keywords.run(context) def _verify_keyword_is_valid(self): if self._errors: raise DataError('User keyword initialization failed:\n%s' % '\n'.join(self._errors)) if not (self.keywords or self.return_value): raise DataError("User keyword '%s' contains no keywords" % self.name) def _get_return_value(self, variables): if not self.return_value: return None try: ret = variables.replace_list(self.return_value) except DataError, err: raise DataError('Replacing variables from keyword return value ' 'failed: %s' % unicode(err)) if len(ret) != 1 or is_list_var(self.return_value[0]): return ret return ret[0]
class UserKeywordHandler(object): type = 'user' def __init__(self, keyword, libname): self.name = keyword.name self.keywords = Keywords(keyword.steps) self.return_value = keyword.return_.value self.teardown = keyword.teardown self.libname = libname self.doc = self._doc = keyword.doc.value self._timeout = keyword.timeout self._keyword_args = keyword.args.value @property def longname(self): return '%s.%s' % (self.libname, self.name) if self.libname else self.name @property def shortdoc(self): return self.doc.splitlines()[0] if self.doc else '' def init_keyword(self, varz): self._errors = [] self.doc = varz.replace_meta('Documentation', self._doc, self._errors) self.timeout = KeywordTimeout(self._timeout.value, self._timeout.message) self.timeout.replace_variables(varz) def run(self, context, arguments): context.namespace.start_user_keyword(self) try: return self._run(context, arguments) finally: context.namespace.end_user_keyword() def _run(self, context, argument_values): args_spec = UserKeywordArguments(self._keyword_args, self.longname) variables = context.get_current_vars() if context.dry_run: return self._dry_run(context, variables, args_spec, argument_values) return self._variable_resolving_run(context, variables, args_spec, argument_values) def _dry_run(self, context, variables, args_spec, argument_values): resolved_arguments = args_spec.resolve_arguments_for_dry_run(argument_values) self._execute(context, variables, args_spec, resolved_arguments) return None def _variable_resolving_run(self, context, variables, args_spec, argument_values): resolved_arguments = args_spec.resolve(argument_values, variables, context.output) self._execute(context, variables, args_spec, resolved_arguments) return self._get_return_value(variables) def _execute(self, context, variables, args_spec, resolved_arguments): args_spec.set_variables(resolved_arguments, variables, context.output) self._verify_keyword_is_valid() self.timeout.start() try: self.keywords.run(context) except ExecutionFailed, error: pass else: