def _handle_lib_import(self, func, args, kwargs): libs = [] errors = [] lib_cached = self._get_lib_from_cache(args[0], args[1]) if lib_cached: libs.append(lib_cached.lib) errors = lib_cached.errors else: try: def to_call(): try: libs.append(func(*args, **kwargs)) except: errors.append(sys.exc_info()) t = threading.Thread(target=to_call) t.setDaemon(True) t.start() t.join(timeout=self.lib_import_timeout) except: errors.append(sys.exc_info()) if len(libs) > 0: library = libs[0] else: try: library = TestLibrary(args[0], args[1], args[2], create_handlers=False) except: try: library = _BaseTestLibrary(libcode=None, name=args[0], args=args[1], source=None, variables=args[2]) except: try: library = _BaseTestLibrary(libcode=None, name=args[0], args=[], source=None, variables=args[3]) except: errors.append(sys.exc_info()) if lib_cached is None: self.cached_lib_items.append( LibItem(args[0], args[1], library, errors)) for e in errors: msg = '{LIB_ERROR: ' + args[0] + ', value: VALUE_START(' + str( e) + ')VALUE_END, lib_file_import:' + str(library.source) + '}' LOGGER.message(Message(message=msg, level='FAIL')) self._handle_keywords(library) return library
def _wrap(self, func, argser, kwargs): if type(func) == MethodType: if func.__name__ == 'import_library': # print str(argser) q = [] errors = [] lib_cached = self.get_from_cache(argser[0], argser[1]) if lib_cached: q.append(lib_cached.result) errors = lib_cached.errors else: try: t = threading.Thread(target=self._imp, args=(func, q, errors, argser), kwargs=kwargs) t.setDaemon(True) t.start() t.join(timeout=int(self.lib_import_timeout)) except: errors.append(sys.exc_info()) if len(q) > 0: result = q[0] else: try: result = TestLibrary(argser[0], argser[1], argser[2], create_handlers=False) except: try: result = _BaseTestLibrary(libcode=None, name=argser[0], args=argser[1], source=None, variables=argser[2]) except: try: result = _BaseTestLibrary(libcode=None, name=argser[0], args=[], source=None, variables=argser[3]) except: errors.append(sys.exc_info()) if lib_cached is None: lib = LibItem(argser[0], argser[1]) lib.result = result lib.errors = errors self.cached_lib_items.append(lib) for p in errors: msg = Message(message='{LIB_ERROR: ' + argser[0] + ', value: VALUE_START(' + str( p) + ')VALUE_END, lib_file_import:' + str(result.source) + '}', level='FAIL') LOGGER.message(msg) else: result = func(*argser, **kwargs) else: result = func(self.obj, *argser, **kwargs) return result
def _handle_lib_import(self, func, args, kwargs): libs = [] errors = [] lib_cached = self._get_lib_from_cache(args[0], args[1]) if lib_cached: libs.append(lib_cached.lib) errors = lib_cached.errors else: try: def to_call(): try: libs.append(func(*args, **kwargs)) except: errors.append(sys.exc_info()) t = threading.Thread(target=to_call) t.setDaemon(True) t.start() t.join(timeout=self.lib_import_timeout) except: errors.append(sys.exc_info()) if len(libs) > 0: library = libs[0] else: try: library = TestLibrary(args[0], args[1], args[2], create_handlers=False) except: try: library = _BaseTestLibrary(libcode=None, name=args[0], args=args[1], source=None, variables=args[2]) except: try: library = _BaseTestLibrary(libcode=None, name=args[0], args=[], source=None, variables=args[3]) except: errors.append(sys.exc_info()) if lib_cached is None: self.cached_lib_items.append(LibItem(args[0], args[1], library, errors)) for e in errors: msg = json.dumps({'import_error': {'name': args[0], 'error': str(e)}}) LOGGER.message(Message(message=msg, level='NONE')) if self.handle_keywords: self._handle_keywords(library) return library
def _handle_lib_import(self, func, args, kwargs): libs = [] errors = [] lib_cached = self._get_lib_from_cache(args[0], args[1]) if lib_cached: libs.append(lib_cached.lib) errors = lib_cached.errors else: try: # this is required to not get blocked thread in code using gevent; if it's not supported # the sleep function is just void if self.support_gevent: from gevent import monkey, sleep monkey.patch_all() else: sleep = lambda: None def to_call(): try: libs.append(func(*args, **kwargs)) sleep() except: errors.append(sys.exc_info()) t = threading.Thread(target=to_call) t.setDaemon(True) t.start() t.join(timeout=self.lib_import_timeout) except: errors.append(sys.exc_info()) if len(libs) > 0: library = libs[0] else: try: library = TestLibrary(args[0], args[1], args[2], create_handlers=False) except: try: library = _BaseTestLibrary(libcode=None, name=args[0], args=args[1], source=None, variables=args[2]) except: try: library = _BaseTestLibrary(libcode=None, name=args[0], args=[], source=None, variables=args[3]) except: errors.append(sys.exc_info()) if lib_cached is None: self.cached_lib_items.append( LibItem(args[0], args[1], library, errors)) for e in errors: msg = json.dumps( {'import_error': { 'name': args[0], 'error': str(e) }}) LOGGER.message(Message(message=msg, level='NONE')) if self.handle_keywords: self._handle_keywords(library) return library
def _create_base_test_library(self, name, args, variables): if self.robot_version < (3, 2): return _BaseTestLibrary(libcode=None, name=name, args=args, source=None, variables=variables) else: return _BaseTestLibrary(libcode=None, name=name, args=args, source=None, logger=None, variables=variables)