.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.search.checker.impl.ResultContainerTests Class Reference

Public Member Functions

 __init__ (self, TestResults test_results, str test_name, SearchQuery search_query, ResultContainer result_container)
 
 result_urls (self)
 
 check_basic (self)
 
 has_infobox (self)
 
 has_answer (self)
 
 has_language (self, lang)
 
 not_empty (self)
 
 one_title_contains (self, str title)
 

Public Attributes

 test_name
 
 search_query
 
 result_container
 
 test_results
 
 stop_test
 

Protected Member Functions

None _record_error (self, str message, *args)
 
typing.Optional[str] _add_language (self, str text)
 
 _check_result (self, result)
 
 _check_results (self, list results)
 
 _check_answers (self, answers)
 
 _check_infoboxes (self, infoboxes)
 

Static Private Attributes

str __slots__ = 'test_name', 'search_query', 'result_container', 'languages', 'stop_test', 'test_results'
 

Detailed Description

Definition at line 185 of file impl.py.

Constructor & Destructor Documentation

◆ __init__()

searx.search.checker.impl.ResultContainerTests.__init__ ( self,
TestResults test_results,
str test_name,
SearchQuery search_query,
ResultContainer result_container )

Definition at line 189 of file impl.py.

191 ):
192 self.test_name = test_name
193 self.search_query = search_query
194 self.result_container = result_container
195 self.languages: typing.Set[str] = set()
196 self.test_results = test_results
197 self.stop_test = False
198

Member Function Documentation

◆ _add_language()

typing.Optional[str] searx.search.checker.impl.ResultContainerTests._add_language ( self,
str text )
protected

Definition at line 209 of file impl.py.

209 def _add_language(self, text: str) -> typing.Optional[str]:
210 langStr = detect_language(text)
211 if langStr:
212 self.languages.add(langStr)
213 self.test_results.add_language(langStr)
214

References searx.enginelib.traits.EngineTraits.languages, searx.query.RawTextQuery.languages, searx.search.checker.impl.ResultContainerTests.test_results, searx.search.checker.impl.CheckerTests.test_results, and searx.search.checker.impl.Checker.test_results.

Referenced by searx.search.checker.impl.ResultContainerTests._check_infoboxes(), and searx.search.checker.impl.ResultContainerTests._check_result().

+ Here is the caller graph for this function:

◆ _check_answers()

searx.search.checker.impl.ResultContainerTests._check_answers ( self,
answers )
protected

Definition at line 249 of file impl.py.

249 def _check_answers(self, answers):
250 for answer in answers:
251 if not _check_no_html(answer):
252 self._record_error('HTML in answer', answer)
253

References searx.search.checker.impl._check_no_html, and searx.search.checker.impl.ResultContainerTests._record_error().

Referenced by searx.search.checker.impl.ResultContainerTests.check_basic().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _check_infoboxes()

searx.search.checker.impl.ResultContainerTests._check_infoboxes ( self,
infoboxes )
protected

Definition at line 254 of file impl.py.

254 def _check_infoboxes(self, infoboxes):
255 for infobox in infoboxes:
256 if not _check_no_html(infobox.get('content', '')):
257 self._record_error('HTML in infobox content', infobox.get('content', ''))
258 self._add_language(infobox.get('content', ''))
259 for attribute in infobox.get('attributes', {}):
260 if not _check_no_html(attribute.get('value', '')):
261 self._record_error('HTML in infobox attribute value', attribute.get('value', ''))
262

References searx.search.checker.impl.ResultContainerTests._add_language(), searx.search.checker.impl._check_no_html, and searx.search.checker.impl.ResultContainerTests._record_error().

Referenced by searx.search.checker.impl.ResultContainerTests.check_basic().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _check_result()

searx.search.checker.impl.ResultContainerTests._check_result ( self,
result )
protected

Definition at line 215 of file impl.py.

