Skip to content

Commit a0faa67

Browse files
committed
Remote: Fix __init/intro__ doc w/ get_library_info.
Related to issue robotframework#3362 and PR robotframework#3802.
1 parent cbb3b8f commit a0faa67

File tree

6 files changed

+58
-18
lines changed

6 files changed

+58
-18
lines changed

atest/robot/standard_libraries/remote/documentation.robot

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
*** Settings ***
22
Suite Setup Run Remote Tests And Libdoc
33
Resource remote_resource.robot
4-
Resource ../../libdoc/libdoc_resource.robot
54
Test Template Verify executed short doc and full Libdoc
65

76
*** Test Cases ***

atest/robot/standard_libraries/remote/library_info.robot

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
*** Settings ***
2-
Suite Setup Run Remote Tests library_info.robot libraryinfo.py
2+
Suite Setup Run Remote Tests And Libdoc
33
Resource remote_resource.robot
44

55
*** Test Cases ***
@@ -8,6 +8,8 @@ Load large library
88

99
Arguments
1010
Check Test Case ${TESTNAME}
11+
Keyword Arguments Should Be 0 arg: int = None
12+
Keyword Arguments Should Be -1 arg: bool *extra
1113

1214
Types
1315
Check Test Case ${TESTNAME}
@@ -19,5 +21,26 @@ Documentation
1921

2022
Tags
2123
${tc} = Check Test Case Types
22-
Should Be Equal As Strings ${tc.body[0].tags} [some_keyword, tag]
23-
Should Be Equal As Strings ${tc.body[4].tags} [keyword_42, tag]
24+
Should Be Equal As Strings ${tc.body[0].tags} [tag]
25+
Should Be Equal As Strings ${tc.body[4].tags} [tag]
26+
27+
__intro__ is not exposed
28+
Check Test Case ${TESTNAME}
29+
30+
__init__ is not exposed
31+
Check Test Case ${TESTNAME}
32+
33+
Intro documentation
34+
Doc Should Be __intro__ documentation.
35+
36+
Init documentation
37+
Init Doc Should Be 0 __init__ documentation.
38+
39+
*** Keywords ***
40+
Run Remote Tests And Libdoc
41+
${port} = Run Remote Tests library_info.robot libraryinfo.py stop server=no
42+
Should Be Empty ${ERRORS}
43+
Run Libdoc And Parse Output Remote::http://127.0.0.1:${port}
44+
[Teardown] Run Keywords
45+
... Stop Remote Server libraryinfo.py AND
46+
... Remove Output Files

atest/robot/standard_libraries/remote/remote_resource.robot

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
*** Settings ***
22
Resource atest_resource.robot
3+
Resource ../../libdoc/libdoc_resource.robot
34

45
*** Variables ***
56
${PORT FILE} %{TEMPDIR}${/}remote_port.txt

atest/testdata/standard_libraries/remote/library_info.robot

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ Load large library
1414

1515
Arguments
1616
[Documentation] FAIL Keyword 'Remote.Keyword 0' expected 0 to 1 arguments, got 2.
17-
Some Keyword
1817
Some Keyword a
1918
Some Keyword a b
2019
Some Keyword a b c d e
@@ -29,3 +28,11 @@ Types
2928
Should be equal ${ret} no
3029
${ret} = Keyword 42 -42
3130
Should be equal ${ret} ${-42}
31+
32+
__intro__ is not exposed
33+
[Documentation] FAIL No keyword with name '__intro__' found.
34+
__intro__
35+
36+
__init__ is not exposed
37+
[Documentation] FAIL No keyword with name '__init__' found.
38+
__init__

atest/testdata/standard_libraries/remote/libraryinfo.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@ def _register_functions(self):
1414
self.register_function(self.run_keyword)
1515

1616
def get_library_information(self):
17-
info_dict = dict()
17+
info_dict = {'__init__': {'doc': '__init__ documentation.'},
18+
'__intro__': {'doc': '__intro__ documentation.'}}
1819
for kw in self.get_keyword_names():
19-
info_dict[kw] = dict(args=['*args'] if kw == 'some_keyword' else ['arg=None'],
20-
doc="Documentation for '%s'." % kw,
21-
tags=['tag', kw],
22-
types=['bool'] if kw == 'some_keyword' else ['int'])
20+
info_dict[kw] = dict(
21+
args=['arg', '*extra'] if kw == 'some_keyword' else ['arg=None'],
22+
doc="Documentation for '%s'." % kw,
23+
tags=['tag'],
24+
types=['bool'] if kw == 'some_keyword' else ['int']
25+
)
2326
return info_dict
2427

2528

@@ -29,7 +32,7 @@ def __init__(self):
2932
for i in range(10000):
3033
setattr(self, 'keyword_%d' % i, lambda result=str(i): result)
3134

32-
def some_keyword(self, arg=True, *extra):
35+
def some_keyword(self, arg, *extra):
3336
return 'yes' if arg else 'no'
3437

3538

src/robot/libraries/Remote.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,26 +66,33 @@ def __init__(self, uri='http://127.0.0.1:8270', timeout=None):
6666
self._uri = uri
6767
self._client = XmlRpcRemoteClient(uri, timeout)
6868
self._lib_info = None
69+
self._lib_info_initialized = False
6970

7071
def get_keyword_names(self):
71-
try:
72-
self._lib_info = self._client.get_library_information()
73-
except TypeError:
74-
pass
75-
else:
76-
return self._lib_info.keys()
72+
if self._initialize_lib_info():
73+
return [name for name in self._lib_info
74+
if not (name[:2] == '__' and name[-2:] == '__')]
7775
try:
7876
return self._client.get_keyword_names()
7977
except TypeError as error:
8078
raise RuntimeError('Connecting remote server at %s failed: %s'
8179
% (self._uri, error))
8280

81+
def _initialize_lib_info(self):
82+
if not self._lib_info_initialized:
83+
try:
84+
self._lib_info = self._client.get_library_information()
85+
except TypeError:
86+
pass
87+
self._lib_info_initialized = True
88+
return self._lib_info is not None
89+
8390
def get_keyword_arguments(self, name):
8491
return self._get_kw_info(name, 'args', self._client.get_keyword_arguments,
8592
default=['*args'])
8693

8794
def _get_kw_info(self, kw, info, getter, default=None):
88-
if self._lib_info is not None:
95+
if self._initialize_lib_info():
8996
return self._lib_info[kw].get(info, default)
9097
try:
9198
return getter(kw)

0 commit comments

Comments
 (0)