How to use generate_min_capability method in lisa

Best Python code snippet using lisa_python

search_space.py

Source:search_space.py Github

copy

Full Screen

...42 self.add_reason(reason, name)43class RequirementMixin:44 def check(self, capability: Any) -> ResultReason:45 raise NotImplementedError()46 def generate_min_capability(self, capability: Any) -> Any:47 self._validate_result(capability)48 return self._generate_min_capability(capability)49 def intersect(self, capability: Any) -> Any:50 self._validate_result(capability)51 return self._intersect(capability)52 def _call_requirement_method(self, method_name: str, capability: Any) -> Any:53 raise NotImplementedError(method_name)54 def _generate_min_capability(self, capability: Any) -> Any:55 return self._call_requirement_method(56 method_name=RequirementMethod.generate_min_capability,57 capability=capability,58 )59 def _intersect(self, capability: Any) -> Any:60 return self._call_requirement_method(61 method_name=RequirementMethod.intersect, capability=capability62 )63 def _validate_result(self, capability: Any) -> None:64 check_result = self.check(capability)65 if not check_result.result:66 raise NotMeetRequirementException(67 f"capability doesn't support requirement: {check_result.reasons}"68 )69T_SEARCH_SPACE = TypeVar("T_SEARCH_SPACE", bound=RequirementMixin)70@dataclass_json()71@dataclass72class IntRange(RequirementMixin):73 min: int = 074 max: int = field(default=sys.maxsize)75 max_inclusive: bool = True76 def __post_init__(self, *args: Any, **kwargs: Any) -> None:77 if self.min > self.max:78 raise LisaException(79 f"min: {self.min} shouldn't be greater than max: {self.max}"80 )81 elif self.min == self.max and self.max_inclusive is False:82 raise LisaException(83 "min shouldn't be equal to max, if max_includes is False."84 )85 def __repr__(self) -> str:86 max_value = self.max if self.max < sys.maxsize else ""87 max_inclusive = ""88 if max_value:89 max_inclusive = "(inc)" if self.max_inclusive else "(exc)"90 return f"[{self.min},{max_value}{max_inclusive}]"91 def __eq__(self, __o: object) -> bool:92 assert isinstance(__o, IntRange), f"actual type: {type(__o)}"93 return (94 self.min == __o.min95 and self.max == __o.max96 and self.max_inclusive == __o.max_inclusive97 )98 def check(self, capability: Any) -> ResultReason:99 result = ResultReason()100 if capability is None:101 result.add_reason("capability shouldn't be None")102 else:103 if isinstance(capability, IntRange):104 if capability.max < self.min:105 result.add_reason(106 f"capability max({capability.max}) is "107 f"smaller than requirement min({self.min})"108 )109 elif capability.max == self.min and not capability.max_inclusive:110 result.add_reason(111 f"capability max({capability.max}) equals "112 f"to requirement min({self.min}), but "113 f"capability is not max_inclusive"114 )115 elif capability.min > self.max:116 result.add_reason(117 f"capability min({capability.min}) is "118 f"bigger than requirement max({self.max})"119 )120 elif capability.min == self.max and not self.max_inclusive:121 result.add_reason(122 f"capability min({capability.min}) equals "123 f"to requirement max({self.max}), but "124 f"requirement is not max_inclusive"125 )126 elif isinstance(capability, int):127 if capability < self.min:128 result.add_reason(129 f"capability({capability}) is "130 f"smaller than requirement min({self.min})"131 )132 elif capability > self.max:133 result.add_reason(134 f"capability ({capability}) is "135 f"bigger than requirement max({self.max})"136 )137 elif capability == self.max and not self.max_inclusive:138 result.add_reason(139 f"capability({capability}) equals "140 f"to requirement max({self.max}), but "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 = True366 if not supported:367 result.add_reason(368 "no capability matches requirement, "369 f"requirement: {requirement}, capability: {capability}"370 )371 return result372def generate_min_capability_countspace(373 requirement: CountSpace, capability: CountSpace374) -> int:375 check_result = check_countspace(requirement, capability)376 if not check_result.result:377 raise NotMeetRequirementException(378 "cannot get min value, capability doesn't support requirement: "379 f"{check_result.reasons}"380 )381 if requirement is None:382 if capability:383 requirement = capability384 result: int = sys.maxsize385 else:386 result = 0387 if isinstance(requirement, int):388 result = requirement389 elif isinstance(requirement, IntRange):390 result = requirement.generate_min_capability(capability)391 else:392 assert isinstance(requirement, list), f"actual: {type(requirement)}"393 result = sys.maxsize394 for req_item in requirement:395 temp_result = req_item.check(capability)396 if temp_result.result:397 temp_min = req_item.generate_min_capability(capability)398 result = min(result, temp_min)399 return result400def intersect_countspace(requirement: CountSpace, capability: CountSpace) -> Any:401 check_result = check_countspace(requirement, capability)402 if not check_result.result:403 raise NotMeetRequirementException(404 "cannot get intersect, capability doesn't support requirement: "405 f"{check_result.reasons}"406 )407 if requirement is None and capability:408 return copy.copy(capability)409 if isinstance(requirement, int):410 result = requirement411 elif isinstance(requirement, IntRange):412 result = requirement.intersect(capability)413 else:414 raise LisaException(415 f"not support to get intersect on countspace type: {type(requirement)}"416 )417 return result418def check_setspace(419 requirement: Optional[Union[SetSpace[T], T]],420 capability: Optional[Union[SetSpace[T], T]],421) -> ResultReason:422 result = ResultReason()423 if capability is None:424 result.add_reason("capability shouldn't be None")425 else:426 if requirement is not None:427 has_met_check = False428 if not isinstance(capability, SetSpace):429 capability = SetSpace[T](items=[capability])430 if not isinstance(requirement, SetSpace):431 requirement = SetSpace[T](items=[requirement])432 for item in requirement:433 if item in capability:434 has_met_check = True435 break436 if not has_met_check:437 result.add_reason(438 f"requirement not supported in capability. "439 f"requirement: {requirement}, "440 f"capability: {capability}"441 )442 return result443def generate_min_capability_setspace_by_priority(444 requirement: Optional[Union[SetSpace[T], T]],445 capability: Optional[Union[SetSpace[T], T]],446 priority_list: List[T],447) -> T:448 check_result = check_setspace(requirement, capability)449 if not check_result.result:450 raise NotMeetRequirementException(451 "cannot get min value, capability doesn't support requirement"452 f"{check_result.reasons}"453 )454 assert capability is not None, "Capability shouldn't be None"455 # Ensure that both cap and req are instance of SetSpace456 if not isinstance(capability, SetSpace):457 capability = SetSpace[T](items=[capability])458 if requirement is None:459 requirement = capability460 if not isinstance(requirement, SetSpace):461 requirement = SetSpace[T](items=[requirement])462 # Find min capability463 min_cap: Optional[T] = None464 for item in priority_list:465 if item in requirement and item in capability:466 min_cap = item467 break468 assert min_cap, (469 "Cannot find min capability on data path, "470 f"requirement: {requirement}"471 f"capability: {capability}"472 )473 return min_cap474def intersect_setspace_by_priority(475 requirement: Optional[Union[SetSpace[T], T]],476 capability: Optional[Union[SetSpace[T], T]],477 priority_list: List[T],478) -> Any:479 # intersect doesn't need to take care about priority.480 check_result = check_setspace(requirement, capability)481 if not check_result.result:482 raise NotMeetRequirementException(483 f"capability doesn't support requirement: {check_result.reasons}"484 )485 assert capability is not None, "Capability shouldn't be None"486 value = SetSpace[T]()487 # Ensure that both cap and req are instance of SetSpace488 if not isinstance(capability, SetSpace):489 capability = SetSpace[T](items=[capability])490 if requirement is None:491 requirement = capability492 if not isinstance(requirement, SetSpace):493 requirement = SetSpace[T](items=[requirement])494 # Find min capability495 for item in requirement:496 if item in capability:497 value.add(item)498 return value499def count_space_to_int_range(count_space: CountSpace) -> IntRange:500 if count_space is None:501 result = IntRange(min=sys.maxsize * -1, max=sys.maxsize)502 elif isinstance(count_space, int):503 result = IntRange(min=count_space, max=count_space)504 elif isinstance(count_space, IntRange):505 result = count_space506 else:507 raise LisaException(508 f"unsupported type: {type(count_space)}, value: '{count_space}'"509 )510 return result511def check(512 requirement: Union[T_SEARCH_SPACE, List[T_SEARCH_SPACE], None],513 capability: Union[T_SEARCH_SPACE, List[T_SEARCH_SPACE], None],514) -> ResultReason:515 result = ResultReason()516 if requirement is not None:517 if capability is None:518 result.add_reason(519 f"capability shouldn't be None, requirement: [{requirement}]"520 )521 elif isinstance(requirement, (list)):522 supported = False523 for req_item in requirement:524 temp_result = req_item.check(capability)525 if temp_result.result:526 supported = True527 if not supported:528 result.add_reason(529 "no capability meet any of requirement, "530 f"requirement: {requirement}, capability: {capability}"531 )532 else:533 result.merge(requirement.check(capability))534 return result535def _call_requirement_method(536 method: str,537 requirement: Union[T_SEARCH_SPACE, List[T_SEARCH_SPACE], None],538 capability: Union[T_SEARCH_SPACE, List[T_SEARCH_SPACE], None],539) -> Any:540 check_result = check(requirement, capability)541 if not check_result.result:542 raise NotMeetRequirementException(543 f"cannot call {method}, capability doesn't support requirement"544 )545 result: Optional[T_SEARCH_SPACE] = None546 if requirement is None:547 if capability is not None:548 requirement = capability549 if (550 isinstance(requirement, list)551 and method == RequirementMethod.generate_min_capability552 ):553 result = None554 for req_item in requirement:555 temp_result = req_item.check(capability)556 if temp_result.result:557 temp_min = getattr(req_item, method)(capability)558 if result is None:559 result = temp_min560 else:561 # TODO: multiple matches found, not supported well yet562 # It can be improved by implement __eq__, __lt__ functions.563 result = min(result, temp_min)564 elif requirement is not None:565 result = getattr(requirement, method)(capability)566 return result567def generate_min_capability(568 requirement: Union[T_SEARCH_SPACE, List[T_SEARCH_SPACE], None],569 capability: Union[T_SEARCH_SPACE, List[T_SEARCH_SPACE], None],570) -> Any:571 return _call_requirement_method(572 RequirementMethod.generate_min_capability,573 requirement=requirement,574 capability=capability,575 )576def intersect(577 requirement: Union[T_SEARCH_SPACE, List[T_SEARCH_SPACE], None],578 capability: Union[T_SEARCH_SPACE, List[T_SEARCH_SPACE], None],579) -> Any:580 return _call_requirement_method(581 RequirementMethod.intersect, requirement=requirement, capability=capability...

Full Screen

Full Screen

test_env_requirement.py

Source:test_env_requirement.py Github

copy

Full Screen

...37 check(self.environment, capability.environment),38 name="environment",39 )40 return result41 def _generate_min_capability(self, capability: Any) -> Any:42 assert isinstance(43 capability, UtTestCaseRequirement44 ), f"actual: {type(capability)}"45 environment = generate_min_capability(self.environment, capability.environment)46 platform_type = generate_min_capability(47 self.platform_type, capability.platform_type48 )49 os = generate_min_capability(self.os_type, capability.os_type)50 result = TestCaseSchema(51 environment=environment, platform_type=platform_type, operating_system=os52 )53 return result54def ut_simple_requirement(55 min_count: int = 1,56 supported_platform_type: Optional[List[str]] = None,57 unsupported_platform_type: Optional[List[str]] = None,58 supported_os: Optional[List[Type[OperatingSystem]]] = None,59 unsupported_os: Optional[List[Type[OperatingSystem]]] = None,60) -> UtTestCaseRequirement:61 simple = simple_requirement(62 min_count=min_count,63 supported_platform_type=supported_platform_type,64 unsupported_platform_type=unsupported_platform_type,65 supported_os=supported_os,66 unsupported_os=unsupported_os,67 )68 return UtTestCaseRequirement(69 environment=simple.environment,70 platform_type=simple.platform_type,71 os_type=simple.os_type,72 )73def ut_node_requirement(74 node: schema.NodeSpace,75 supported_platform_type: Optional[List[str]] = None,76 unsupported_platform_type: Optional[List[str]] = None,77 supported_os: Optional[List[Type[OperatingSystem]]] = None,78 unsupported_os: Optional[List[Type[OperatingSystem]]] = None,79) -> UtTestCaseRequirement:80 node_require = node_requirement(81 node,82 supported_platform_type,83 unsupported_platform_type,84 supported_os,85 unsupported_os,86 )87 return UtTestCaseRequirement(88 environment=node_require.environment,89 platform_type=node_require.platform_type,90 os_type=node_require.os_type,91 )92UT_DEFAULT_REQUIREMENT = UtTestCaseRequirement(93 environment=DEFAULT_REQUIREMENT.environment,94 platform_type=DEFAULT_REQUIREMENT.platform_type,95 os_type=SetSpace(is_allow_set=True, items=[Linux]),96)97class RequirementTestCase(SearchSpaceTestCase):98 def test_supported_simple_requirement(self) -> None:99 n1 = schema.NodeSpace()100 n1 = n1.generate_min_capability(n1)101 n4 = schema.load_by_type(102 schema.NodeSpace,103 {"type": constants.ENVIRONMENTS_NODES_REQUIREMENT, "core_count": 4},104 )105 n4 = n4.generate_min_capability(n4)106 n4g1 = schema.load_by_type(107 schema.NodeSpace,108 {109 "type": constants.ENVIRONMENTS_NODES_REQUIREMENT,110 "core_count": 4,111 "gpu_count": 1,112 },113 )114 n4g1 = n4g1.generate_min_capability(n4g1)115 n6 = schema.load_by_type(116 schema.NodeSpace,117 {"type": constants.ENVIRONMENTS_NODES_REQUIREMENT, "core_count": 6},118 )119 n6 = n6.generate_min_capability(n6)120 n6g2 = schema.load_by_type(121 schema.NodeSpace,122 {123 "type": constants.ENVIRONMENTS_NODES_REQUIREMENT,124 "core_count": 6,125 "gpu_count": 2,126 },127 )128 n6g2 = n6g2.generate_min_capability(n6g2)129 n6g1 = schema.load_by_type(130 schema.NodeSpace,131 {132 "type": constants.ENVIRONMENTS_NODES_REQUIREMENT,133 "core_count": 6,134 "gpu_count": 1,135 },136 )137 n6g1 = n6g1.generate_min_capability(n6g1)138 n10 = schema.load_by_type(139 schema.NodeSpace,140 {"type": constants.ENVIRONMENTS_NODES_REQUIREMENT, "core_count": 10},141 )142 n10 = n10.generate_min_capability(n10)143 partial_testcase_schema = partial(144 TestCaseSchema,145 platform_type=None,146 operating_system=SetSpace(is_allow_set=True, items=[Linux]),147 )148 s11 = partial_testcase_schema(environment=EnvironmentSpace())149 s11.environment.nodes = [n1]150 s14 = partial_testcase_schema(environment=EnvironmentSpace())151 s14.environment.nodes = [n4]152 s14g1 = partial_testcase_schema(environment=EnvironmentSpace())153 s14g1.environment.nodes = [n4g1]154 s24 = partial_testcase_schema(environment=EnvironmentSpace())155 s24.environment.nodes = [n4, n4]156 s16 = partial_testcase_schema(environment=EnvironmentSpace())...

