|
| 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