Skip to content

Commit d0ebf59

Browse files
added integration tests for RemoteRobot and TestRobot
--HG-- branch : dev
1 parent 1a699b6 commit d0ebf59

2 files changed

Lines changed: 119 additions & 0 deletions

File tree

test/remote/conftest.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import sys
2+
from textwrap import dedent
3+
from subprocess import Popen
4+
5+
from robottools import TestRobot
6+
from robottools.remote import RemoteRobot
7+
8+
import pytest
9+
10+
11+
# the libraries to load in the RemoteRobot instance
12+
# created in an external python process via process fixture
13+
REMOTE_LIBRARIES = [
14+
'BuiltIn',
15+
'ToolsLibrary',
16+
]
17+
ALLOWED_REMOTE_IMPORTS = [
18+
'Collections',
19+
]
20+
21+
22+
@pytest.fixture(scope='module')
23+
def process(request):
24+
"""Creates an external python process with a ``RemoteRobot`` instance
25+
loading all libraries defined in ``REMOTE_LIBRARIES``.
26+
"""
27+
return Popen([
28+
sys.executable, '-c', dedent("""
29+
__import__('robottools.remote').remote.RemoteRobot(
30+
[%s], allow_import=[%s]
31+
)""") % (', '.join(map(repr, REMOTE_LIBRARIES)),
32+
', '.join(map(repr, ALLOWED_REMOTE_IMPORTS)))])
33+
34+
35+
@pytest.fixture(scope='module')
36+
def robot_Remote(request):
37+
"""Creates a ``TestRobot`` instance loading ``Remote`` library,
38+
which automatically connects to the external ``RemoteRobot`` instance
39+
created in ``process`` fixture.
40+
"""
41+
robot = TestRobot('Test')
42+
robot.Import('Remote')
43+
return robot

test/remote/test_remote.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
from six import text_type as unicode
2+
from time import sleep
3+
4+
from decorator import decorate
5+
6+
from robottools import TestRobot
7+
8+
import pytest
9+
10+
11+
def check_process(func):
12+
"""Decorator for ``TestRemoteRobot.test_...`` methods
13+
to check if the external ``RemoteRobot`` process is still running,
14+
which is passed to every test method as ``process`` fixture.
15+
"""
16+
def caller(func, self, process, *args, **kwargs):
17+
# polling returns None as long as process is running
18+
assert process.poll() is None, \
19+
"RemoteRobot process is not running (anymore)."
20+
return func(self, process, *args, **kwargs)
21+
22+
return decorate(func, caller)
23+
24+
25+
class TestRemoteRobot(object):
26+
"""Integration tests for ``RemoteRobot`` and ``TestRobot``.
27+
"""
28+
@check_process
29+
def test_bool_result(self, process, robot_Remote):
30+
for value in [True, 1, 2.3, b'four', u'five', [5], {'six': 7}]:
31+
assert robot_Remote.ConvertToBool(value) is True
32+
for value in [False, 0, 0.0, b'', u'', [], {}]:
33+
assert robot_Remote.ConvertToBool('') is False
34+
35+
@check_process
36+
def test_int_result(self, process, robot_Remote):
37+
for value in [1, 2.3, '4', u'5']:
38+
result = robot_Remote.ConvertToInteger(value)
39+
assert isinstance(result, int)
40+
assert result == int(value)
41+
42+
@check_process
43+
def test_float_result(self, process, robot_Remote):
44+
for value in [1, 2.3, '4.5', u'6.7']:
45+
result = robot_Remote.ConvertToNumber(value)
46+
assert isinstance(result, float)
47+
assert result == float(value)
48+
49+
@check_process
50+
def test_bytes_result(self, process, robot_Remote):
51+
for value in [b'bytes', u'bytes']:
52+
result = robot_Remote.ConvertToBytes(value)
53+
assert isinstance(result, bytes)
54+
assert result == b'bytes'
55+
56+
@check_process
57+
def test_string_result(self, process, robot_Remote):
58+
for value in [1, 2.3, 'four', u'five']:
59+
result = robot_Remote.ConvertToString(value)
60+
assert isinstance(result, unicode)
61+
assert result == unicode(value)
62+
63+
@check_process
64+
def test_ImportRemoteLibrary(self, process, robot_Remote):
65+
assert not hasattr(robot_Remote, 'CopyList')
66+
robot_Remote.ImportRemoteLibrary('Collections')
67+
robot = TestRobot('New')
68+
robot.Import('Remote')
69+
assert robot.CopyList
70+
71+
@check_process
72+
def test_StopRemoteServer(self, process, robot_Remote):
73+
assert robot_Remote.StopRemoteServer() is True
74+
process.wait()
75+
# polling returns None as long as process is running
76+
assert process.poll() is not None

0 commit comments

Comments
 (0)