Skip to content

Commit a0b087d

Browse files
merged with [dev] branch
2 parents e998d9e + c9504df commit a0b087d

File tree

10 files changed

+100
-60
lines changed

10 files changed

+100
-60
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ install:
1111
- pip install -r requirements.txt --upgrade
1212
- pip install -r requirements.remote.txt --upgrade
1313
- pip install -r requirements.robotshell.txt --upgrade
14+
- pip install robotframework-python3
1415
- pip install zetup[commands] --upgrade
1516
- pip install pytest --upgrade
1617
- pip install tox --upgrade

README.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,13 @@ Package extra features:
4040

4141
### Requirements
4242

43-
* [`six>=1.9`](https://pypi.python.org/pypi/six)
44-
* [`path.py>=7.0`](https://pypi.python.org/pypi/path.py)
45-
* [`moretools>=0.1.5`](https://pypi.python.org/pypi/moretools)
46-
* [`robotframework>=2.8`](https://pypi.python.org/pypi/robotframework)
47-
* __Python 3.x__: [`robotframework-python3>=2.8.3`](
43+
* [`six>=1.10`](https://pypi.python.org/pypi/six)
44+
* [`path.py>=8.0`](https://pypi.python.org/pypi/path.py)
45+
* [`moretools>=0.1.8`](https://pypi.python.org/pypi/moretools)
46+
* [`robotframework>=2.8.7`](https://pypi.python.org/pypi/robotframework)
47+
* __Python 3.x__:
48+
* Robot Framework 3.0+ is officially Python 3 compatible
49+
* For earlier versions please install [`robotframework-python3`](
4850
https://pypi.python.org/pypi/robotframework-python3)
4951

5052
Extra requirements for __[remote]__:
@@ -53,7 +55,7 @@ Extra requirements for __[remote]__:
5355

5456
Extra requirements for __[robotshell]__:
5557

56-
* [`ipython>=3.0`](https://pypi.python.org/pypi/ipython)
58+
* [`ipython>=4.0`](https://pypi.python.org/pypi/ipython)
5759

5860
### Installation
5961

@@ -71,6 +73,8 @@ Or from [PyPI](https://pypi.python.org/pypi/robotframework-tools):
7173

7274
pip install robotframework-tools[remote,robotshell]
7375

76+
* Robot Framework will not be installed automatically
77+
7478

7579
# 1. Creating Dynamic Test Libraries
7680
------------------------------------

requirements.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,3 @@ six >= 1.10
33
path.py >= 8.0 #import path
44
moretools >= 0.1.8
55
modeled >= 0.1.8
6-
#py2 robotframework >= 2.8.7 #import robot
7-
#py3 robotframework-python3 >= 2.8.7 #import robot

robottools/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"""
2626

2727
from zetup import find_zetup_config
28+
from zetup.version import Version
2829

2930
zfg = find_zetup_config(__name__)
3031

@@ -38,6 +39,17 @@
3839

3940
## __notebook__ = zfg.NOTEBOOKS['README']
4041

42+
try:
43+
import robot
44+
except ImportError as exc:
45+
raise ImportError(
46+
"%s depends on robotframework but import failed with: %s"
47+
% (repr(__distribution__), exc))
48+
if Version(robot.__version__) < '2.8.7':
49+
raise __import__('pkg_resources').VersionConflict(
50+
"%s needs robotframework>=2.8.7 but found %s in %s"
51+
% (repr(__distribution__), robot.__version__, repr(robot)))
52+
4153
from robottools.library import *
4254
from robottools.library.keywords import *
4355
from robottools.library.session import SessionHandler

robottools/library/keywords/__init__.py

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -147,18 +147,17 @@ def __call__(self, *args, **kwargs):
147147
try:
148148
sname = kwargs.pop(identifier)
149149
except KeyError:
150-
pass
151-
else:
152-
previous = getattr(self.libinstance, identifier)
153-
switch = getattr(self.libinstance, 'switch_' + identifier)
154-
try:
155-
switch(sname)
156-
except hcls.SessionError:
157-
error = sys.exc_info()
158-
# don't switch any more sessions
159-
break
160-
# store previous session for switching back later
161-
current_sessions[identifier, plural_identifier] = previous
150+
continue
151+
previous = getattr(self.libinstance, identifier)
152+
switch = getattr(self.libinstance, 'switch_' + identifier)
153+
try:
154+
switch(sname)
155+
except hcls.SessionError:
156+
error = sys.exc_info()
157+
# don't switch any more sessions
158+
break
159+
# store previous session for switching back later
160+
current_sessions[identifier, plural_identifier] = previous
162161
# only perform explicit context switching
163162
# if explicit session switching didn't raise any error
164163
current_contexts = {}
@@ -170,19 +169,17 @@ def __call__(self, *args, **kwargs):
170169
try:
171170
ctxname = kwargs.pop(identifier)
172171
except KeyError:
173-
pass
174-
else:
175-
previous = getattr(self.libinstance, identifier)
176-
switch = getattr(self.libinstance,
177-
'switch_' + identifier)
178-
try:
179-
switch(ctxname)
180-
except hcls.ContextError:
181-
error = sys.exc_info()
182-
# don't switch any more contexts
183-
break
184-
# store previous context for switching back later
185-
current_contexts[identifier] = previous
172+
continue
173+
previous = getattr(self.libinstance, identifier)
174+
switch = getattr(self.libinstance, 'switch_' + identifier)
175+
try:
176+
switch(ctxname)
177+
except hcls.ContextError:
178+
error = sys.exc_info()
179+
# don't switch any more contexts
180+
break
181+
# store previous context for switching back later
182+
current_contexts[identifier] = previous
186183
# only call the acutal keyword func
187184
# if explicit session and context switching didn't raise any error
188185
if error is None:

robottools/testrobot/__init__.py

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,27 @@
2323
2424
.. moduleauthor:: Stefan Zimmermann <[email protected]>
2525
"""
26-
from six import reraise
27-
28-
__all__ = ['TestRobot',
29-
'TestResult', # from .result
30-
]
26+
__all__ = [
27+
'TestRobot',
28+
'TestResult', # from .result
29+
]
3130

31+
from six import reraise
3232
from inspect import getargspec
3333
from functools import partial
3434

3535
from moretools import isidentifier
3636

3737
from robot.errors import DataError
38-
from robot.model import TestSuite
3938
from robot.conf import RobotSettings
39+
from robot.running.model import TestSuite
40+
from robot.running.namespace import Namespace
41+
from robot.running.runner import Runner
42+
from robot.running import TestSuiteBuilder
4043
try:
4144
from robot.variables import GLOBAL_VARIABLES, init_global_variables
4245
except ImportError: # Robot 2.9
4346
from robot.variables import VariableScopes
44-
from robot.running.namespace import Namespace
45-
from robot.running.runner import Runner
46-
from robot.running import TestSuiteBuilder
4747

4848
from robottools import TestLibraryInspector
4949

@@ -76,25 +76,36 @@ def __init__(self, name, BuiltIn=True, variable_getters=None):
7676
self.debug = False
7777
try:
7878
GLOBAL_VARIABLES
79-
except NameError: # Robot 2.9
79+
except NameError:
80+
# Robot 2.9+
8081
self._variables = VariableScopes(RobotSettings())
8182
else:
82-
if not GLOBAL_VARIABLES: #HACK
83+
# Robot 2.8
84+
if not GLOBAL_VARIABLES: # HACK
8385
init_global_variables(RobotSettings())
8486
self._variables = GLOBAL_VARIABLES.copy()
85-
#HACK even more to extend variable lookup:
87+
# HACK even more to extend variable lookup
8688
self._variables.__class__ = variablesclass(
87-
self._variables.__class__, extra_getters=variable_getters)
89+
self._variables.__class__, extra_getters=variable_getters)
90+
8891
self._output = Output()
8992
self._context = Context(testrobot=self)
9093
self._suite = TestSuite(name)
91-
namespace = partial(Namespace,
92-
suite=self._suite, variables=self._variables,
93-
user_keywords=[], imports=None)
94-
if 'parent_variables' in getargspec(Namespace.__init__).args:
95-
self._namespace = namespace(parent_variables=None)
96-
else: # Robot 2.9
97-
self._namespace = namespace()
94+
95+
argspec = getargspec(Namespace.__init__)
96+
namespace = partial(
97+
Namespace, suite=self._suite, variables=self._variables)
98+
if 'resource' in argspec.args:
99+
# Robot 3.0
100+
self._namespace = namespace(resource=self._suite.resource)
101+
else:
102+
namespace.keywords.update(user_keywords=[], imports=None)
103+
if 'parent_variables' in argspec.args:
104+
# Robot 2.8
105+
self._namespace = namespace(parent_variables=None)
106+
else:
107+
# Robot 2.9
108+
self._namespace = namespace()
98109

99110
if BuiltIn:
100111
self.Import('BuiltIn')
@@ -115,8 +126,8 @@ def __doc__(self):
115126
"""Dynamic doc string, listing imported Test Libraries.
116127
"""
117128
return '%s\n\n%s' % (repr(self), '\n\n'.join(sorted(
118-
'* [Import] ' + lib.name
119-
for alias, lib in self._libraries.items())))
129+
'* [Import] ' + lib.name
130+
for alias, lib in self._libraries.items())))
120131

121132
def Import(self, lib, args=None, alias=None):
122133
"""Import a Test Library with an optional `alias` name.
@@ -125,8 +136,8 @@ def Import(self, lib, args=None, alias=None):
125136
#HACK: `with` adds Context to robot.running.EXECUTION_CONTEXTS
126137
# and registers Output to robot.output.LOGGER
127138
with self._context:
128-
lib = self._context.importer.import_library(lib,
129-
args and list(args), alias, None)
139+
lib = self._context.importer.import_library(
140+
lib, args and list(args), alias, None)
130141
self._libraries[alias or lib.name] = lib
131142
lib = TestLibraryInspector(lib)
132143
## lib = TestLibraryInspector(lib, *(args or ()))
@@ -189,8 +200,8 @@ def __getattr__(self, name):
189200
return self._variables['${%s}' % name]
190201
except DataError:
191202
raise AttributeError(
192-
"No Test Library, Keyword or Variable named '%s'."
193-
% name)
203+
"No Test Library, Keyword or Variable named '%s'."
204+
% name)
194205

195206
def __dir__(self):
196207
"""List all Robot Variables (UPPER_CASE),

robottools/testrobot/context.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def __init__(self, testrobot):
3838
self.in_teardown = False
3939
self.test = None
4040
self.importer = Importer()
41+
self.timeouts = set()
4142

4243
def __enter__(self):
4344
"""Prepare the TestRobot's context
@@ -84,6 +85,10 @@ def get_handler(self, name):
8485
repr(self.testrobot.name), repr(name)))
8586
return keyword._handler
8687

88+
def get_runner(self, name):
89+
handler = self.get_handler(name)
90+
return handler.create_runner(name)
91+
8792
def start_keyword(self, keyword):
8893
pass
8994

robottools/testrobot/output.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
from robot.output import LOGGER, LEVELS as LOG_LEVELS
3131
from robot.output.loggerhelper import AbstractLogger
3232
from robot.output.pyloggingconf import RobotHandler
33+
try: # Robot 3.0
34+
from robot.output.listeners import LibraryListeners
35+
except ImportError:
36+
LibraryListeners = None
3337

3438
from .highlighting import Highlighter
3539

@@ -61,11 +65,17 @@ class Output(AbstractLogger):
6165
def __init__(self, log_level='INFO'):
6266
AbstractLogger.__init__(self, level=log_level)
6367
self.logging_handler = LoggingHandler()
68+
if LibraryListeners is not None:
69+
# Robot 3.0
70+
self.library_listeners = LibraryListeners(log_level)
6471
# streams to be used internally for writing messages
6572
# - see self.__enter__() and self.message()
6673
self._out = self._err = None
6774

6875
def set_log_level(self, level):
76+
if LibraryListeners is not None:
77+
# Robot 3.0
78+
self.library_listeners.set_log_level(level)
6979
return self.set_level(level)
7080

7181
def __enter__(self):

tox.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ envlist = py27,py33,py34
77

88
[testenv]
99
deps =
10+
robotframework-python3
1011
pytest
1112

1213
commands =
13-
py.test -v test
14+
py.test -v test

zetup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ zetup_config module = yes
2121

2222
no make =
2323
VERSION
24+
tox.ini
2425

2526
keep made =
2627
setup.py

0 commit comments

Comments
 (0)