Skip to content

Commit ce976e0

Browse files
committed
Cleanup and fixes to @Keyword support (issue #35, PR #37)
- Dont' require keywords to always have `robot_tags`. - Minor cleanup elsewhere in code. - Test enhancements. Tags not really tested yet.
1 parent b430137 commit ce976e0

File tree

4 files changed

+53
-38
lines changed

4 files changed

+53
-38
lines changed

src/robotremoteserver.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -194,14 +194,13 @@ def __init__(self, library):
194194

195195
def get_keyword_names(self):
196196
names = []
197-
for name, value in inspect.getmembers(self._library):
198-
if is_function_or_method(value):
199-
if getattr(value, 'robot_name', None) not in (None, ''):
200-
names.append(value.robot_name)
201-
self._robot_name_index[value.robot_name] = name
202-
else:
203-
if name[0] != '_':
204-
names.append(name)
197+
for name, kw in inspect.getmembers(self._library):
198+
if is_function_or_method(kw):
199+
if getattr(kw, 'robot_name', None):
200+
names.append(kw.robot_name)
201+
self._robot_name_index[kw.robot_name] = name
202+
elif name[0] != '_':
203+
names.append(name)
205204
return names
206205

207206
def run_keyword(self, name, args, kwargs=None):
@@ -240,7 +239,7 @@ def get_keyword_documentation(self, name):
240239
return ''
241240
keyword = self._get_keyword(name)
242241
doc = inspect.getdoc(keyword) or ''
243-
if len(getattr(keyword, 'robot_tags')):
242+
if getattr(keyword, 'robot_tags', []):
244243
doc += "\nTags: %s\n" % ', '.join(keyword.robot_tags)
245244
return doc
246245

test/atest/keyword_decorator.robot

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
*** Settings ***
22
Resource resource.robot
3-
Suite Setup Start And Import Remote Library keyword_decorator.py
3+
Suite Setup Start And Import Remote Library KeywordDecorator.py
44
Suite Teardown Stop Remote Library
55

66
*** Test Cases ***
7-
Keyword with 2 arguments
8-
Add 7 Copies Of Coffee To Cart
7+
Custom name
8+
[Documentation] FAIL Keyword 'Remote.Custom Name' expected 1 argument, got 3.
9+
Custom name arg
10+
Custom name too many args
911

10-
When embedded name is empty keyword is still callable
11-
Embedded name empty
12+
Embedded arguments
13+
Result of 1 + 2 should be 3
14+
Result of (1+2) * 3 should be 9
1215

13-
Tags added with keyword decorator
14-
login admin
16+
No custom name
17+
Just marker
18+
19+
Tags
20+
Tags
21+
Tags with doc (and custom name)

test/libs/KeywordDecorator.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from robot.api.deco import keyword
2+
3+
4+
class KeywordDecorator(object):
5+
6+
@keyword('Custom name')
7+
def _this_name_doesnt_matter(self, arg):
8+
assert arg == 'arg'
9+
10+
@keyword('Result of ${expression} should be ${result:\d+}')
11+
def calculate(self, expression, expected):
12+
assert eval(expression) == int(expected)
13+
14+
@keyword
15+
def just_marker(self):
16+
pass
17+
18+
@keyword(tags=['tag1', 'tag2'])
19+
def tags(self):
20+
pass
21+
22+
@keyword('Tags with doc (and custom name)', ['tag1'])
23+
def tags_(self):
24+
"""Keyword documentation."""
25+
26+
27+
if __name__ == '__main__':
28+
import sys
29+
from robotremoteserver import RobotRemoteServer
30+
31+
RobotRemoteServer(KeywordDecorator(), '127.0.0.1', *sys.argv[1:])

test/libs/keyword_decorator.py

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)