How to use _generate_transformers_runbook method in lisa

Best Python code snippet using lisa_python

test_transformer.py

Source:test_transformer.py Github

copy

Full Screen

...36 return result37class TestTransformerCase(TestCase):38 def test_transformer_ordered(self) -> None:39 # transformers are sorted by the dependent order40 transformers = self._generate_transformers_runbook(3)41 transformers[0].depends_on = ["t1", "t2"]42 transformers[1].depends_on = ["t2"]43 transformers = transformer._sort(transformers)44 self.assertEqual("t2", transformers[0].name)45 self.assertEqual("t1", transformers[1].name)46 self.assertEqual("t0", transformers[2].name)47 def test_transformer_cycle_detection(self) -> None:48 # cycle reference and raise exception49 transformers = self._generate_transformers_runbook(3)50 transformers[0].depends_on = ["t1", "t2"]51 transformers[1].depends_on = ["t0"]52 with self.assertRaises(LisaException) as cm:53 transformers = transformer._sort(transformers)54 self.assertEqual(55 "found cycle dependent transformers: 't1' and 't0'", str(cm.exception)56 )57 def test_transformer_keep_all_values(self) -> None:58 # no value is overridden, all values are kept59 transformers = self._generate_transformers_runbook(2)60 runbook_builder = self._generate_runbook_builder(transformers)61 result = transformer._run_transformers(runbook_builder)62 self._validate_variables(63 {64 "v0": "original",65 "va": "original",66 "t0_v0": "0_0 processed",67 "t1_v0": "1_0 processed",68 "t1_v1": "1_1 processed",69 },70 result,71 )72 def test_transformer_overridden_values(self) -> None:73 # value is overridden74 transformers = self._generate_transformers_runbook(2)75 transformers[0].rename = {"t0_v0": "v0"}76 transformers[1].rename = {"t1_v0": "v0", "t1_v1": "v1"}77 runbook_builder = self._generate_runbook_builder(transformers)78 result = transformer._run_transformers(runbook_builder)79 self._validate_variables(80 {81 "va": "original",82 "v0": "1_0 processed",83 "v1": "1_1 processed",84 },85 result,86 )87 def test_transformer_rename_not_exist(self) -> None:88 # not exist name raise exception89 transformers = self._generate_transformers_runbook(1)90 transformers[0].rename = {"v0": "v0_1"}91 runbook_builder = self._generate_runbook_builder(transformers)92 with self.assertRaises(LisaException) as cm:93 transformer._run_transformers(runbook_builder)94 self.assertEqual("unmatched rename variable: {'v0': 'v0_1'}", str(cm.exception))95 def test_transformer_customized_prefix(self) -> None:96 # modified prefix97 transformers = self._generate_transformers_runbook(1)98 transformers[0].prefix = "v0_1"99 runbook_builder = self._generate_runbook_builder(transformers)100 result = transformer._run_transformers(runbook_builder)101 self._validate_variables(102 {103 "v0": "original",104 "va": "original",105 "v0_1_v0": "0_0 processed",106 },107 result,108 )109 def test_transformer_no_name(self) -> None:110 # no name, the type will be used. in name111 transformers_data: List[Any] = [{"type": MOCK, "items": {"v0": "v0_1"}}]112 transformers = schema.load_by_type_many(schema.Transformer, transformers_data)113 runbook_builder = self._generate_runbook_builder(transformers)114 result = transformer._run_transformers(runbook_builder)115 self._validate_variables(116 {117 "v0": "original",118 "va": "original",119 "mock_v0": "v0_1 processed",120 },121 result,122 )123 def test_transformer_skip_disabled(self) -> None:124 # the second transformer should be skipped, so the value is original.125 transformers = self._generate_transformers_runbook(2)126 transformers[0].rename = {"t0_v0": "v0"}127 transformers[0].enabled = False128 runbook_builder = self._generate_runbook_builder(transformers)129 result = transformer._run_transformers(runbook_builder)130 self._validate_variables(131 {132 "v0": "original",133 "va": "original",134 "t1_v0": "1_0 processed",135 "t1_v1": "1_1 processed",136 },137 result,138 )139 def _validate_variables(140 self, expected: Dict[str, str], actual: Dict[str, VariableEntry]141 ) -> None:142 actual_pairs = {name: value.data for name, value in actual.items()}143 self.assertDictEqual(expected, actual_pairs)144 def _generate_runbook_builder(145 self, transformers: List[schema.Transformer]146 ) -> RunbookBuilder:147 transformers_data: List[Any] = [148 x.to_dict() for x in transformers # type:ignore149 ]150 runbook_builder = RunbookBuilder(Path("mock_runbook.yml"))151 runbook_builder._raw_data = {152 constants.TRANSFORMER: transformers_data,153 }154 runbook_builder._variables = {155 "v0": VariableEntry("v0", "original"),156 "va": VariableEntry("va", "original"),157 }158 return runbook_builder159 def _generate_transformers_runbook(self, count: int) -> List[schema.Transformer]:160 results: List[schema.Transformer] = []161 for index in range(count):162 items: Dict[str, str] = dict()163 for item_index in range(index + 1):164 items[f"v{item_index}"] = f"{index}_{item_index}"165 runbook: schema.Transformer = schema.load_by_type(166 schema.Transformer, {"type": MOCK, "name": f"t{index}", "items": items}167 )168 results.append(runbook)...

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