Skip to content

Commit aa0ee8e

Browse files
committed
Support defining keywords in main lib
1 parent 09f21a9 commit aa0ee8e

File tree

6 files changed

+27
-4
lines changed

6 files changed

+27
-4
lines changed

atest/DynamicLibrary.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from robotlibcore import DynamicCore
1+
from robotlibcore import DynamicCore, keyword
22

33
import librarycomponents
44

@@ -15,3 +15,10 @@ def __init__(self, arg=None):
1515
librarycomponents.DocsAndTags()]
1616
DynamicCore.__init__(self, components)
1717
self.instance_attribute = 'not keyword'
18+
19+
@keyword
20+
def keyword_in_main(self):
21+
pass
22+
23+
def not_keyword_in_main(self):
24+
pass

atest/HybridLibrary.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from robotlibcore import HybridCore
1+
from robotlibcore import HybridCore, keyword
22

33
import librarycomponents
44

@@ -14,3 +14,10 @@ def __init__(self):
1414
librarycomponents.DocsAndTags()]
1515
HybridCore.__init__(self, components)
1616
self.instance_attribute = 'not keyword'
17+
18+
@keyword
19+
def keyword_in_main(self):
20+
pass
21+
22+
def not_keyword_in_main(self):
23+
pass

atest/librarycomponents.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ def _whatever(self):
2222
def not_keyword(self):
2323
pass
2424

25+
@keyword
26+
def keyword_in_main(self):
27+
raise AssertionError('Should be overridden by the main library!')
28+
2529

2630
class Arguments(object):
2731

atest/tests.robot

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ ${LIBRARY} DynamicLibrary
66

77
*** Test Cases ***
88
Keyword names
9+
Keyword in main
910
Function
1011
FUNCTION
1112
Method

src/robotlibcore.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ def decorator(func):
2020
class HybridCore(object):
2121

2222
def __init__(self, libraries):
23-
self.keywords = dict(self._find_keywords(libraries))
23+
self.keywords = dict(self._find_keywords(*libraries))
24+
self.keywords.update(self._find_keywords(self))
2425

25-
def _find_keywords(self, libraries):
26+
def _find_keywords(self, *libraries):
2627
for library in libraries:
2728
for name, func in self._get_members(library):
2829
if callable(func) and hasattr(func, 'robot_name'):

utest/test_robotlibcore.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ def test_keyword_names():
1111
'defaults',
1212
'doc_and_tags',
1313
'function',
14+
'keyword_in_main',
1415
'mandatory',
1516
'method',
1617
'multi_line_doc',
@@ -33,10 +34,12 @@ def test_dir():
3334
'get_keyword_documentation',
3435
'get_keyword_names',
3536
'instance_attribute',
37+
'keyword_in_main',
3638
'keywords',
3739
'mandatory',
3840
'method',
3941
'multi_line_doc',
42+
'not_keyword_in_main',
4043
'one_line_doc',
4144
'run_keyword',
4245
'tags',

0 commit comments

Comments
 (0)