Best Python code snippet using lemoncheesecake
server.py
Source:server.py
...219 if sortby == vsc.SortBy.NoneOrRelevance:220 sortby = vsc.SortBy.InstallCount221 sortorder = vsc.SortOrder.Descending 222223 result = self._apply_criteria(criteria)224 self._sort(result, sortby, sortorder) 225 resp.media = self._build_response(result)226 resp.status = falcon.HTTP_200227228 def _sort(self, result, sortby, sortorder):229 if sortorder == vsc.SortOrder.Ascending:230 rev = False231 else:232 rev = True233234 if sortby == vsc.SortBy.PublisherName:235 rev = not rev236 result.sort(key=lambda k: k['publisher']['publisherName'], reverse=rev)237238 elif sortby == vsc.SortBy.InstallCount:239 result.sort(key=lambda k: k['stats']['install'], reverse=rev)240241 elif sortby == vsc.SortBy.AverageRating:242 result.sort(key=lambda k: k['stats']['averagerating'], reverse=rev)243244 elif sortby == vsc.SortBy.WeightedRating:245 result.sort(key=lambda k: k['stats']['weightedRating'], reverse=rev)246247 elif sortby == vsc.SortBy.LastUpdatedDate:248 result.sort(key=lambda k: vsc.Utility.from_json_datetime(k['lastUpdated']), reverse=rev)249250 elif sortby == vsc.SortBy.PublishedDate:251 result.sort(key=lambda k: vsc.Utility.from_json_datetime(k['publishedDate']), reverse=rev)252253 else:254 rev = not rev255 result.sort(key=lambda k: k['displayName'], reverse=rev) 256257 def _apply_criteria(self, criteria):258 result = []259260 for crit in criteria:261 if 'filterType' not in crit or 'value' not in crit:262 continue263 ft = vsc.FilterType(crit['filterType'])264 val = crit['value'].lower()265266 if ft == vsc.FilterType.Tag:267 # ?? Tags268 log.info(f"Not implemented filter type {ft} for {val}")269 continue 270271 elif ft == vsc.FilterType.ExtensionId:
...
filter.py
Source:filter.py
...90 return all(self._match_key_values(node.hierarchy_properties, props) for props in self.properties)91 def _do_links(self, node):92 return all(self._match_values_lists(node.hierarchy_links, links) for links in self.links)93 @staticmethod94 def _apply_criteria(obj, *criteria):95 return all(criterion(obj) for criterion in criteria)96 def __call__(self, node):97 assert isinstance(node, (BaseTest, BaseSuite))98 return self._apply_criteria(99 node, self._do_paths, self._do_descriptions, self._do_tags, self._do_properties, self._do_links100 )101class TestFilter(BaseTreeNodeFilter):102 def __init__(self, enabled=False, disabled=False, **kwargs):103 BaseTreeNodeFilter.__init__(self, **kwargs)104 self.enabled = enabled105 self.disabled = disabled106 def __bool__(self):107 return BaseTreeNodeFilter.__bool__(self) or any((self.enabled, self.disabled))108 def _do_enabled(self, test):109 return not test.is_disabled() if self.enabled else True110 def _do_disabled(self, test):111 return test.is_disabled() if self.disabled else True112 def _apply_test_criteria(self, test):113 return self._apply_criteria(test, self._do_enabled, self._do_disabled)114 def __call__(self, test):115 assert isinstance(test, Test)116 return BaseTreeNodeFilter.__call__(self, test) and self._apply_test_criteria(test)117class ResultFilter(BaseTreeNodeFilter):118 def __init__(self, statuses=None, enabled=False, disabled=False, grep=None, **kwargs):119 BaseTreeNodeFilter.__init__(self, **kwargs)120 self.statuses = set(statuses) if statuses is not None else set()121 self.enabled = enabled122 self.disabled = disabled123 self.grep = grep124 def __bool__(self):125 return BaseTreeNodeFilter.__bool__(self) or any((self.statuses, self.enabled, self.disabled, self.grep))126 def _do_statuses(self, result):127 return result.status in self.statuses if self.statuses else True128 def _do_enabled(self, result):129 return result.status != "disabled" if self.enabled else True130 def _do_disabled(self, result):131 return result.status == "disabled" if self.disabled else True132 def _do_grep(self, result):133 if not self.grep:134 return True135 return _grep(self.grep, result.get_steps())136 def _apply_result_criteria(self, result):137 return self._apply_criteria(138 result, self._do_statuses, self._do_enabled, self._do_disabled, self._do_grep139 )140 def __call__(self, result):141 # type: (Result) -> bool142 assert isinstance(result, Result)143 # test result:144 if isinstance(result, TestResult):145 return BaseTreeNodeFilter.__call__(self, result) and self._apply_result_criteria(result)146 # suite setup or teardown result, apply the base filter on the suite node:147 elif result.parent_suite:148 return BaseTreeNodeFilter.__call__(self, result.parent_suite) and self._apply_result_criteria(result)149 # session setup or teardown:150 else:151 if BaseTreeNodeFilter.__bool__(self):152 # no criteria of BaseFilter is applicable to a session setup/teardown result,153 # meaning it's a no match154 return False155 else:156 return self._apply_result_criteria(result)157class StepFilter(BaseTreeNodeFilter):158 def __init__(self, passed=False, failed=False, grep=None, **kwargs):159 BaseTreeNodeFilter.__init__(self, **kwargs)160 self.passed = passed161 self.failed = failed162 self.grep = grep163 def __bool__(self):164 return BaseTreeNodeFilter.__bool__(self) or any((self.passed, self.failed, self.grep))165 def _do_passed(self, step):166 return step.is_successful() if self.passed else True167 def _do_failed(self, step):168 return not step.is_successful() if self.failed else True169 def _do_grep(self, step):170 if not self.grep:171 return True172 return _grep(self.grep, (step,))173 def _apply_step_criteria(self, step):174 return self._apply_criteria(175 step, self._do_passed, self._do_failed, self._do_grep176 )177 def __call__(self, step):178 # type: (Step) -> bool179 assert isinstance(step, Step)180 # test result:181 if isinstance(step.parent_result, TestResult):182 return BaseTreeNodeFilter.__call__(self, step.parent_result) and self._apply_step_criteria(step)183 # suite setup or teardown result, apply the base filter on the suite node:184 elif step.parent_result.parent_suite:185 return BaseTreeNodeFilter.__call__(self, step.parent_result.parent_suite) and self._apply_step_criteria(step)186 # session setup or teardown:187 else:188 if BaseTreeNodeFilter.__bool__(self):...
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!!