215 def _check_result(self, result):
216 if not _check_no_html(result.get('title', '')):
217 self._record_error('HTML in title', repr(result.get('title', '')))
218 if not _check_no_html(result.get('content', '')):
219 self._record_error('HTML in content', repr(result.get('content', '')))
220 if result.get('url') is None:
221 self._record_error('url is None')
222
223 self._add_language(result.get('title', ''))
224 self._add_language(result.get('content', ''))
225
226 template = result.get('template', 'default.html')
227 if template == 'default.html':
228 return
229 if template == 'code.html':
230 return
231 if template == 'torrent.html':
232 return
233 if template == 'map.html':
234 return
235 if template == 'images.html':
236 thumbnail_src = result.get('thumbnail_src')
237 if thumbnail_src is not None:
238 if not _is_url_image(thumbnail_src):
239 self._record_error('thumbnail_src URL is invalid', thumbnail_src)
240 elif not _is_url_image(result.get('img_src')):
241 self._record_error('img_src URL is invalid', result.get('img_src'))
242 if template == 'videos.html' and not _is_url_image(result.get('thumbnail')):
243 self._record_error('thumbnail URL is invalid', result.get('img_src'))
244

References searx.search.checker.impl.ResultContainerTests._add_language(), searx.search.checker.impl._check_no_html, searx.search.checker.impl._is_url_image(), and searx.search.checker.impl.ResultContainerTests._record_error().

Referenced by searx.search.checker.impl.ResultContainerTests._check_results().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _check_results()

searx.search.checker.impl.ResultContainerTests._check_results ( self,
list results )
protected

Definition at line 245 of file impl.py.

245 def _check_results(self, results: list):
246 for result in results:
247 self._check_result(result)
248

References searx.search.checker.impl.ResultContainerTests._check_result().

Referenced by searx.search.checker.impl.ResultContainerTests.check_basic().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _record_error()

None searx.search.checker.impl.ResultContainerTests._record_error ( self,
str message,
* args )
protected

Definition at line 204 of file impl.py.

204 def _record_error(self, message: str, *args) -> None:
205 sq = _search_query_to_dict(self.search_query)
206 sqstr = ' '.join(['{}={!r}'.format(k, v) for k, v in sq.items()])
207 self.test_results.add_error(self.test_name, message, *args, '(' + sqstr + ')')
208

References searx.search.checker.impl._search_query_to_dict(), searx.format, searx.search.Search.search_query, searx.search.checker.impl.ResultContainerTests.search_query, searx.search.checker.impl.ResultContainerTests.test_name, searx.search.checker.impl.CheckerTests.test_name, searx.search.checker.impl.ResultContainerTests.test_results, searx.search.checker.impl.CheckerTests.test_results, and searx.search.checker.impl.Checker.test_results.

Referenced by searx.search.checker.impl.ResultContainerTests._check_answers(), searx.search.checker.impl.ResultContainerTests._check_infoboxes(), searx.search.checker.impl.ResultContainerTests._check_result(), searx.search.checker.impl.ResultContainerTests.check_basic(), and searx.search.checker.impl.ResultContainerTests.has_infobox().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ check_basic()

searx.search.checker.impl.ResultContainerTests.check_basic ( self)

Definition at line 263 of file impl.py.

263 def check_basic(self):
264 if len(self.result_container.unresponsive_engines) > 0:
265 for message in self.result_container.unresponsive_engines:
266 self._record_error(message[1] + ' ' + (message[2] or ''))
267 self.stop_test = True
268 return
269
270 results = self.result_container.get_ordered_results()
271 if len(results) > 0:
272 self._check_results(results)
273
274 if len(self.result_container.answers) > 0:
275 self._check_answers(self.result_container.answers)
276
277 if len(self.result_container.infoboxes) > 0:
278 self._check_infoboxes(self.result_container.infoboxes)
279

