How to use _replace_variables method in lisa

Best Python code snippet using lisa_python

tablesetter.py

Source:tablesetter.py Github

copy

Full Screen

...49 def _format_values(self, values):50 return values51 def resolve(self, variables):52 with self._avoid_recursion:53 return self._replace_variables(self._values, variables)54 @property55 @contextmanager56 def _avoid_recursion(self):57 if self._resolving:58 raise DataError('Recursive variable definition.')59 self._resolving = True60 try:61 yield62 finally:63 self._resolving = False64 def _replace_variables(self, value, variables):65 raise NotImplementedError66 def report_error(self, error):67 if self._error_reporter:68 self._error_reporter(unic(error))69class ScalarVariableTableValue(VariableTableValueBase):70 def _format_values(self, values):71 separator = None72 if is_string(values):73 values = [values]74 elif values and values[0].startswith('SEPARATOR='):75 separator = values[0][10:]76 values = values[1:]77 return separator, values78 def _replace_variables(self, values, variables):79 separator, values = values80 # Avoid converting single value to string.81 if self._is_single_value(separator, values):82 return variables.replace_scalar(values[0])83 if separator is None:84 separator = ' '85 separator = variables.replace_string(separator)86 values = variables.replace_list(values)87 return separator.join(unic(item) for item in values)88 def _is_single_value(self, separator, values):89 return (separator is None and len(values) == 1 and90 not is_list_variable(values[0]))91class ListVariableTableValue(VariableTableValueBase):92 def _replace_variables(self, values, variables):93 return variables.replace_list(values)94class DictVariableTableValue(VariableTableValueBase):95 def _format_values(self, values):96 return list(self._yield_formatted(values))97 def _yield_formatted(self, values):98 for item in values:99 if is_dict_variable(item):100 yield item101 else:102 name, value = split_from_equals(item)103 if value is None:104 raise DataError(105 "Invalid dictionary variable item '%s'. "106 "Items must use 'name=value' syntax or be dictionary "107 "variables themselves." % item108 )109 yield name, value110 def _replace_variables(self, values, variables):111 try:112 return DotDict(self._yield_replaced(values,113 variables.replace_scalar))114 except TypeError as err:115 raise DataError('Creating dictionary failed: %s' % err)116 def _yield_replaced(self, values, replace_scalar):117 for item in values:118 if isinstance(item, tuple):119 key, values = item120 yield replace_scalar(key), replace_scalar(values)121 else:122 for key, values in replace_scalar(item).items():...

Full Screen

Full Screen

lift_definition.py

Source:lift_definition.py Github

copy

Full Screen

...7def resolve_lift_definition(lift_def: str, parameters: dict):8 # Retrive and process lift definition9 lift_definition = fetch_lift_definition(lift_def)10 # Parse the lift definition11 return _replace_variables(lift_definition, parameters)12def fetch_lift_definition(lift_def: str) -> dict:13 """Load yaml string or fetch lift definition from s3."""14 if lift_def.startswith("s3://") or lift_def.startswith("s3a://"):15 lift_def = S3Path(lift_def).read_text()16 return yaml.safe_load(lift_def)17def _replace_variables(var: Union[dict, list, str, int, bool], params: dict):18 """Replace all the variables with the given parameters."""19 if isinstance(var, dict):20 return {key: _replace_variables(value, params) for key, value in var.items()}21 if isinstance(var, list):22 return [_replace_variables(value, params) for value in var]23 if isinstance(var, str):24 # Check if the format is "${myVar}" or "${myVar} + extra string"25 if re.match(r"^\$\{\w+\}$", var):26 # Return the raw param27 return params[var[2:-1]]28 # Use string replacement29 return string.Template(var).substitute(params)30 # Do nothing for int and bool...

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