-
Notifications
You must be signed in to change notification settings - Fork 27
Support RF 3.2 get_keyword_arguments new format #31
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ | |
|
||
|
||
from robot.api.deco import keyword # noqa F401 | ||
from robot import __version__ as robot_version | ||
|
||
PY2 = sys.version_info < (3,) | ||
|
||
|
@@ -97,7 +98,27 @@ def run_keyword(self, name, args, kwargs=None): | |
return self.keywords[name](*args, **(kwargs or {})) | ||
|
||
def get_keyword_arguments(self, name): | ||
kw = self.keywords[name] if name != '__init__' else self.__init__ | ||
if robot_version >= '3.2': | ||
return self.__new_arg_spec(name) | ||
return self.__old_arg_spec(name) | ||
|
||
def __new_arg_spec(self, keyword_name): | ||
kw = self.__get_keyword(keyword_name) | ||
if kw is None: | ||
return [tuple(), ] | ||
args, defaults, varargs, kwargs = self.__get_arg_spec(kw) | ||
args = [(arg, ) for arg in args] | ||
args += [(name, value) for name, value in defaults] | ||
if varargs: | ||
args.append(('*{}'.format(varargs), )) | ||
if kwargs: | ||
args.append(('**{}'.format(kwargs), )) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's no need to return other than defaults as tuples. That's ok but also Looking at this code I remember that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
return args | ||
|
||
def __old_arg_spec(self, keyword_name): | ||
kw = self.__get_keyword(keyword_name) | ||
if kw is None: | ||
return [] | ||
args, defaults, varargs, kwargs = self.__get_arg_spec(kw) | ||
args += ['{}={}'.format(name, value) for name, value in defaults] | ||
if varargs: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is invalid return value. The syntax also looks a bit strange when
[()]
could be used instead, but that's not really relevant.It would probably be better to handle
kw
being none inget_keyword_arguments
before callingnew/old
methods. I'm not actually sure what would be a good return value in that case. ProbablyNone
to let Robot handle the fact that we don't know the spec. Returning[]
would mean that we say the kw accepts no args.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was not sure what should be returned. Other thing that I was considering, that it would be possible to raise an exception. But if
None
is better from Robot Framework side, let's go with that.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Items in the list returned from
get_keyword_names
must be strings or tuples with 1-2 items so that the first item is a string.Isn't it so that
kw
can beNone
only if RF callsget_keyword_arguments
with some new special value like__special__
? It's very unlikely to happen in general, but I guess returningNone
as an indication that we don't know is the best solution. This could be tested with unit tests but I'm no certain is it worth the effort.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, None is used for other
__special__
values, expect__init__
.