Skip to content

Commit 85d235d

Browse files
committed
Example tuning.
- Python 3 support. Related to robotframework#17. - Documentation cleanup. - Make it explicit example works on a single machine only. Fixes robotframework#30.
1 parent f8c1067 commit 85d235d

File tree

4 files changed

+35
-21
lines changed

4 files changed

+35
-21
lines changed

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
MANIFEST
22
.idea
3-
test/results
43
*.pyc
54
build
5+
test/results
6+
example/log.html
7+
example/report.html
8+
example/output.xml

example/README.rst

+21-18
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,38 @@ Remote server example
22
=====================
33

44
This directory contains a very simple remote library example in
5-
`<examplelibrary.py>`__ file and tests using it in `<example_tests.robot>`__
6-
file. The example library can be executed with Python, Jython, and IronPython.
7-
Also tests can be run with any of these interpreters, independently from
8-
the interpreter used for executing the library.
5+
`<examplelibrary.py>`__ file and tests using it in `<tests.robot>`__
6+
file. The example library can be executed with Python (both 2 and 3), Jython,
7+
IronPython or PyPy. Also tests can be run with any of these interpreters,
8+
independently from the interpreter used for executing the library.
99

1010
A precondition to running the example is installing the remote server or
11-
putting it into PYTHONPATH or equivalent otherwise. After that the remote
11+
putting it into ``PYTHONPATH`` or equivalent otherwise. After that the remote
1212
library can be started from the command line by just executing it with
1313
the selected interpreter::
1414

15-
python examplelibrary.py # Execute on Python
16-
jython examplelibrary.py # Execute on Jython
17-
ipy examplelibrary.py # Execute on IronPython
15+
python examplelibrary.py # Start library on Python
16+
jython examplelibrary.py # Start library on Jython
1817

19-
Alternatively the library can be double-clicked on a file manager. In that
20-
case it will run on Python.
18+
Depending on the operating system configuration, it may also be possible to
19+
simply double-click the library on a file manager.
2120

2221
After the library is running, tests can be executed normally::
2322

24-
pybot example_tests.robot # Execute with Python
25-
jybot example_tests.robot # Execute with Jython
26-
ipy example_tests.robot # Execute with IronPython
23+
robot tests.robot # Execute with the `robot` command
24+
pypy -m robot tests.robot # Execute `robot` module using PyPy
2725

28-
It is possible to use custom address and port by passing them as arguments
29-
to the library, which passes them further to the remote server, and overriding
30-
related variables when running tests::
26+
My default the library starts to listen on connections from the localhost on
27+
port 8270. Both the address and the port to listen to can be configured with
28+
command line arguments to the library, and also given as variables to tests
29+
that are run::
3130

32-
python examplelibrary.py 0.0.0.0 7777
33-
pybot --variable PORT:7777 example_tests.robot
31+
python examplelibrary.py 192.168.1.15 7777
32+
robot --variable ADDRESS:192.168.1.15 --variable PORT:7777 tests.robot
33+
34+
Although the remote server in general can be used from a different machine,
35+
this example only works correctly when tests are run on the same machine
36+
where the server is running.
3437

3538
See the example library and tests themselves for details how configuration
3639
is implemented and the general `remote server documentation <../README.rst>`__

example/examplelibrary.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
#!/usr/bin/env python
22

3+
from __future__ import print_function
4+
35
import os
46

7+
try:
8+
basestring
9+
except NameError: # Python 3
10+
basestring = str
11+
512

613
class ExampleRemoteLibrary(object):
714
"""Example library to be used with Robot Framework's remote server.
@@ -11,10 +18,11 @@ class ExampleRemoteLibrary(object):
1118

1219
def count_items_in_directory(self, path):
1320
"""Returns the number of items in the directory specified by `path`."""
14-
return len([i for i in os.listdir(path) if not i.startswith('.')])
21+
items = [i for i in os.listdir(path) if not i.startswith('.')]
22+
return len(items)
1523

1624
def strings_should_be_equal(self, str1, str2):
17-
print "Comparing '%s' to '%s'." % (str1, str2)
25+
print("Comparing '%s' to '%s'." % (str1, str2))
1826
if not (isinstance(str1, basestring) and isinstance(str2, basestring)):
1927
raise AssertionError("Given strings are not strings.")
2028
if str1 != str2:
File renamed without changes.

0 commit comments

Comments
 (0)