How to use _match_cases method in lisa

Best Python code snippet using lisa_python

testselector.py

Source:testselector.py Github

copy

Full Screen

...81 is_matched = criteria_tags in case_tags82 else:83 is_matched = any(x in case_tags for x in criteria_tags)84 return is_matched85def _match_cases(86 candidates: Mapping[str, Union[TestCaseRuntimeData, TestCaseMetadata]],87 patterns: List[Callable[[Union[TestCaseRuntimeData, TestCaseMetadata]], bool]],88) -> Dict[str, TestCaseRuntimeData]:89 changed_cases: Dict[str, TestCaseRuntimeData] = {}90 for candidate_name in candidates:91 candidate = candidates[candidate_name]92 is_matched = all(pattern(candidate) for pattern in patterns)93 if is_matched:94 if isinstance(candidate, TestCaseMetadata):95 candidate = TestCaseRuntimeData(candidate)96 changed_cases[candidate_name] = candidate97 return changed_cases98def _apply_settings(99 applied_case_data: TestCaseRuntimeData, case_runbook: schema.TestCase, action: str100) -> None:101 fields = [102 constants.TESTCASE_TIMES,103 constants.TESTCASE_RETRY,104 constants.TESTCASE_IGNORE_FAILURE,105 constants.ENVIRONMENT,106 ]107 set_filtered_fields(case_runbook, applied_case_data, fields)108 applied_case_data.use_new_environment = (109 applied_case_data.use_new_environment or case_runbook.use_new_environment110 )111 # use default value from selector112 applied_case_data.select_action = action113def _force_check(114 name: str,115 is_force: bool,116 force_expected_set: Set[str],117 force_exclusive_set: Set[str],118 temp_force_exclusive_set: Set[str],119 case_runbook: schema.TestCase,120) -> bool:121 is_skip = False122 if name in force_exclusive_set:123 if is_force:124 raise LisaException(f"case {name} has force conflict on {case_runbook}")125 else:126 temp_force_exclusive_set.add(name)127 is_skip = True128 if not is_skip and is_force:129 force_expected_set.add(name)130 return is_skip131def _apply_filter( # noqa: C901132 case_runbook: schema.TestCase,133 current_selected: Dict[str, TestCaseRuntimeData],134 force_included: Set[str],135 force_excluded: Set[str],136 full_list: Dict[str, TestCaseMetadata],137) -> Dict[str, TestCaseRuntimeData]:138 # TODO: Reduce this function's complexity and remove the disabled warning.139 log = _get_logger()140 # initialize criteria141 patterns: List[Callable[[Union[TestCaseRuntimeData, TestCaseMetadata]], bool]] = []142 criteria_runbook = case_runbook.criteria143 assert criteria_runbook, "test case criteria cannot be None"144 criteria_runbook_dict = criteria_runbook.__dict__145 for runbook_key, runbook_value in criteria_runbook_dict.items():146 # the value may be 0 in priority, it shouldn't be skipped.147 if runbook_value is None or runbook_value == "":148 continue149 if runbook_key in [150 constants.NAME,151 constants.TESTCASE_CRITERIA_AREA,152 constants.TESTCASE_CRITERIA_CATEGORY,153 ]:154 pattern = cast(str, criteria_runbook_dict[runbook_key])155 expression = re.compile(pattern)156 patterns.append(157 partial(_match_string, pattern=expression, attr_name=runbook_key)158 )159 elif runbook_key == constants.TESTCASE_CRITERIA_PRIORITY:160 priority_pattern = cast(161 Union[int, List[int]], criteria_runbook_dict[runbook_key]162 )163 patterns.append(partial(_match_priority, pattern=priority_pattern))164 elif runbook_key == constants.TESTCASE_CRITERIA_TAGS:165 tag_pattern = cast(166 Union[str, List[str]], criteria_runbook_dict[runbook_key]167 )168 patterns.append(partial(_match_tags, criteria_tags=tag_pattern))169 else:170 raise LisaException(f"unknown criteria key: {runbook_key}")171 # match by select Action:172 changed_cases: Dict[str, TestCaseRuntimeData] = {}173 is_force = case_runbook.select_action in [174 constants.TESTCASE_SELECT_ACTION_FORCE_INCLUDE,175 constants.TESTCASE_SELECT_ACTION_FORCE_EXCLUDE,176 ]177 is_update_setting = case_runbook.select_action in [178 constants.TESTCASE_SELECT_ACTION_NONE,179 constants.TESTCASE_SELECT_ACTION_INCLUDE,180 constants.TESTCASE_SELECT_ACTION_FORCE_INCLUDE,181 ]182 temp_force_set: Set[str] = set()183 if case_runbook.select_action == constants.TESTCASE_SELECT_ACTION_NONE:184 # Just apply settings on test cases185 changed_cases = _match_cases(current_selected, patterns)186 elif case_runbook.select_action in [187 constants.TESTCASE_SELECT_ACTION_INCLUDE,188 constants.TESTCASE_SELECT_ACTION_FORCE_INCLUDE,189 ]:190 # to include cases191 changed_cases = _match_cases(full_list, patterns)192 for name, new_case_data in changed_cases.items():193 is_skip = _force_check(194 name,195 is_force,196 force_included,197 force_excluded,198 temp_force_set,199 case_runbook,200 )201 if is_skip:202 continue203 # reuse original test cases204 case_data = current_selected.get(name, new_case_data)205 current_selected[name] = case_data206 changed_cases[name] = case_data207 elif case_runbook.select_action in [208 constants.TESTCASE_SELECT_ACTION_EXCLUDE,209 constants.TESTCASE_SELECT_ACTION_FORCE_EXCLUDE,210 ]:211 changed_cases = _match_cases(current_selected, patterns)212 for name in changed_cases:213 is_skip = _force_check(214 name,215 is_force,216 force_excluded,217 force_included,218 temp_force_set,219 case_runbook,220 )221 if is_skip:222 continue223 del current_selected[name]224 else:225 raise LisaException(f"unknown selectAction: '{case_runbook.select_action}'")...

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