Full Screen

Full Screen

test_search_space.py

Source:test_search_space.py Github

copy

Full Screen

...26 number: CountSpace = IntRange(min=1, max=5)27 def check(self, capability: Any) -> ResultReason:28 assert isinstance(capability, MockItem), f"actual: {type(capability)}"29 return check_countspace(self.number, capability.number)30 def _generate_min_capability(self, capability: Any) -> MockSchema:31 result = MockSchema()32 assert isinstance(capability, MockItem), f"actual: {type(capability)}"33 result.number = generate_min_capability_countspace(34 self.number, capability.number35 )36 return result37class SearchSpaceTestCase(unittest.TestCase):38 def __init__(self, *args: Any, **kwargs: Any) -> None:39 super().__init__(*args, **kwargs)40 id = f"{'.'.join(self.id().split('.')[-2:])}"41 self._log = get_logger(id)42 def test_supported_intrange(self) -> None:43 self._verify_matrix(44 expected_meet=[45 [True, True, True, False, True, True, False, True, False, False],46 [True, True, False, False, True, True, False, False, False, False],47 ],48 expected_min=[49 [12, 10, 15, False, 10, 10, False, 15, False, False],50 [12, 10, False, False, 10, 10, False, False, False, False],51 ],52 requirements=[53 IntRange(min=10, max=15),54 IntRange(min=10, max=15, max_inclusive=False),55 ],56 capabilities=[57 IntRange(12),58 IntRange(10),59 IntRange(15),60 IntRange(20),61 IntRange(5, 11),62 IntRange(5, 10),63 IntRange(5, 10, max_inclusive=False),64 IntRange(15, 20),65 IntRange(1, 5),66 IntRange(20, 100),67 ],68 )69 def test_supported_countspace(self) -> None:70 expected_meet = [71 [True, True, True, True, True, True, True, True, True, True, True],72 [False, True, False, False, False, True, True, True, False, False, False],73 [False, False, True, False, False, True, False, True, True, False, False],74 [False, False, False, False, True, False, False, True, True, True, True],75 [False, True, True, False, False, True, True, True, True, False, False],76 [False, True, False, False, False, True, True, True, True, False, False],77 [False, True, True, False, True, True, True, True, True, True, True],78 ]79 expected_min: List[List[Any]] = [80 [None, 10, 15, 18, 25, 10, 10, 10, 12, 21, 21],81 [False, 10, False, False, False, 10, 10, 10, False, False, False],82 [False, False, 15, False, False, 15, False, 15, 15, False, False],83 [False, False, False, False, 25, False, False, 25, 25, 25, 25],84 [False, 10, 15, False, False, 10, 10, 10, 12, False, False],85 [False, 10, False, False, False, 10, 10, 10, 12, False, False],86 [False, 10, 15, False, 25, 10, 10, 10, 12, 21, 21],87 ]88 self._verify_matrix(89 expected_meet=expected_meet,90 expected_min=expected_min,91 requirements=[92 None,93 10,94 15,95 25,96 IntRange(min=10, max=15),97 IntRange(min=10, max=15, max_inclusive=False),98 [IntRange(min=10, max=15), IntRange(min=20, max=80)],99 ],100 capabilities=[101 None,102 10,103 15,104 18,105 25,106 IntRange(min=10, max=15),107 IntRange(min=10, max=15, max_inclusive=False),108 [IntRange(min=10, max=15), IntRange(min=20, max=80)],109 [IntRange(min=12, max=30)],110 [IntRange(min=21, max=25)],111 IntRange(min=21, max=25),112 ],113 )114 def test_supported_set_space(self) -> None:115 set_aa = set(["aa"])116 set_aa_bb = set(["aa", "bb"])117 set_aa_bb_cc = set(["aa", "bb", "cc"])118 set_aa_cc = set(["aa", "cc"])119 set_cc = set(["cc"])120 self._verify_matrix(121 expected_meet=[122 [True, True, True, True, True],123 [True, True, True, True, True],124 [False, False, False, True, False],125 [True, False, True, False, False],126 [True, False, True, False, False],127 ],128 expected_min=[129 [None, None, None, None, None],130 [None, None, None, None, None],131 [False, False, False, set_aa_bb, False],132 [None, False, None, False, False],133 [None, False, None, False, False],134 ],135 requirements=[136 SetSpace[str](is_allow_set=True),137 SetSpace[str](is_allow_set=False),138 SetSpace[str](items=set_aa_bb, is_allow_set=True),139 SetSpace[str](items=set_aa_bb),140 SetSpace[str](items=set_aa_bb, is_allow_set=False),141 ],142 capabilities=[143 SetSpace[str](is_allow_set=True),144 SetSpace[str](items=set_aa, is_allow_set=True),145 SetSpace[str](items=set_cc, is_allow_set=True),146 SetSpace[str](items=set_aa_bb_cc, is_allow_set=True),147 SetSpace[str](items=set_aa_cc, is_allow_set=True),148 ],149 )150 def test_generate_min_capability_not_supported(self) -> None:151 requirement = IntRange(min=5)152 capability = IntRange(max=4)153 with self.assertRaises(expected_exception=LisaException) as cm:154 requirement.generate_min_capability(capability)155 self.assertIn("doesn't support", str(cm.exception))156 def test_int_range_validation(self) -> None:157 with self.assertRaises(expected_exception=LisaException) as cm:158 IntRange(min=6, max=4)159 self.assertIn("shouldn't be greater than", str(cm.exception))160 # no exception161 IntRange(min=5, max=5)162 with self.assertRaises(expected_exception=LisaException) as cm:163 IntRange(min=5, max=5, max_inclusive=False)164 self.assertIn("shouldn't be equal to", str(cm.exception))165 def _verify_matrix(166 self,167 expected_meet: List[List[bool]],168 expected_min: List[List[Any]],169 requirements: List[T],170 capabilities: List[T],171 ) -> None:172 for r_index, requirement in enumerate(requirements):173 for c_index, capability in enumerate(capabilities):174 extra_msg = (175 f"index: [{r_index},{c_index}], "176 f"requirement: {requirement}, capability: {capability}"177 )178 if isinstance(requirement, RequirementMixin):179 self._assert_check(180 expected_meet[r_index][c_index],181 requirement.check(capability),182 extra_msg=extra_msg,183 )184 if expected_meet[r_index][c_index]:185 actual_min = requirement.generate_min_capability(capability)186 if expected_min[r_index][c_index] != actual_min:187 self._log.info(extra_msg)188 self._log.info(189 f"expected_min: {expected_min[r_index][c_index]}"190 )191 self._log.info(f"actual_min: {actual_min}")192 self.assertEqual(193 expected_min[r_index][c_index], actual_min, extra_msg194 )195 elif (196 isinstance(requirement, IntRange)197 or isinstance(requirement, int)198 or isinstance(capability, IntRange)199 or isinstance(capability, int)200 ):201 self._assert_check(202 expected_meet[r_index][c_index],203 check_countspace(requirement, capability), # type:ignore204 extra_msg=extra_msg,205 )206 if expected_meet[r_index][c_index]:207 actual_min = generate_min_capability_countspace(208 requirement, capability # type:ignore209 )210 if expected_min[r_index][c_index] != actual_min:211 self._log.info(extra_msg)212 self.assertEqual(213 expected_min[r_index][c_index], actual_min, extra_msg214 )215 else:216 self._assert_check(217 expected_meet[r_index][c_index],218 check(requirement, capability), # type:ignore219 extra_msg=extra_msg,220 )221 if expected_meet[r_index][c_index]:222 actual_min = generate_min_capability(223 requirement, capability # type:ignore224 )225 self.assertEqual(226 expected_min[r_index][c_index], actual_min, extra_msg227 )228 def _assert_check(229 self,230 expected_meet: bool,231 result: ResultReason,232 extra_msg: str = "",233 ) -> None:234 msg = f"expected result: {expected_meet}, actual: {result.result}"235 if extra_msg:236 msg = f"{msg}, {extra_msg}"...

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