Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions src/robotremoteserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,16 +190,27 @@ class StaticRemoteLibrary(object):

def __init__(self, library):
self._library = library
self._robot_name_index = {}

def get_keyword_names(self):
return [name for name, value in inspect.getmembers(self._library)
if name[0] != '_' and is_function_or_method(value)]
names = []
for name, value in inspect.getmembers(self._library):
if is_function_or_method(value):
if getattr(value, 'robot_name', None) not in (None, ''):
names.append(value.robot_name)
self._robot_name_index[value.robot_name] = name
else:
if name[0] != '_':
names.append(name)
return names

def run_keyword(self, name, args, kwargs=None):
kw = self._get_keyword(name)
return KeywordRunner(kw).run_keyword(args, kwargs)

def _get_keyword(self, name):
if name in self._robot_name_index:
name = self._robot_name_index[name]
kw = getattr(self._library, name, None)
return kw if is_function_or_method(kw) else None

Expand Down Expand Up @@ -227,7 +238,11 @@ def get_keyword_documentation(self, name):
return inspect.getdoc(self._library) or ''
if name == '__init__' and inspect.ismodule(self._library):
return ''
return inspect.getdoc(self._get_keyword(name)) or ''
keyword = self._get_keyword(name)
doc = inspect.getdoc(keyword) or ''
if len(getattr(keyword, 'robot_tags')):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This causes AttributeError if keyword doesn't have robot_tags. I'll fix it myself along with few other minor changes and test enhancements.

doc += "\nTags: %s\n" % ', '.join(keyword.robot_tags)
return doc


class HybridRemoteLibrary(StaticRemoteLibrary):
Expand Down
14 changes: 14 additions & 0 deletions test/atest/keyword_decorator.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
*** Settings ***
Resource resource.robot
Suite Setup Start And Import Remote Library keyword_decorator.py
Suite Teardown Stop Remote Library

*** Test Cases ***
Keyword with 2 arguments
Add 7 Copies Of Coffee To Cart

When embedded name is empty keyword is still callable
Embedded name empty

Tags added with keyword decorator
login admin
22 changes: 22 additions & 0 deletions test/libs/keyword_decorator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from robot.api.deco import keyword

class Arguments(object):

@keyword('Add ${quantity:\d+} Copies Of ${item} To Cart')
def add_copies_to_cart(self, quantity, item):
pass

@keyword('')
def embedded_name_empty(self):
pass

@keyword(tags=['tag1', 'tag2'])
def login(username, password):
'''
This is keyword documentation'''

if __name__ == '__main__':
import sys
from robotremoteserver import RobotRemoteServer

RobotRemoteServer(Arguments(), '127.0.0.1', *sys.argv[1:])