Best Python code snippet using lisa_python
schema.py
Source:schema.py
...685 )686 return core_count + gpu_count * 100687 @property688 def features(self) -> Optional[search_space.SetSpace[FeatureSettings]]:689 self._features = self._create_feature_settings_list(self._features)690 if self._features is not None:691 self._features.is_allow_set = True692 return cast(Optional[search_space.SetSpace[FeatureSettings]], self._features)693 @features.setter694 def features(self, value: Optional[search_space.SetSpace[FeatureSettings]]) -> None:695 self._features = cast(FeaturesSpace, value)696 @property697 def excluded_features(self) -> Optional[search_space.SetSpace[FeatureSettings]]:698 if not self._excluded_features:699 self._excluded_features = self._create_feature_settings_list(700 self._excluded_features701 )702 if self._excluded_features is not None:703 self._excluded_features.is_allow_set = False704 return cast(705 Optional[search_space.SetSpace[FeatureSettings]], self._excluded_features706 )707 @excluded_features.setter708 def excluded_features(709 self, value: Optional[search_space.SetSpace[FeatureSettings]]710 ) -> None:711 self._excluded_features = cast(FeaturesSpace, value)712 def check(self, capability: Any) -> search_space.ResultReason:713 result = search_space.ResultReason()714 if capability is None:715 result.add_reason("capability shouldn't be None")716 if self.features:717 assert self.features.is_allow_set, "features should be allow set"718 if self.excluded_features:719 assert (720 not self.excluded_features.is_allow_set721 ), "excluded_features shouldn't be allow set"722 assert isinstance(capability, NodeSpace), f"actual: {type(capability)}"723 if (724 not capability.node_count725 or not capability.core_count726 or not capability.memory_mb727 ):728 result.add_reason(729 "node_count, core_count, memory_mb " "shouldn't be None or zero."730 )731 if isinstance(self.node_count, int) and isinstance(capability.node_count, int):732 if self.node_count > capability.node_count:733 result.add_reason(734 f"capability node count {capability.node_count} "735 f"must be more than requirement {self.node_count}"736 )737 else:738 result.merge(739 search_space.check_countspace(self.node_count, capability.node_count),740 "node_count",741 )742 result.merge(743 search_space.check_countspace(self.core_count, capability.core_count),744 "core_count",745 )746 result.merge(747 search_space.check_countspace(self.memory_mb, capability.memory_mb),748 "memory_mb",749 )750 if self.disk:751 result.merge(self.disk.check(capability.disk))752 if self.network_interface:753 result.merge(self.network_interface.check(capability.network_interface))754 result.merge(755 search_space.check_countspace(self.gpu_count, capability.gpu_count),756 "gpu_count",757 )758 if self.features:759 for feature in self.features:760 cap_feature = self._find_feature_by_type(761 feature.type, capability.features762 )763 if cap_feature:764 result.merge(feature.check(cap_feature))765 else:766 result.add_reason(767 f"no feature '{feature.type}' found in capability"768 )769 if self.excluded_features:770 for feature in self.excluded_features:771 cap_feature = self._find_feature_by_type(772 feature.type, capability.features773 )774 if cap_feature:775 result.add_reason(776 f"excluded feature '{feature.type}' found in capability"777 )778 return result779 def expand_by_node_count(self) -> List[Any]:780 # expand node count in requirement to one,781 # so that's easy to compare equalization later.782 expanded_requirements: List[NodeSpace] = []783 node_count = search_space.generate_min_capability_countspace(784 self.node_count, self.node_count785 )786 for _ in range(node_count):787 expanded_copy = copy.copy(self)788 expanded_copy.node_count = 1789 expanded_requirements.append(expanded_copy)790 return expanded_requirements791 def has_feature(self, find_type: str) -> bool:792 result = False793 if not self.features:794 return result795 return any(feature for feature in self.features if feature.type == find_type)796 def _call_requirement_method(self, method_name: str, capability: Any) -> Any:797 assert isinstance(capability, NodeSpace), f"actual: {type(capability)}"798 # copy to duplicate extended schema799 value: NodeSpace = copy.deepcopy(self)800 if self.node_count or capability.node_count:801 if isinstance(self.node_count, int) and isinstance(802 capability.node_count, int803 ):804 # capability can have more node805 value.node_count = capability.node_count806 else:807 value.node_count = getattr(search_space, f"{method_name}_countspace")(808 self.node_count, capability.node_count809 )810 else:811 raise LisaException("node_count cannot be zero")812 if self.core_count or capability.core_count:813 value.core_count = getattr(search_space, f"{method_name}_countspace")(814 self.core_count, capability.core_count815 )816 else:817 raise LisaException("core_count cannot be zero")818 if self.memory_mb or capability.memory_mb:819 value.memory_mb = getattr(search_space, f"{method_name}_countspace")(820 self.memory_mb, capability.memory_mb821 )822 else:823 raise LisaException("memory_mb cannot be zero")824 if self.disk or capability.disk:825 value.disk = getattr(search_space, method_name)(self.disk, capability.disk)826 if self.network_interface or capability.network_interface:827 value.network_interface = getattr(search_space, method_name)(828 self.network_interface, capability.network_interface829 )830 if self.gpu_count or capability.gpu_count:831 value.gpu_count = getattr(search_space, f"{method_name}_countspace")(832 self.gpu_count, capability.gpu_count833 )834 else:835 value.gpu_count = 0836 if (837 capability.features838 and method_name == search_space.RequirementMethod.generate_min_capability839 ):840 # The requirement features are ignored, if cap doesn't have it.841 value.features = search_space.SetSpace[FeatureSettings](is_allow_set=True)842 for original_cap_feature in capability.features:843 capability_feature = self._get_or_create_feature_settings(844 original_cap_feature845 )846 requirement_feature = (847 self._find_feature_by_type(capability_feature.type, self.features)848 or capability_feature849 )850 current_feature = getattr(requirement_feature, method_name)(851 capability_feature852 )853 value.features.add(current_feature)854 elif method_name == search_space.RequirementMethod.intersect and (855 capability.features or self.features856 ):857 # This is a hack to work with lisa_runner. The capability features858 # are joined case req and runbook req. Here just take the results859 # from capability.860 value.features = capability.features861 if (862 capability.excluded_features863 and method_name == search_space.RequirementMethod.generate_min_capability864 ):865 # TODO: the min value for excluded feature is not clear. It may need866 # to be improved with real scenarios.867 value.excluded_features = search_space.SetSpace[FeatureSettings](868 is_allow_set=True869 )870 for original_cap_feature in capability.excluded_features:871 capability_feature = self._get_or_create_feature_settings(872 original_cap_feature873 )874 requirement_feature = (875 self._find_feature_by_type(876 capability_feature.type, self.excluded_features877 )878 or capability_feature879 )880 current_feature = getattr(requirement_feature, method_name)(881 capability_feature882 )883 value.excluded_features.add(current_feature)884 elif method_name == search_space.RequirementMethod.intersect and (885 capability.excluded_features or self.excluded_features886 ):887 # This is a hack to work with lisa_runner. The capability features888 # are joined case req and runbook req. Here just take the results889 # from capability.890 value.excluded_features = capability.excluded_features891 return value892 def _find_feature_by_type(893 self,894 find_type: str,895 features: Optional[search_space.SetSpace[Any]],896 ) -> Optional[FeatureSettings]:897 result: Optional[FeatureSettings] = None898 if not features:899 return result900 is_found = False901 for original_feature in features.items:902 feature = self._get_or_create_feature_settings(original_feature)903 if feature.type == find_type:904 is_found = True905 break906 if is_found:907 result = feature908 return result909 def _create_feature_settings_list(910 self, features: Optional[search_space.SetSpace[Any]]911 ) -> Optional[FeaturesSpace]:912 result: Optional[FeaturesSpace] = None913 if features is None:914 return result915 result = cast(916 FeaturesSpace,917 search_space.SetSpace[FeatureSettings](is_allow_set=features.is_allow_set),918 )919 for raw_feature in features.items:920 feature = self._get_or_create_feature_settings(raw_feature)921 result.add(feature)922 return result923 def _get_or_create_feature_settings(self, feature: Any) -> FeatureSettings:...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!