References searx.search.checker.impl.ResultContainerTests._check_answers(), searx.search.checker.impl.ResultContainerTests._check_infoboxes(), searx.search.checker.impl.ResultContainerTests._check_results(), searx.search.checker.impl.ResultContainerTests._record_error(), searx.search.Search.result_container, searx.search.checker.impl.ResultContainerTests.result_container, and searx.search.checker.impl.ResultContainerTests.stop_test.

+ Here is the call graph for this function:

◆ has_answer()

searx.search.checker.impl.ResultContainerTests.has_answer ( self)
Check the ResultContainer has at least one answer

Definition at line 285 of file impl.py.

285 def has_answer(self):
286 """Check the ResultContainer has at least one answer"""
287 if len(self.result_container.answers) == 0:
288 self._record_error('No answer')
289

◆ has_infobox()

searx.search.checker.impl.ResultContainerTests.has_infobox ( self)
Check the ResultContainer has at least one infobox

Definition at line 280 of file impl.py.

280 def has_infobox(self):
281 """Check the ResultContainer has at least one infobox"""
282 if len(self.result_container.infoboxes) == 0:
283 self._record_error('No infobox')
284

References searx.search.checker.impl.ResultContainerTests._record_error(), searx.search.Search.result_container, and searx.search.checker.impl.ResultContainerTests.result_container.

+ Here is the call graph for this function:

◆ has_language()

searx.search.checker.impl.ResultContainerTests.has_language ( self,
lang )
Check at least one title or content of the results is written in the `lang`.

Detected using pycld3, may be not accurate

Definition at line 290 of file impl.py.

290 def has_language(self, lang):
291 """Check at least one title or content of the results is written in the `lang`.
292
293 Detected using pycld3, may be not accurate"""
294 if lang not in self.languages:
295 self._record_error(lang + ' not found')
296

◆ not_empty()

searx.search.checker.impl.ResultContainerTests.not_empty ( self)
Check the ResultContainer has at least one answer or infobox or result

Definition at line 297 of file impl.py.

297 def not_empty(self):
298 """Check the ResultContainer has at least one answer or infobox or result"""
299 result_types = set()
300 results = self.result_container.get_ordered_results()
301 if len(results) > 0:
302 result_types.add('results')
303
304 if len(self.result_container.answers) > 0:
305 result_types.add('answers')
306
307 if len(self.result_container.infoboxes) > 0:
308 result_types.add('infoboxes')
309
310 if len(result_types) == 0:
311 self._record_error('No result')
312

◆ one_title_contains()

searx.search.checker.impl.ResultContainerTests.one_title_contains ( self,
str title )
Check one of the title contains `title` (case insensitive comparison)

Definition at line 313 of file impl.py.

313 def one_title_contains(self, title: str):
314 """Check one of the title contains `title` (case insensitive comparison)"""
315 title = title.lower()
316 for result in self.result_container.get_ordered_results():
317 if title in result['title'].lower():
318 return
319 self._record_error(('{!r} not found in the title'.format(title)))
320
321

◆ result_urls()

searx.search.checker.impl.ResultContainerTests.result_urls ( self)

Definition at line 200 of file impl.py.

200 def result_urls(self):
201 results = self.result_container.get_ordered_results()
202 return [result['url'] for result in results if 'url' in result]
203

References searx.search.Search.result_container, and searx.search.checker.impl.ResultContainerTests.result_container.

Member Data Documentation

◆ __slots__

str searx.search.checker.impl.ResultContainerTests.__slots__ = 'test_name', 'search_query', 'result_container', 'languages', 'stop_test', 'test_results'
staticprivate

Definition at line 187 of file impl.py.

◆ result_container

◆ search_query

searx.search.checker.impl.ResultContainerTests.search_query

◆ stop_test

searx.search.checker.impl.ResultContainerTests.stop_test

Definition at line 197 of file impl.py.

Referenced by searx.search.checker.impl.ResultContainerTests.check_basic().

◆ test_name

searx.search.checker.impl.ResultContainerTests.test_name

◆ test_results

searx.search.checker.impl.ResultContainerTests.test_results

The documentation for this class was generated from the following file: