Skip to content

Commit 724445d

Browse files
committed
Explicit test for using library implemented as a module. #43
1 parent 904d918 commit 724445d

File tree

4 files changed

+119
-4
lines changed

4 files changed

+119
-4
lines changed

test/atest/basic_communication.robot

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
*** Settings ***
2+
Documentation Testing basic communication using a class based library.
3+
... `module.robot` contains same tests using a library
4+
... implemented as a module.
25
Resource resource.robot
36
Suite Setup Start And Import Remote Library Basics.py
47
Suite Teardown Stop Remote Library

test/atest/module.robot

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
*** Settings ***
2+
Documentation Testing basic communication using a module based library.
3+
... `basic_communication.robot` contains same tests using
4+
... a library implemented as a class.
5+
Resource resource.robot
6+
Suite Setup Start And Import Remote Library Module.py
7+
Suite Teardown Stop Remote Library
8+
9+
*** Variables ***
10+
${COUNT} 100
11+
12+
*** Test Cases ***
13+
Passing
14+
Passing
15+
16+
Failing
17+
[Documentation] FAIL This is the error we get
18+
Failing This is the error we get
19+
Fail This should not be executed
20+
21+
Logging
22+
[Documentation] LOG 1 INFO Hello, world! LOG 2 WARN Warning, warning!!
23+
Logging Hello, world!
24+
Logging Warning, warning!! WARN
25+
26+
Returning
27+
${ret} = Returning return this
28+
Should Be Equal ${ret} return this
29+
30+
Use multiple times
31+
[Documentation]
32+
... LOG 1.1.2 Round 1
33+
... LOG 1.2.2 Round 2
34+
... LOG 1.${COUNT}.2 Round ${COUNT}
35+
: FOR ${i} IN RANGE ${COUNT}
36+
\ Passing
37+
\ Logging Round ${i + 1}
38+
39+
Private methods should ne ignored
40+
[Documentation] FAIL No keyword with name 'Private Method' found.
41+
Private Method
42+
43+
Attributes should be ignored
44+
[Documentation] FAIL No keyword with name 'ATTRIBUTE' found.
45+
ATTRIBUTE

test/libs/Basics.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33

44
class BasicCommunication(object):
5-
"""Testing basic communication and keyword documentation."""
5+
"""Testing basic communication and keyword documentation using a class.
6+
7+
Module.py has same stuff but using a module, not a class, as a library.
8+
"""
69

710
def passing(self):
811
"""This keyword passes.
@@ -12,9 +15,7 @@ def passing(self):
1215
pass
1316

1417
def get_pid(self):
15-
"""
16-
Returns process id for the remote server that is serving this library.
17-
"""
18+
"""Return process id of the server that is serving this library."""
1819
return os.getpid()
1920

2021
def failing(self, message):

test/libs/Module.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import os
2+
3+
4+
"""Testing basic communication and keyword documentation using module.
5+
6+
Same stuff as in Basics.py but this library is implemented as a module,
7+
not as a class.
8+
"""
9+
10+
11+
def passing():
12+
"""This keyword passes.
13+
14+
See `Failing`, `Logging`, and `Returning` for other basic keywords.
15+
"""
16+
pass
17+
18+
19+
def get_pid():
20+
"""Return process id of the server that is serving this library."""
21+
return os.getpid()
22+
23+
24+
def failing(message):
25+
"""This keyword fails with provided `message`"""
26+
raise AssertionError(message)
27+
28+
29+
def logging(message, level='INFO'):
30+
"""This keywords logs given `message` with given `level`
31+
32+
Example:
33+
| Logging | Hello, world! | |
34+
| Logging | Warning!!! | WARN |
35+
"""
36+
print('*%s* %s' % (level, message))
37+
38+
39+
def returning(value):
40+
"""This keyword returns the given `value`."""
41+
return value
42+
43+
44+
def _private_method():
45+
"""This is not a keyword. Nor is the next one."""
46+
pass
47+
48+
49+
def __private_method():
50+
pass
51+
52+
53+
ATTRIBUTE = 'Not a keyword'
54+
55+
56+
if __name__ == '__main__':
57+
import sys
58+
from robotremoteserver import RobotRemoteServer
59+
60+
if sys.argv[-1] == 'no_stop':
61+
conf = {'allow_remote_stop': False}
62+
sys.argv.pop()
63+
else:
64+
conf = {}
65+
library = sys.modules[__name__]
66+
RobotRemoteServer(library, '127.0.0.1', *sys.argv[1:], **conf)

0 commit comments

Comments
 (0)