Skip to content

Commit 070fb66

Browse files
changed TestRobot's Handler wrapping for compatibility with RFW<3.0
--HG-- branch : dev
1 parent a11d81c commit 070fb66

File tree

3 files changed

+32
-22
lines changed

3 files changed

+32
-22
lines changed

robottools/testrobot/context.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
from robot.running.namespace import Importer
3030

3131
from .keyword import Keyword
32-
from .handler import Handler
3332

3433

3534
class Context(object):
@@ -89,9 +88,6 @@ def get_handler(self, name):
8988
def get_runner(self, name):
9089
handler = self.get_handler(name)
9190
runner = handler.create_runner(name)
92-
# wrap the handler for Pythonic args/kwargs handling
93-
# as needed by .keyword.Keyword.__call__
94-
runner._handler = Handler(runner._handler)
9591
return runner
9692

9793
def start_keyword(self, keyword):

robottools/testrobot/handler.py

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,29 @@
2626
"""
2727
__all__ = ['Handler']
2828

29-
from moretools import isstring, dictitems
29+
from six import with_metaclass
3030

31+
from moretools import isstring, isdict, dictitems
3132

32-
class Handler(object):
33-
"""A wrapper for instances of classes from ``robot.running.handlers``,
34-
implementing a custom :meth:`.resolve_arguments`,
35-
which supports passing arbitrary python objects
36-
as keyword argument values.
37-
"""
38-
def __init__(self, handler):
39-
"""Create with the `handler` instance to wrap.
40-
"""
41-
self._handler = handler
4233

43-
def __getattr__(self, name):
44-
return getattr(self._handler, name)
34+
class HandlerMeta(type):
35+
36+
def __getitem__(cls, handlercls):
37+
return type('Handler', (cls, handlercls), {
38+
'_resolve_arguments': handlercls.resolve_arguments,
39+
})
4540

41+
42+
class Handler(with_metaclass(HandlerMeta, object)):
43+
"""A wrapper base class for instances of classes
44+
from ``robot.running.handlers``.
45+
46+
* Implements a custom :meth:`.resolve_arguments`,
47+
which supports passing arbitrary python objects
48+
as keyword argument values.
49+
"""
4650
# HACK
47-
def resolve_arguments(self, args_and_kwargs, variables):
51+
def resolve_arguments(self, args_and_kwargs, variables=None):
4852
"""More Pythonic argument handling for interactive
4953
:class:`robottools.testrobot.keyword.Keyword` calls.
5054
@@ -77,13 +81,19 @@ def resolve_arguments(self, args_and_kwargs, variables):
7781
if not isstring(value):
7882
value = repr(value)
7983
rfwargs.append(u'%s=%s' % (name, value))
80-
posargs, rfwkwargslist \
81-
= self._handler.resolve_arguments(rfwargs, variables)
84+
posargs, rfwkwargs = self._resolve_arguments(rfwargs, variables)
8285
# and replace values with original non-string objects after resolving
8386
kwargslist = []
84-
for name, rfwvalue in rfwkwargslist:
87+
if isdict(rfwkwargs):
88+
# ==> RFW < 3.0
89+
rfwkwargs = dictitems(rfwkwargs)
90+
for name, rfwvalue in rfwkwargs:
8591
value = kwargs[name]
8692
if isstring(value):
8793
value = rfwvalue
88-
kwargslist.append(value)
94+
kwargslist.append((name, value))
95+
if hasattr(self, 'run'):
96+
# ==> RFW < 3.0
97+
return posargs, dict(kwargslist)
98+
# RFW >= 3.0
8999
return posargs, kwargslist

robottools/testrobot/keyword.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242

4343
from robottools.library.inspector.keyword import KeywordInspector
4444

45+
from .handler import Handler
46+
4547

4648
def debug_fail(context, exc_info=None):
4749
"""Handles a Keyword FAIL in debugging mode
@@ -125,6 +127,8 @@ def __exit__(self, *exc):
125127
class Keyword(KeywordInspector):
126128
def __init__(self, handler, context, debug=False):
127129
KeywordInspector.__init__(self, handler)
130+
if not isinstance(handler, Handler):
131+
handler.__class__ = Handler[handler.__class__]
128132
self._context = context
129133
self._debug = debug
130134

0 commit comments

Comments
 (0)