How to use _one_of_matched method in lisa

Best Python code snippet using lisa_python

search_space.py

Source:search_space.py Github

copy

Full Screen

...141 f"requirement is not max_inclusive"142 )143 else:144 assert isinstance(capability, list), f"actual: {type(capability)}"145 temp_result = _one_of_matched(self, capability)146 if not temp_result.result:147 result.add_reason(148 "no capability matches requirement, "149 f"requirement: {self}, capability: {capability}"150 )151 return result152 def _generate_min_capability(self, capability: Any) -> int:153 if isinstance(capability, int):154 result: int = capability155 elif isinstance(capability, IntRange):156 if self.min < capability.min:157 result = capability.min158 else:159 result = self.min160 else:161 assert isinstance(capability, list), f"actual: {type(capability)}"162 result = self.max if self.max_inclusive else self.max - 1163 for cap_item in capability:164 temp_result = self.check(cap_item)165 if temp_result.result:166 temp_min = self.generate_min_capability(cap_item)167 result = min(temp_min, result)168 return result169 def _intersect(self, capability: Any) -> Any:170 if isinstance(capability, int):171 return capability172 elif isinstance(capability, IntRange):173 result = IntRange(174 min=self.min, max=self.max, max_inclusive=self.max_inclusive175 )176 if self.min < capability.min:177 result.min = capability.min178 if self.max > capability.max:179 result.max = capability.max180 result.max_inclusive = capability.max_inclusive181 elif self.max == capability.max:182 result.max_inclusive = capability.max_inclusive and self.max_inclusive183 else:184 raise NotImplementedError(185 f"IntRange doesn't support other intersect on {type(capability)}."186 )187 return result188CountSpace = Union[int, List[IntRange], IntRange, None]189def decode_count_space(data: Any) -> Any:190 """191 CountSpace is complex to marshmallow, so it needs customized decode.192 Anyway, marshmallow can encode it correctly.193 """194 decoded_data: CountSpace = None195 if data is None or isinstance(data, int) or isinstance(data, IntRange):196 decoded_data = data197 elif isinstance(data, list):198 decoded_data = []199 for item in data:200 if isinstance(item, dict):201 decoded_data.append(IntRange.schema().load(item)) # type: ignore202 else:203 assert isinstance(item, IntRange), f"actual: {type(item)}"204 decoded_data.append(item)205 else:206 assert isinstance(data, dict), f"actual: {type(data)}"207 decoded_data = IntRange.schema().load(data) # type: ignore208 return decoded_data209def _one_of_matched(requirement: Any, capabilities: List[Any]) -> ResultReason:210 result = ResultReason()211 supported = False212 assert isinstance(requirement, RequirementMixin), f"actual: {type(requirement)}"213 for cap_item in capabilities:214 temp_result = requirement.check(cap_item)215 if temp_result.result:216 supported = True217 break218 if not supported:219 result.add_reason("no one meeting requirement")220 return result221@dataclass_json()222@dataclass223class SetSpace(RequirementMixin, Set[T]):224 is_allow_set: bool = False225 items: List[T] = field(default_factory=list)226 def __init__(227 self,228 is_allow_set: Optional[bool] = None,229 items: Optional[Iterable[T]] = None,230 ) -> None:231 self.items: List[T] = []232 if items:233 self.update(items)234 if is_allow_set is not None:235 self.is_allow_set = is_allow_set236 def __repr__(self) -> str:237 return (238 f"allowed:{self.is_allow_set},"239 f"items:[{','.join([str(x) for x in self])}]"240 )241 def __post_init__(self, *args: Any, **kwargs: Any) -> None:242 self.update(self.items)243 def check(self, capability: Any) -> ResultReason:244 result = ResultReason()245 if self.is_allow_set and len(self) > 0 and not capability:246 result.add_reason(247 "if requirements is allow set and len > 0, capability shouldn't be None"248 )249 assert isinstance(capability, SetSpace), f"actual: {type(capability)}"250 assert capability.is_allow_set, "capability must be allow set"251 # if self.options is not None:252 # cap_set = capability.options253 if result.result:254 if self.is_allow_set:255 if not capability.issuperset(self):256 result.add_reason(257 "capability cannot support some of requirements, "258 f"requirement: '{self}'"259 f"capability: '{capability}', "260 )261 else:262 inter_set: Set[Any] = self.intersection(capability)263 if len(inter_set) > 0:264 names: List[str] = []265 for item in inter_set:266 if isinstance(item, type):267 names.append(item.__name__)268 elif isinstance(item, object):269 names.append(item.__class__.__name__)270 else:271 names.append(item)272 result.add_reason(f"requirements excludes {names}")273 return result274 def add(self, element: T) -> None:275 super().add(element)276 self.items.append(element)277 def remove(self, element: T) -> None:278 super().remove(element)279 self.items.remove(element)280 def update(self, *s: Iterable[T]) -> None:281 super().update(*s)282 self.items.extend(*s)283 def _generate_min_capability(self, capability: Any) -> Optional[Set[T]]:284 result: Optional[SetSpace[T]] = None285 if self.is_allow_set and len(self) > 0:286 assert isinstance(capability, SetSpace), f"actual: {type(capability)}"287 result = SetSpace(is_allow_set=self.is_allow_set)288 if len(capability) > 0:289 for item in self:290 if item in capability:291 result.add(item)292 return result293 def _intersect(self, capability: Any) -> Any:294 return self._generate_min_capability(capability)295def decode_set_space(data: Any) -> Any:296 """297 not sure what's reason, __post_init__ won't be called automatically.298 So write this decoder to force it's called on deserializing299 """300 result = None301 if data:302 result = SetSpace.schema().load(data) # type: ignore303 return result304def decode_set_space_by_type(305 data: Any, base_type: Type[T]306) -> Optional[Union[SetSpace[T], T]]:307 if isinstance(data, dict):308 new_data = SetSpace[T](is_allow_set=True)309 types = data.get("items", [])310 for item in types:311 new_data.add(base_type(item)) # type: ignore312 decoded_data: Optional[Union[SetSpace[T], T]] = new_data313 elif isinstance(data, list):314 new_data = SetSpace[T](is_allow_set=True)315 for item in data:316 new_data.add(base_type(item)) # type: ignore317 decoded_data = new_data318 elif isinstance(data, str):319 decoded_data = base_type(data) # type: ignore320 elif isinstance(data, SetSpace):321 decoded_data = data322 else:323 raise LisaException(f"unknown data type: {type(data)}")324 return decoded_data325def check_countspace(requirement: CountSpace, capability: CountSpace) -> ResultReason:326 result = ResultReason()327 if requirement is not None:328 if capability is None:329 result.add_reason(330 "if requirements isn't None, capability shouldn't be None"331 )332 else:333 if isinstance(requirement, int):334 if isinstance(capability, int):335 if requirement != capability:336 result.add_reason(337 "requirement is a number, capability should be exact "338 f"much, but requirement: {requirement}, "339 f"capability: {capability}"340 )341 elif isinstance(capability, IntRange):342 temp_result = capability.check(requirement)343 if not temp_result.result:344 result.add_reason(345 "requirement is a number, capability should include it, "346 f"but requirement: {requirement}, capability: {capability}"347 )348 else:349 assert isinstance(capability, list), f"actual: {type(capability)}"350 temp_requirement = IntRange(min=requirement, max=requirement)351 temp_result = _one_of_matched(temp_requirement, capability)352 if not temp_result.result:353 result.add_reason(354 f"requirement is a number, no capability matched, "355 f"requirement: {requirement}, capability: {capability}"356 )357 elif isinstance(requirement, IntRange):358 result.merge(requirement.check(capability))359 else:360 assert isinstance(requirement, list), f"actual: {type(requirement)}"361 supported = False362 for req_item in requirement:363 temp_result = req_item.check(capability)364 if temp_result.result:365 supported = True...

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