How to use _record_error method in green

Best Python code snippet using green

impl.py

Source:impl.py Github

copy

Full Screen

...160 @property161 def result_urls(self):162 results = self.result_container.get_ordered_results()163 return [result['url'] for result in results if 'url' in result]164 def _record_error(self, message: str, *args) -> None:165 sq = _search_query_to_dict(self.search_query)166 sqstr = ' '.join(['{}={!r}'.format(k, v) for k, v in sq.items()])167 self.test_results.add_error(self.test_name, message, *args, '(' + sqstr + ')')168 def _add_language(self, text: str) -> typing.Optional[str]:169 try:170 r = detect_langs(str(text)) # pylint: disable=E1101171 except LangDetectException:172 return None173 if len(r) > 0 and r[0].prob > 0.95:174 self.languages.add(r[0].lang)175 self.test_results.add_language(r[0].lang)176 return None177 def _check_result(self, result):178 if not _check_no_html(result.get('title', '')):179 self._record_error('HTML in title', repr(result.get('title', '')))180 if not _check_no_html(result.get('content', '')):181 self._record_error('HTML in content', repr(result.get('content', '')))182 if result.get('url') is None:183 self._record_error('url is None')184 self._add_language(result.get('title', ''))185 self._add_language(result.get('content', ''))186 template = result.get('template', 'default.html')187 if template == 'default.html':188 return189 if template == 'code.html':190 return191 if template == 'torrent.html':192 return193 if template == 'map.html':194 return195 if template == 'images.html':196 thumbnail_src = result.get('thumbnail_src')197 if thumbnail_src is not None:198 if not _is_url_image(thumbnail_src):199 self._record_error('thumbnail_src URL is invalid', thumbnail_src)200 elif not _is_url_image(result.get('img_src')):201 self._record_error('img_src URL is invalid', result.get('img_src'))202 if template == 'videos.html' and not _is_url_image(result.get('thumbnail')):203 self._record_error('thumbnail URL is invalid', result.get('img_src'))204 def _check_results(self, results: list):205 for result in results:206 self._check_result(result)207 def _check_answers(self, answers):208 for answer in answers:209 if not _check_no_html(answer):210 self._record_error('HTML in answer', answer)211 def _check_infoboxes(self, infoboxes):212 for infobox in infoboxes:213 if not _check_no_html(infobox.get('content', '')):214 self._record_error('HTML in infobox content', infobox.get('content', ''))215 self._add_language(infobox.get('content', ''))216 for attribute in infobox.get('attributes', {}):217 if not _check_no_html(attribute.get('value', '')):218 self._record_error('HTML in infobox attribute value', attribute.get('value', ''))219 def check_basic(self):220 if len(self.result_container.unresponsive_engines) > 0:221 for message in self.result_container.unresponsive_engines:222 self._record_error(message[1] + ' ' + (message[2] or ''))223 self.stop_test = True224 return225 results = self.result_container.get_ordered_results()226 if len(results) > 0:227 self._check_results(results)228 if len(self.result_container.answers) > 0:229 self._check_answers(self.result_container.answers)230 if len(self.result_container.infoboxes) > 0:231 self._check_infoboxes(self.result_container.infoboxes)232 def has_infobox(self):233 """Check the ResultContainer has at least one infobox"""234 if len(self.result_container.infoboxes) == 0:235 self._record_error('No infobox')236 def has_answer(self):237 """Check the ResultContainer has at least one answer"""238 if len(self.result_container.answers) == 0:239 self._record_error('No answer')240 def has_language(self, lang):241 """Check at least one title or content of the results is written in the `lang`.242 Detected using pycld3, may be not accurate"""243 if lang not in self.languages:244 self._record_error(lang + ' not found')245 def not_empty(self):246 """Check the ResultContainer has at least one answer or infobox or result"""247 result_types = set()248 results = self.result_container.get_ordered_results()249 if len(results) > 0:250 result_types.add('results')251 if len(self.result_container.answers) > 0:252 result_types.add('answers')253 if len(self.result_container.infoboxes) > 0:254 result_types.add('infoboxes')255 if len(result_types) == 0:256 self._record_error('No result')257 def one_title_contains(self, title: str):258 """Check one of the title contains `title` (case insensitive comparaison)"""259 title = title.lower()260 for result in self.result_container.get_ordered_results():261 if title in result['title'].lower():262 return263 self._record_error(('{!r} not found in the title'.format(title)))264class CheckerTests:265 __slots__ = 'test_results', 'test_name', 'result_container_tests_list'266 def __init__(267 self, test_results: TestResults, test_name: str, result_container_tests_list: typing.List[ResultContainerTests]268 ):269 self.test_results = test_results270 self.test_name = test_name271 self.result_container_tests_list = result_container_tests_list272 def unique_results(self):273 """Check the results of each ResultContainer is unique"""274 urls_list = [rct.result_urls for rct in self.result_container_tests_list]275 if len(urls_list[0]) > 0:276 # results on the first page277 for i, urls_i in enumerate(urls_list):...

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 green 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