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
3232from inspect import getargspec
3333from functools import partial
3434
3535from moretools import isidentifier
3636
3737from robot .errors import DataError
38- from robot .model import TestSuite
3938from 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
4043try :
4144 from robot .variables import GLOBAL_VARIABLES , init_global_variables
4245except 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
4848from 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),
0 commit comments