@@ -46,7 +46,9 @@ def parse_resource(self, file_path):
4646 model = parsing .TestDataDirectory (source = folder ).populate ()
4747 else :
4848 model = parsing .ResourceFile (file_path ).populate ()
49- return self ._parse_robot_data (file_path , model )
49+ data = self ._parse_robot_data (file_path , model )
50+ data [DBJsonSetting .table_type ] = DBJsonSetting .resource_file
51+ return data
5052 else :
5153 logging .error ('File %s could not be found' , file_path )
5254 raise ValueError (
@@ -56,7 +58,9 @@ def parse_suite(self, file_path):
5658 self .file_path = file_path
5759 if path .exists (file_path ):
5860 model = parsing .TestCaseFile (source = file_path ).populate ()
59- return self ._parse_robot_data (file_path , model )
61+ data = self ._parse_robot_data (file_path , model )
62+ data [DBJsonSetting .table_type ] = DBJsonSetting .suite
63+ return data
6064 else :
6165 logging .error ('File %s could not be found' , file_path )
6266 raise ValueError (
@@ -78,6 +82,7 @@ def parse_variable_file(self, file_path, args=None):
7882 for variable in variables :
7983 var_list .append (variable [0 ])
8084 data [DBJsonSetting .variables ] = sorted (var_list )
85+ data [DBJsonSetting .table_type ] = DBJsonSetting .variable_file
8186 return data
8287
8388 def parse_library (self , library , args = None ):
@@ -116,6 +121,7 @@ def parse_library(self, library, args=None):
116121 if data [DBJsonSetting .keywords ] is None :
117122 raise ValueError ('Library did not contain keywords' )
118123 else :
124+ data [DBJsonSetting .table_type ] = DBJsonSetting .library
119125 return data
120126
121127 def register_console_logger (self ):
@@ -140,8 +146,10 @@ def _parse_python_lib(self, library, args):
140146 else :
141147 import_name = library
142148 importer = Importer ('test library' )
149+ lib_args = self ._argument_strip (lib , args )
143150 libcode = importer .import_class_or_module (
144- import_name , return_source = False )
151+ import_name , instantiate_with_args = lib_args ,
152+ return_source = False )
145153 kw_with_deco = self ._get_keywords_with_robot_name (libcode )
146154 for keyword in lib .keywords :
147155 kw = {}
@@ -155,25 +163,41 @@ def _parse_python_lib(self, library, args):
155163 function_name = keyword .name
156164 kw [DBJsonSetting .keyword_file ] = self ._get_library_kw_source (
157165 libcode , function_name )
166+ # if 'selenium' in str(libcode).lower():
167+ # import pdb; pdb.set_trace() # breakpoint 402cb44b //
158168 kws [strip_and_lower (keyword .name )] = kw
159169 return kws
160170
161- def _get_keywords_with_robot_name (self , libcode ):
171+ def _argument_strip (self , lib , given_args ):
172+ formated_args = []
173+ if not given_args :
174+ return formated_args
175+ try :
176+ default_args = lib .inits [0 ].args
177+ except IndexError :
178+ default_args = []
179+ for default_arg in default_args :
180+ if '=' in default_arg :
181+ default_parts = default_arg .split ('=' , 1 )
182+ formated_args .append (default_parts [1 ])
183+ else :
184+ formated_args .append (default_arg )
185+ return formated_args
186+
187+ def _get_keywords_with_robot_name (self , lib_instance ):
162188 """Returns keywords which uses Robot keyword decorator with robot_name
163189
164- The keyword name can be chaned with Robot Framework keyword decorator
165- and by using the robot_name attribute. Return dictinionary which key is
166- the value of the robot_name attribute and the orinal function name.
190+ The keyword name can be changed with Robot Framework keyword decorator
191+ and by using the robot_name attribute. Return dictionary which key is
192+ the value of the robot_name attribute and the original function name.
167193 """
168194 kw_deco = {}
169- for key in libcode .__dict__ :
170- if callable (libcode .__dict__ [key ]):
171- try :
172- if 'robot_name' in libcode .__dict__ [key ].__dict__ :
173- kw = libcode .__dict__ [key ].__dict__ ['robot_name' ]
174- kw_deco [kw ] = key
175- except AttributeError :
176- pass
195+ lib_class = type (lib_instance )
196+ for name in dir (lib_instance ):
197+ owner = lib_class if hasattr (lib_class , name ) else lib_instance
198+ method_attrib = getattr (owner , name )
199+ if hasattr (method_attrib , 'robot_name' ) and method_attrib .robot_name :
200+ kw_deco [method_attrib .robot_name ] = name
177201 return kw_deco
178202
179203 def _get_library_kw_source (self , libcode , keyword ):
@@ -182,12 +206,15 @@ def _get_library_kw_source(self, libcode, keyword):
182206 func_file = None
183207 if hasattr (libcode , kw_func ):
184208 func = getattr (libcode , kw_func )
209+ else :
210+ func_file , func = None , None
185211 if func :
186- kw_class = self .get_class_that_defined_method (func )
187- if kw_class :
188- func_file = self .get_function_file (kw_class )
189- else :
190- func_file = self .get_function_file (func )
212+ # kw_class = self.get_class_that_defined_method(func)
213+ # if kw_class:
214+ # func_file = self.get_function_file(kw_class)
215+ # else:
216+ # func_file = self.get_function_file(func)
217+ return func .__code__ .co_filename
191218 return func_file
192219
193220 def get_class_that_defined_method (self , meth ):
0 commit comments