SearXNG is a free internet metasearch engine which aggregates results from various search services and databases. Users are neither tracked nor profiled.
Python bingbravedegoogleduckduckgogooglemetasearchprivacypythonqwantsearchsearch-enginesearxsearxngstartpageyahoo
[fix] unit tests: call searx.search.initialize in test's setUp
Markus Heiserbb04699b17e0
diff --git a/tests/unit/processors/test_online.py b/tests/unit/processors/test_online.pyindex 10e0deb97..fcb01587d 100644--- a/tests/unit/processors/test_online.py+++ b/tests/unit/processors/test_online.py@@ -3,7 +3,7 @@from searx.search import SearchQuery, EngineReffrom searx.search.processors import online-from searx.engines import load_engines+import searx.searchfrom searx import enginesfrom tests import SearxTestCase@@ -22,10 +22,10 @@ TEST_ENGINE = {class TestOnlineProcessor(SearxTestCase): # pylint: disable=missing-class-docstringdef 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)diff --git a/tests/unit/test_engine_mariadb_server.py b/tests/unit/test_engine_mariadb_server.pyindex 423132e34..c4144a601 100644--- a/tests/unit/test_engine_mariadb_server.py+++ b/tests/unit/test_engine_mariadb_server.py@@ -2,26 +2,11 @@# pylint: disable=missing-module-docstringfrom unittest.mock import MagicMock, Mock-from searx.engines import load_engines, mariadb_server+from searx.engines import mariadb_serverfrom tests import SearxTestCaseclass 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({}))diff --git a/tests/unit/test_engine_tineye.py b/tests/unit/test_engine_tineye.pyindex 5855a7313..7dc8233d4 100644--- a/tests/unit/test_engine_tineye.py+++ b/tests/unit/test_engine_tineye.py@@ -1,28 +1,34 @@# SPDX-License-Identifier: AGPL-3.0-or-later# pylint: disable=missing-module-docstring-+import loggingfrom datetime import datetimefrom unittest.mock import Mockfrom requests import HTTPErrorfrom parameterized import parameterized-from searx.engines import load_engines, tineye+import searx.search+import searx.enginesfrom tests import SearxTestCaseclass TinEyeTests(SearxTestCase): # pylint: disable=missing-class-docstringdef 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 = 401response.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-docstringresponse.json.return_value = {}response.status_code = status_coderesponse.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-docstringresponse.status_code = 422response.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-docstringresponse.status_code = 422response.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-docstringresponse.status_code = 422response.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-docstringresponse.status_code = 400response.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'])diff --git a/tests/unit/test_query.py b/tests/unit/test_query.pyindex 601a6e60d..00c53edc7 100644--- a/tests/unit/test_query.py+++ b/tests/unit/test_query.py@@ -2,7 +2,7 @@# pylint: disable=missing-module-docstringfrom parameterized.parameterized import parameterized-from searx.engines import load_engines+import searx.searchfrom searx.query import RawTextQueryfrom tests import SearxTestCase@@ -218,10 +218,10 @@ class TestBang(SearxTestCase): # pylint:disable=missing-class-docstringTHE_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):diff --git a/tests/unit/test_results.py b/tests/unit/test_results.pyindex 608d3c8c3..740d36a03 100644--- a/tests/unit/test_results.py+++ b/tests/unit/test_results.py@@ -2,7 +2,7 @@# pylint: disable=missing-module-docstringfrom searx.results import ResultContainer-from searx.engines import load_engines+import searx.searchfrom tests import SearxTestCase@@ -36,17 +36,16 @@ def fake_result(url='https://aa.bb/cc?dd=ee#ff', title='aaa', content='bbb', engclass 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")-- load_engines([stract_engine, duckduckgo_engine, mojeek_engine])-+ searx.search.initialize([stract_engine, duckduckgo_engine, mojeek_engine])self.container = ResultContainer()def tearDown(self):- load_engines([])+ searx.search.load_engines([])def test_empty(self):self.assertEqual(self.container.get_ordered_results(), [])