Best Python code snippet using lisa_python
executable.py
Source:executable.py
...473 """474 Create a new tool with given arguments. Call it only when a new tool is475 needed. Otherwise, call the get method.476 """477 tool_key = self._get_tool_key(tool_type)478 tool = self._cache.get(tool_key, None)479 if tool:480 del self._cache[tool_key]481 return self.get(tool_type, *args, **kwargs)482 def get(483 self,484 tool_type: Union[Type[T], CustomScriptBuilder, str],485 *args: Any,486 **kwargs: Any,487 ) -> T:488 """489 return a typed subclass of tool or script builder.490 for example,491 echo_tool = node.tools[Echo]492 echo_tool.run("hello")493 """494 if tool_type is CustomScriptBuilder:495 raise LisaException(496 "CustomScriptBuilder should call build to create a script instance"497 )498 tool_key = self._get_tool_key(tool_type)499 tool = self._cache.get(tool_key)500 if tool is None:501 # the Tool is not installed on current node, try to install it.502 tool_log = get_logger("tool", tool_key, self._node.log)503 tool_log.debug(f"initializing tool [{tool_key}]")504 if isinstance(tool_type, CustomScriptBuilder):505 tool = tool_type.build(self._node)506 elif isinstance(tool_type, str):507 raise LisaException(508 f"{tool_type} cannot be found. "509 f"short usage need to get with type before get with name."510 )511 else:512 cast_tool_type = cast(Type[Tool], tool_type)513 tool = cast_tool_type.create(self._node, *args, **kwargs)514 tool.initialize()515 if not tool.exists:516 tool_log.debug(f"'{tool.name}' not installed")517 if tool.can_install:518 tool_log.debug(f"{tool.name} is installing")519 timer = create_timer()520 is_success = tool.install()521 if not is_success:522 raise LisaException(523 f"install '{tool.name}' failed. After installed, "524 f"it cannot be detected."525 )526 tool_log.debug(f"installed in {timer}")527 else:528 raise LisaException(529 f"cannot find [{tool.name}] on [{self._node.name}], "530 f"{self._node.os.__class__.__name__}, "531 f"Remote({self._node.is_remote}) "532 f"and installation of [{tool.name}] isn't enabled in lisa."533 )534 else:535 tool_log.debug("installed already")536 self._cache[tool_key] = tool537 return cast(T, tool)538 def _get_tool_key(self, tool_type: Union[type, CustomScriptBuilder, str]) -> str:539 if isinstance(tool_type, CustomScriptBuilder):540 tool_key = tool_type.name541 elif isinstance(tool_type, str):542 tool_key = tool_type.lower()543 else:544 tool_key = tool_type.__name__.lower()...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!