summaryrefslogtreecommitdiff
path: root/searx/search/processors
diff options
context:
space:
mode:
authorAlexandre Flament <alex@al-f.net>2020-12-24 09:28:16 +0100
committerAlexandre Flament <alex@al-f.net>2021-01-12 11:47:17 +0100
commit8cbc9f2d5823eb984e99e15c963e306610007fa1 (patch)
tree4dea97c668d960926938aefc8f0f77456bee47d6 /searx/search/processors
parentf7e11fd7222363a72a8fa33cf69190f64a3880bd (diff)
[enh] add checker
Diffstat (limited to 'searx/search/processors')
-rw-r--r--searx/search/processors/abstract.py12
-rw-r--r--searx/search/processors/online.py44
-rw-r--r--searx/search/processors/online_currency.py10
-rw-r--r--searx/search/processors/online_dictionary.py18
4 files changed, 84 insertions, 0 deletions
diff --git a/searx/search/processors/abstract.py b/searx/search/processors/abstract.py
index cf3fd723..eb8d296e 100644
--- a/searx/search/processors/abstract.py
+++ b/searx/search/processors/abstract.py
@@ -37,3 +37,15 @@ class EngineProcessor:
@abstractmethod
def search(self, query, params, result_container, start_time, timeout_limit):
pass
+
+ def get_tests(self):
+ tests = getattr(self.engine, 'tests', None)
+ if tests is None:
+ tests = getattr(self.engine, 'additional_tests', {})
+ tests.update(self.get_default_tests())
+ return tests
+ else:
+ return tests
+
+ def get_default_tests(self):
+ return {}
diff --git a/searx/search/processors/online.py b/searx/search/processors/online.py
index b62f8059..54d63b4c 100644
--- a/searx/search/processors/online.py
+++ b/searx/search/processors/online.py
@@ -211,3 +211,47 @@ class OnlineProcessor(EngineProcessor):
# reset the suspend variables
self.engine.continuous_errors = 0
self.engine.suspend_end_time = 0
+
+ def get_default_tests(self):
+ tests = {}
+
+ tests['simple'] = {
+ 'matrix': {'query': ('time', 'time')},
+ 'result_container': ['not_empty'],
+ }
+
+ if getattr(self.engine, 'paging', False):
+ # [1, 2, 3] --> isinstance(l, (list, tuple)) ??
+ tests['paging'] = {
+ 'matrix': {'query': 'time',
+ 'pageno': (1, 2, 3)},
+ 'result_container': ['not_empty'],
+ 'test': ['unique_results']
+ }
+
+ if getattr(self.engine, 'time_range', False):
+ tests['time_range'] = {
+ 'matrix': {'query': 'time',
+ 'time_range': (None, 'day')},
+ 'result_container': ['not_empty'],
+ 'test': ['unique_results']
+ }
+
+ if getattr(self.engine, 'lang', False):
+ tests['lang_fr'] = {
+ 'matrix': {'query': 'paris', 'lang': 'fr'},
+ 'result_container': ['not_empty', ('has_lang', 'fr')],
+ }
+ tests['lang_en'] = {
+ 'matrix': {'query': 'paris', 'lang': 'en'},
+ 'result_container': ['not_empty', ('has_lang', 'en')],
+ }
+
+ if getattr(self.engine, 'safesearch', False):
+ tests['safesearch'] = {
+ 'matrix': {'query': 'porn',
+ 'safesearch': (0, 2)},
+ 'test': ['unique_results']
+ }
+
+ return tests
diff --git a/searx/search/processors/online_currency.py b/searx/search/processors/online_currency.py
index f0e919c0..132c1059 100644
--- a/searx/search/processors/online_currency.py
+++ b/searx/search/processors/online_currency.py
@@ -55,3 +55,13 @@ class OnlineCurrencyProcessor(OnlineProcessor):
params['from_name'] = iso4217_to_name(from_currency, 'en')
params['to_name'] = iso4217_to_name(to_currency, 'en')
return params
+
+ def get_default_tests(self):
+ tests = {}
+
+ tests['currency'] = {
+ 'matrix': {'query': '1337 usd in rmb'},
+ 'result_container': ['has_answer'],
+ }
+
+ return tests
diff --git a/searx/search/processors/online_dictionary.py b/searx/search/processors/online_dictionary.py
index 8e9ef162..987c710a 100644
--- a/searx/search/processors/online_dictionary.py
+++ b/searx/search/processors/online_dictionary.py
@@ -35,3 +35,21 @@ class OnlineDictionaryProcessor(OnlineProcessor):
params['query'] = query
return params
+
+ def get_default_tests(self):
+ tests = {}
+
+ if getattr(self.engine, 'paging', False):
+ tests['translation_paging'] = {
+ 'matrix': {'query': 'en-es house',
+ 'pageno': (1, 2, 3)},
+ 'result_container': ['not_empty', ('one_title_contains', 'house')],
+ 'test': ['unique_results']
+ }
+ else:
+ tests['translation'] = {
+ 'matrix': {'query': 'en-es house'},
+ 'result_container': ['not_empty', ('one_title_contains', 'house')],
+ }
+
+ return tests