How to use _load_from_runbook method in lisa

Best Python code snippet using lisa_python

variable.py

Source:variable.py Github

copy

Full Screen

...83 merge_variables(current_variables, cmd_variables)84 final_variables: Dict[str, VariableEntry] = {}85 merge_variables(86 final_variables,87 _load_from_runbook(runbook_data, higher_level_variables=current_variables),88 )89 if isinstance(higher_level_variables, dict):90 merge_variables(final_variables, higher_level_variables)91 else:92 merge_variables(final_variables, env_variables)93 merge_variables(final_variables, cmd_variables)94 return final_variables95def merge_variables(96 variables: Dict[str, VariableEntry], new_variables: Dict[str, VariableEntry]97) -> None:98 """99 in place update variables. If variables don't exist, will create them100 """101 for name, new_variable in new_variables.items():102 variable = variables.get(name, None)103 if variable:104 variable.update(new_variable)105 else:106 variables[name] = new_variable.copy()107def _get_undefined_variables(108 value: str, variables: Dict[str, VariableEntry]109) -> List[str]:110 undefined_variables: List[str] = []111 # check if there is variable or not in a value112 matches = _VARIABLE_PATTERN.findall(value)113 for variable_name in matches:114 lower_variable_name = variable_name[2:-1].lower()115 if lower_variable_name not in variables:116 undefined_variables.append(variable_name)117 return undefined_variables118def _load_from_env() -> Dict[str, VariableEntry]:119 results: Dict[str, VariableEntry] = {}120 for env_name in os.environ:121 is_lisa_variable = True122 is_secret = False123 name = ""124 if env_name.startswith(_ENV_START):125 name = env_name[len(_ENV_START) :]126 value = os.environ[env_name]127 elif env_name.startswith(_SECRET_ENV_START):128 name = env_name[len(_SECRET_ENV_START) :]129 is_secret = True130 else:131 is_lisa_variable = False132 if is_lisa_variable:133 value = os.environ[env_name]134 _add_variable(name, value, results, is_secret=is_secret)135 return results136def _load_from_runbook(137 runbook_data: Any, higher_level_variables: Dict[str, VariableEntry]138) -> Dict[str, VariableEntry]:139 # make a copy to prevent modifying existing dict140 current_variables = higher_level_variables.copy()141 if constants.VARIABLE in runbook_data:142 variable_entries: List[schema.Variable] = schema.load_by_type_many(143 schema.Variable, runbook_data[constants.VARIABLE]144 )145 left_variables = variable_entries.copy()146 undefined_variables: List[str] = []147 is_current_updated = True148 # when is_current_updated, it means one of variable is processed, and149 # it's ok to loop again. If it's false, there are some variables cannot150 # be resolved....

Full Screen

Full Screen

test_variable.py

Source:test_variable.py Github

copy

Full Screen

...231 current_variables: Dict[str, variable.VariableEntry],232 ) -> Any:233 constants.RUNBOOK_PATH = Path(__file__).parent234 variables = self._get_default_variables()235 variables.update(variable._load_from_runbook(data, current_variables))236 data = self._replace_and_validate(variables, secret_variables)237 return data238 def _test_files(239 self, file_name: str, all_secret: bool, secret_variables: Dict[str, str]240 ) -> Any:241 constants.RUNBOOK_PATH = Path(__file__).parent242 variables = self._get_default_variables()243 variables.update(variable._load_from_file(file_name, is_secret=all_secret))244 data = self._replace_and_validate(variables, secret_variables)245 self.assertEqual("normal_value", data["nested"]["normal_value"])246 self.assertEqual("entry_value", data["normal_entry"])247 self.assertEqual("12345678-abcd-efab-cdef-1234567890ab", data["list"][0])248 self.assertEqual(1234567890, data["list"][1]["dictInList"])249 self.assertEqual("abcdefgh", data["headtail"])...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run lisa automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful