Compare commits

...

5 Commits

Author SHA1 Message Date
Allen 6309f80765
Merge 21dd524a12 into 2fbf15eccb 2024-11-08 17:26:08 +01:00
dependabot[bot] 2fbf15eccb [upd] pypi: Bump typer-slim from 0.12.5 to 0.13.0
Bumps [typer-slim](https://github.com/fastapi/typer) from 0.12.5 to 0.13.0.
- [Release notes](https://github.com/fastapi/typer/releases)
- [Changelog](https://github.com/fastapi/typer/blob/master/docs/release-notes.md)
- [Commits](https://github.com/fastapi/typer/compare/0.12.5...0.13.0)

---
updated-dependencies:
- dependency-name: typer-slim
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-11-08 08:51:43 +01:00
searxng-bot 08c5f258d8 [l10n] update translations from Weblate
8d90a7e6d - 2024-11-06 - sahussawud <sahussawud@users.noreply.translate.codeberg.org>
41ee8bb0d - 2024-11-02 - laaknor <laaknor@users.noreply.translate.codeberg.org>
c1a30afab - 2024-11-02 - return42 <return42@users.noreply.translate.codeberg.org>
627ab7a8e - 2024-11-01 - zarlin <zarlin@users.noreply.translate.codeberg.org>
2024-11-08 08:45:07 +01:00
Markus Heiser 21dd524a12 [fix] unit tests: call searx.search.initialize in test's setUp
Depending on the order the unit tests are executed, the searx.search module is
initalized or not, issue reported in [1]::

    Traceback (most recent call last):
      File "searxng/tests/unit/test_results.py", line 72, in test_result_merge_by_title
        self.container.extend('stract', [fake_result(engine='stract', title='short title')])
      File "searxng/searx/results.py", line 243, in extend
        histogram_observe(standard_result_count, 'engine', engine_name, 'result', 'count')
      File "searxng/searx/metrics/__init__.py", line 49, in histogram_observe
        histogram_storage.get(*args).observe(duration)
        ^^^^^^^^^^^^^^^^^^^^^
      AttributeError: 'NoneType' object has no attribute 'get'

To ensure that the searx.search module is initialized, the

- searx.engines.load_engines is replace by
- searx.search.initialize

[1] https://github.com/searxng/searxng/pull/3932#discussion_r1822406569

Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
2024-10-30 14:33:52 +01:00
Allen 0476de443e [enh] use longest title and test get_ordered_results() 2024-10-30 14:33:52 +01:00
15 changed files with 117 additions and 88 deletions

View File

@ -18,4 +18,4 @@ fasttext-predict==0.9.2.2
tomli==2.0.2; python_version < '3.11'
msgspec==0.18.6
eval_type_backport; python_version < '3.9'
typer-slim==0.12.5
typer-slim==0.13.0

View File

@ -12,7 +12,6 @@ from searx import logger
from searx.engines import engines
from searx.metrics import histogram_observe, counter_add, count_error
CONTENT_LEN_IGNORED_CHARS_REGEX = re.compile(r'[,;:!?\./\\\\ ()-_]', re.M | re.U)
WHITESPACE_REGEX = re.compile('( |\t|\n)+', re.M | re.U)
@ -133,7 +132,7 @@ def result_score(result, priority):
weight = 1.0
for result_engine in result['engines']:
if hasattr(engines[result_engine], 'weight'):
if hasattr(engines.get(result_engine), 'weight'):
weight *= float(engines[result_engine].weight)
weight *= len(result['positions'])
@ -332,10 +331,14 @@ class ResultContainer:
return None
def __merge_duplicated_http_result(self, duplicated, result, position):
# using content with more text
# use content with more text
if result_content_len(result.get('content', '')) > result_content_len(duplicated.get('content', '')):
duplicated['content'] = result['content']
# use title with more text
if result_content_len(result.get('title', '')) > len(duplicated.get('title', '')):
duplicated['title'] = result['title']
# merge all result's parameters not found in duplicate
for key in result.keys():
if not duplicated.get(key):
@ -347,7 +350,7 @@ class ResultContainer:
# add engine to list of result-engines
duplicated['engines'].add(result['engine'])
# using https if possible
# use https if possible
if duplicated['parsed_url'].scheme != 'https' and result['parsed_url'].scheme == 'https':
duplicated['url'] = result['parsed_url'].geturl()
duplicated['parsed_url'] = result['parsed_url']

View File

@ -39,9 +39,8 @@ msgstr ""
"Project-Id-Version: searx\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2024-10-05 06:24+0000\n"
"PO-Revision-Date: 2024-10-26 21:13+0000\n"
"Last-Translator: Atul_Eterno <Atul_Eterno@users.noreply.translate.codeberg."
"org>\n"
"PO-Revision-Date: 2024-11-03 09:08+0000\n"
"Last-Translator: return42 <return42@users.noreply.translate.codeberg.org>\n"
"Language-Team: Spanish <https://translate.codeberg.org/projects/searxng/"
"searxng/es/>\n"
"Language: es\n"
@ -1246,7 +1245,7 @@ msgstr "Tiempo máximo"
#: searx/templates/simple/preferences/favicon.html:2
msgid "Favicon Resolver"
msgstr ""
msgstr "Buscador de favicon"
#: searx/templates/simple/preferences/favicon.html:15
msgid "Display favicons near search results"

View File

@ -10,21 +10,22 @@
# return42 <return42@users.noreply.translate.codeberg.org>, 2024.
# omfj <omfj@users.noreply.translate.codeberg.org>, 2024.
# combwizard <combwizard@users.noreply.translate.codeberg.org>, 2024.
# laaknor <laaknor@users.noreply.translate.codeberg.org>, 2024.
msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2024-10-05 06:24+0000\n"
"PO-Revision-Date: 2024-10-04 21:35+0000\n"
"Last-Translator: combwizard "
"<combwizard@users.noreply.translate.codeberg.org>\n"
"PO-Revision-Date: 2024-11-03 09:08+0000\n"
"Last-Translator: laaknor <laaknor@users.noreply.translate.codeberg.org>\n"
"Language-Team: Norwegian Bokmål <https://translate.codeberg.org/projects/"
"searxng/searxng/nb_NO/>\n"
"Language: nb_NO\n"
"Language-Team: Norwegian Bokmål "
"<https://translate.codeberg.org/projects/searxng/searxng/nb_NO/>\n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Weblate 5.8.1\n"
"Generated-By: Babel 2.16.0\n"
#. CONSTANT_NAMES['NO_SUBGROUPING']
@ -1051,7 +1052,7 @@ msgstr "Det er ingen flere resultater. Du kan prøve å:"
#: searx/templates/simple/messages/no_results.html:19
msgid "Refresh the page."
msgstr "oppfrisk siden"
msgstr "oppfrisk siden."
#: searx/templates/simple/messages/no_results.html:20
msgid "Search for another query or select another category (above)."
@ -1882,4 +1883,3 @@ msgstr "skjul video"
#~ msgid "Engines cannot retrieve results"
#~ msgstr "Søkemotorer kan ikke motta resultater"

View File

@ -23,13 +23,14 @@
# notlmutsaers <notlmutsaers@users.noreply.translate.codeberg.org>, 2024.
# return42 <return42@users.noreply.translate.codeberg.org>, 2024.
# ljansen <ljansen@users.noreply.translate.codeberg.org>, 2024.
# zarlin <zarlin@users.noreply.translate.codeberg.org>, 2024.
msgid ""
msgstr ""
"Project-Id-Version: searx\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2024-10-05 06:24+0000\n"
"PO-Revision-Date: 2024-10-28 21:07+0000\n"
"Last-Translator: ljansen <ljansen@users.noreply.translate.codeberg.org>\n"
"PO-Revision-Date: 2024-11-02 04:00+0000\n"
"Last-Translator: zarlin <zarlin@users.noreply.translate.codeberg.org>\n"
"Language-Team: Dutch <https://translate.codeberg.org/projects/searxng/"
"searxng/nl/>\n"
"Language: nl\n"
@ -493,7 +494,7 @@ msgstr "stemmen"
#: searx/engines/radio_browser.py:107
msgid "clicks"
msgstr "clicks"
msgstr "klikken"
#: searx/engines/seekr.py:193 searx/engines/yummly.py:71
#: searx/engines/zlibrary.py:137
@ -662,7 +663,7 @@ msgstr "Voorkeuren"
#: searx/templates/simple/base.html:68
msgid "Powered by"
msgstr "Zoekmachine"
msgstr "Verzorgd door"
#: searx/templates/simple/base.html:68
msgid "a privacy-respecting, open metasearch engine"
@ -1069,7 +1070,7 @@ msgstr "Er zijn geen resultaten meer. U kunt proberen om:"
#: searx/templates/simple/messages/no_results.html:19
msgid "Refresh the page."
msgstr "Ververs de pagina"
msgstr "Ververs de pagina."
#: searx/templates/simple/messages/no_results.html:20
msgid "Search for another query or select another category (above)."
@ -1235,9 +1236,8 @@ msgid "Max time"
msgstr "Max. duur"
#: searx/templates/simple/preferences/favicon.html:2
#, fuzzy
msgid "Favicon Resolver"
msgstr "favicon-resolver"
msgstr "Favicon Oplosser"
#: searx/templates/simple/preferences/favicon.html:15
msgid "Display favicons near search results"

View File

@ -8,21 +8,23 @@
# return42 <return42@users.noreply.translate.codeberg.org>, 2024.
# abhabongse <abhabongse@users.noreply.translate.codeberg.org>, 2024.
# tutakrab <tutakrab@users.noreply.translate.codeberg.org>, 2024.
# sahussawud <sahussawud@users.noreply.translate.codeberg.org>, 2024.
msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2024-10-05 06:24+0000\n"
"PO-Revision-Date: 2024-10-02 16:10+0000\n"
"Last-Translator: tutakrab <tutakrab@users.noreply.translate.codeberg.org>"
"PO-Revision-Date: 2024-11-06 07:26+0000\n"
"Last-Translator: sahussawud <sahussawud@users.noreply.translate.codeberg.org>"
"\n"
"Language-Team: Thai <https://translate.codeberg.org/projects/searxng/searxng/"
"th/>\n"
"Language: th\n"
"Language-Team: Thai "
"<https://translate.codeberg.org/projects/searxng/searxng/th/>\n"
"Plural-Forms: nplurals=1; plural=0;\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=1; plural=0;\n"
"X-Generator: Weblate 5.8.1\n"
"Generated-By: Babel 2.16.0\n"
#. CONSTANT_NAMES['NO_SUBGROUPING']
@ -163,7 +165,7 @@ msgstr "มืด"
#. STYLE_NAMES['BLACK']
#: searx/searxng.msg
msgid "black"
msgstr ""
msgstr "สีดำ"
#. BRAND_CUSTOM_LINKS['UPTIME']
#: searx/searxng.msg
@ -331,12 +333,12 @@ msgstr "ผู้เขียน"
#. SOCIAL_MEDIA_TERMS['THREAD OPEN']
#: searx/engines/discourse.py:149 searx/searxng.msg
msgid "open"
msgstr ""
msgstr "สร้าง"
#. SOCIAL_MEDIA_TERMS['THREAD CLOSED']
#: searx/engines/discourse.py:149 searx/searxng.msg
msgid "closed"
msgstr ""
msgstr "ลบ"
#. SOCIAL_MEDIA_TERMS['THREAD ANSWERED']
#: searx/engines/discourse.py:160 searx/searxng.msg
@ -450,7 +452,7 @@ msgstr "คำนวณ {functions} จากอาร์กิวเมนต
#: searx/engines/mozhi.py:57
msgid "Synonyms"
msgstr ""
msgstr "คำเหมือน"
#: searx/engines/openstreetmap.py:159
msgid "Get directions"
@ -538,8 +540,9 @@ msgid "hash digest"
msgstr "แฮชย่อย"
#: searx/plugins/hostnames.py:103
#, fuzzy
msgid "Hostnames plugin"
msgstr ""
msgstr "ชื่อโฮส ปลั๊กอิน"
#: searx/plugins/hostnames.py:104
msgid "Rewrite hostnames, remove results or prioritize them based on the hostname"
@ -1698,4 +1701,3 @@ msgstr "ซ่อนวิดีโอ"
#~ msgid "Engines cannot retrieve results"
#~ msgstr "เครื่องมือไม่สามารถดึงผลลัพธ์ได้"

View File

@ -3,7 +3,7 @@
from searx.search import SearchQuery, EngineRef
from searx.search.processors import online
from searx.engines import load_engines
import searx.search
from searx import engines
from tests import SearxTestCase
@ -22,10 +22,10 @@ TEST_ENGINE = {
class TestOnlineProcessor(SearxTestCase): # pylint: disable=missing-class-docstring
def setUp(self):
load_engines([TEST_ENGINE])
searx.search.initialize([TEST_ENGINE])
def tearDown(self):
load_engines([])
searx.search.load_engines([])
def _get_params(self, online_processor, search_query, engine_category):
params = online_processor.get_params(search_query, engine_category)

View File

@ -2,26 +2,11 @@
# pylint: disable=missing-module-docstring
from unittest.mock import MagicMock, Mock
from searx.engines import load_engines, mariadb_server
from searx.engines import mariadb_server
from tests import SearxTestCase
class MariadbServerTests(SearxTestCase): # pylint: disable=missing-class-docstring
def setUp(self):
load_engines(
[
{
'name': 'mariadb server',
'engine': 'mariadb_server',
'shortcut': 'mdb',
'timeout': 9.0,
'disabled': True,
}
]
)
def tearDown(self):
load_engines([])
def test_init_no_query_str_raises(self):
self.assertRaises(ValueError, lambda: mariadb_server.init({}))

View File

@ -1,28 +1,34 @@
# SPDX-License-Identifier: AGPL-3.0-or-later
# pylint: disable=missing-module-docstring
import logging
from datetime import datetime
from unittest.mock import Mock
from requests import HTTPError
from parameterized import parameterized
from searx.engines import load_engines, tineye
import searx.search
import searx.engines
from tests import SearxTestCase
class TinEyeTests(SearxTestCase): # pylint: disable=missing-class-docstring
def setUp(self):
load_engines([{'name': 'tineye', 'engine': 'tineye', 'shortcut': 'tin', 'timeout': 9.0, 'disabled': True}])
searx.search.initialize(
[{'name': 'tineye', 'engine': 'tineye', 'shortcut': 'tin', 'timeout': 9.0, 'disabled': True}]
)
self.tineye = searx.engines.engines['tineye']
self.tineye.logger.setLevel(logging.CRITICAL)
def tearDown(self):
load_engines([])
searx.search.load_engines([])
def test_status_code_raises(self):
response = Mock()
response.status_code = 401
response.raise_for_status.side_effect = HTTPError()
self.assertRaises(HTTPError, lambda: tineye.response(response))
self.assertRaises(HTTPError, lambda: self.tineye.response(response))
@parameterized.expand([(400), (422)])
def test_returns_empty_list(self, status_code):
@ -30,7 +36,7 @@ class TinEyeTests(SearxTestCase): # pylint: disable=missing-class-docstring
response.json.return_value = {}
response.status_code = status_code
response.raise_for_status.side_effect = HTTPError()
results = tineye.response(response)
results = self.tineye.response(response)
self.assertEqual(0, len(results))
def test_logs_format_for_422(self):
@ -39,9 +45,9 @@ class TinEyeTests(SearxTestCase): # pylint: disable=missing-class-docstring
response.status_code = 422
response.raise_for_status.side_effect = HTTPError()
with self.assertLogs(tineye.logger) as assert_logs_context:
tineye.response(response)
self.assertIn(tineye.FORMAT_NOT_SUPPORTED, ','.join(assert_logs_context.output))
with self.assertLogs(self.tineye.logger) as assert_logs_context:
self.tineye.response(response)
self.assertIn(self.tineye.FORMAT_NOT_SUPPORTED, ','.join(assert_logs_context.output))
def test_logs_signature_for_422(self):
response = Mock()
@ -49,9 +55,9 @@ class TinEyeTests(SearxTestCase): # pylint: disable=missing-class-docstring
response.status_code = 422
response.raise_for_status.side_effect = HTTPError()
with self.assertLogs(tineye.logger) as assert_logs_context:
tineye.response(response)
self.assertIn(tineye.NO_SIGNATURE_ERROR, ','.join(assert_logs_context.output))
with self.assertLogs(self.tineye.logger) as assert_logs_context:
self.tineye.response(response)
self.assertIn(self.tineye.NO_SIGNATURE_ERROR, ','.join(assert_logs_context.output))
def test_logs_download_for_422(self):
response = Mock()
@ -59,9 +65,9 @@ class TinEyeTests(SearxTestCase): # pylint: disable=missing-class-docstring
response.status_code = 422
response.raise_for_status.side_effect = HTTPError()
with self.assertLogs(tineye.logger) as assert_logs_context:
tineye.response(response)
self.assertIn(tineye.DOWNLOAD_ERROR, ','.join(assert_logs_context.output))
with self.assertLogs(self.tineye.logger) as assert_logs_context:
self.tineye.response(response)
self.assertIn(self.tineye.DOWNLOAD_ERROR, ','.join(assert_logs_context.output))
def test_logs_description_for_400(self):
description = 'There was a problem with that request. Error ID: ad5fc955-a934-43c1-8187-f9a61d301645'
@ -70,8 +76,8 @@ class TinEyeTests(SearxTestCase): # pylint: disable=missing-class-docstring
response.status_code = 400
response.raise_for_status.side_effect = HTTPError()
with self.assertLogs(tineye.logger) as assert_logs_context:
tineye.response(response)
with self.assertLogs(self.tineye.logger) as assert_logs_context:
self.tineye.response(response)
self.assertIn(description, ','.join(assert_logs_context.output))
def test_crawl_date_parses(self):
@ -90,5 +96,5 @@ class TinEyeTests(SearxTestCase): # pylint: disable=missing-class-docstring
]
}
response.status_code = 200
results = tineye.response(response)
results = self.tineye.response(response)
self.assertEqual(date, results[0]['publishedDate'])

View File

@ -2,7 +2,7 @@
# pylint: disable=missing-module-docstring
from parameterized.parameterized import parameterized
from searx.engines import load_engines
import searx.search
from searx.query import RawTextQuery
from tests import SearxTestCase
@ -218,10 +218,10 @@ class TestBang(SearxTestCase): # pylint:disable=missing-class-docstring
THE_QUERY = 'the query'
def setUp(self):
load_engines(TEST_ENGINES)
searx.search.initialize(TEST_ENGINES)
def tearDown(self):
load_engines([])
searx.search.load_engines([])
@parameterized.expand(SPECIFIC_BANGS)
def test_bang(self, bang: str):

View File

@ -2,9 +2,26 @@
# pylint: disable=missing-module-docstring
from searx.results import ResultContainer
import searx.search
from tests import SearxTestCase
def make_test_engine_dict(**kwargs) -> dict:
test_engine = {
# fmt: off
'name': None,
'engine': None,
'categories': 'general',
'shortcut': 'dummy',
'timeout': 3.0,
'tokens': [],
# fmt: on
}
test_engine.update(**kwargs)
return test_engine
def fake_result(url='https://aa.bb/cc?dd=ee#ff', title='aaa', content='bbb', engine='wikipedia', **kwargs):
result = {
# fmt: off
@ -19,23 +36,40 @@ def fake_result(url='https://aa.bb/cc?dd=ee#ff', title='aaa', content='bbb', eng
class ResultContainerTestCase(SearxTestCase): # pylint: disable=missing-class-docstring
def setUp(self) -> None:
stract_engine = make_test_engine_dict(name="stract", engine="stract", shortcut="stra")
duckduckgo_engine = make_test_engine_dict(name="duckduckgo", engine="duckduckgo", shortcut="ddg")
mojeek_engine = make_test_engine_dict(name="mojeek", engine="mojeek", shortcut="mjk")
searx.search.initialize([stract_engine, duckduckgo_engine, mojeek_engine])
self.container = ResultContainer()
def tearDown(self):
searx.search.load_engines([])
def test_empty(self):
c = ResultContainer()
self.assertEqual(c.get_ordered_results(), [])
self.assertEqual(self.container.get_ordered_results(), [])
def test_one_result(self):
c = ResultContainer()
c.extend('wikipedia', [fake_result()])
self.assertEqual(c.results_length(), 1)
self.container.extend('wikipedia', [fake_result()])
self.assertEqual(self.container.results_length(), 1)
def test_one_suggestion(self):
c = ResultContainer()
c.extend('wikipedia', [fake_result(suggestion=True)])
self.assertEqual(len(c.suggestions), 1)
self.assertEqual(c.results_length(), 0)
self.container.extend('wikipedia', [fake_result(suggestion=True)])
self.assertEqual(len(self.container.suggestions), 1)
self.assertEqual(self.container.results_length(), 0)
def test_result_merge(self):
c = ResultContainer()
c.extend('wikipedia', [fake_result()])
c.extend('wikidata', [fake_result(), fake_result(url='https://example.com/')])
self.assertEqual(c.results_length(), 2)
self.container.extend('wikipedia', [fake_result()])
self.container.extend('wikidata', [fake_result(), fake_result(url='https://example.com/')])
self.assertEqual(self.container.results_length(), 2)
def test_result_merge_by_title(self):
self.container.extend('stract', [fake_result(engine='stract', title='short title')])
self.container.extend('duckduckgo', [fake_result(engine='duckduckgo', title='normal title')])
self.container.extend('mojeek', [fake_result(engine='mojeek', title='this long long title')])
self.assertEqual(self.container.get_ordered_results()[0].get('title', ''), 'this long long title')