forked from Icycoide/searxng
[mod] pylint all files with one profile / drop PYLINT_SEARXNG_DISABLE_OPTION
In the past, some files were tested with the standard profile, others with a profile in which most of the messages were switched off ... some files were not checked at all. - ``PYLINT_SEARXNG_DISABLE_OPTION`` has been abolished - the distinction ``# lint: pylint`` is no longer necessary - the pylint tasks have been reduced from three to two 1. ./searx/engines -> lint engines with additional builtins 2. ./searx ./searxng_extra ./tests -> lint all other python files Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
This commit is contained in:
parent
8205f170ff
commit
542f7d0d7b
118 changed files with 261 additions and 369 deletions
|
@ -1,5 +1,7 @@
|
|||
import os
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
# pylint: disable=missing-module-docstring
|
||||
|
||||
import os
|
||||
import aiounittest
|
||||
|
||||
os.environ.pop('SEARX_DEBUG', None)
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
# pylint: disable=missing-module-docstring, cyclic-import
|
|
@ -1,5 +1,4 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
# lint: pylint
|
||||
"""Shared testing code."""
|
||||
|
||||
# pylint: disable=missing-function-docstring
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
# lint: pylint
|
||||
# pylint: disable=missing-module-docstring,missing-function-docstring
|
||||
|
||||
from time import sleep
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
# pylint: disable=missing-module-docstring
|
||||
|
||||
import os
|
||||
from os.path import dirname, sep, abspath
|
||||
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
# pylint: disable=missing-module-docstring
|
||||
|
||||
'''
|
||||
searx is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
# pylint: disable=missing-module-docstring
|
||||
|
||||
from collections import defaultdict
|
||||
import mock
|
||||
from searx.engines import xpath
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
# pylint: disable=missing-module-docstring
|
|
@ -1,4 +1,5 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
# pylint: disable=missing-module-docstring, protected-access
|
||||
|
||||
from mock import patch
|
||||
|
||||
|
@ -8,7 +9,7 @@ from searx.network.network import Network, NETWORKS, initialize
|
|||
from tests import SearxTestCase
|
||||
|
||||
|
||||
class TestNetwork(SearxTestCase):
|
||||
class TestNetwork(SearxTestCase): # pylint: disable=missing-class-docstring
|
||||
def setUp(self):
|
||||
initialize()
|
||||
|
||||
|
@ -121,7 +122,7 @@ class TestNetwork(SearxTestCase):
|
|||
await network.aclose()
|
||||
|
||||
|
||||
class TestNetworkRequestRetries(SearxTestCase):
|
||||
class TestNetworkRequestRetries(SearxTestCase): # pylint: disable=missing-class-docstring
|
||||
|
||||
TEXT = 'Lorem Ipsum'
|
||||
|
||||
|
@ -129,7 +130,7 @@ class TestNetworkRequestRetries(SearxTestCase):
|
|||
def get_response_404_then_200(cls):
|
||||
first = True
|
||||
|
||||
async def get_response(*args, **kwargs):
|
||||
async def get_response(*args, **kwargs): # pylint: disable=unused-argument
|
||||
nonlocal first
|
||||
if first:
|
||||
first = False
|
||||
|
@ -169,7 +170,7 @@ class TestNetworkRequestRetries(SearxTestCase):
|
|||
async def test_retries_exception_then_200(self):
|
||||
request_count = 0
|
||||
|
||||
async def get_response(*args, **kwargs):
|
||||
async def get_response(*args, **kwargs): # pylint: disable=unused-argument
|
||||
nonlocal request_count
|
||||
request_count += 1
|
||||
if request_count < 3:
|
||||
|
@ -194,7 +195,7 @@ class TestNetworkRequestRetries(SearxTestCase):
|
|||
await network.aclose()
|
||||
|
||||
|
||||
class TestNetworkStreamRetries(SearxTestCase):
|
||||
class TestNetworkStreamRetries(SearxTestCase): # pylint: disable=missing-class-docstring
|
||||
|
||||
TEXT = 'Lorem Ipsum'
|
||||
|
||||
|
@ -202,7 +203,7 @@ class TestNetworkStreamRetries(SearxTestCase):
|
|||
def get_response_exception_then_200(cls):
|
||||
first = True
|
||||
|
||||
def stream(*args, **kwargs):
|
||||
def stream(*args, **kwargs): # pylint: disable=unused-argument
|
||||
nonlocal first
|
||||
if first:
|
||||
first = False
|
||||
|
@ -228,7 +229,7 @@ class TestNetworkStreamRetries(SearxTestCase):
|
|||
async def test_retries_exception(self):
|
||||
first = True
|
||||
|
||||
def stream(*args, **kwargs):
|
||||
def stream(*args, **kwargs): # pylint: disable=unused-argument
|
||||
nonlocal first
|
||||
if first:
|
||||
first = False
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
# pylint: disable=missing-module-docstring
|
||||
|
||||
from mock import Mock
|
||||
|
||||
|
@ -6,7 +7,7 @@ from searx.answerers import answerers
|
|||
from tests import SearxTestCase
|
||||
|
||||
|
||||
class AnswererTest(SearxTestCase):
|
||||
class AnswererTest(SearxTestCase): # pylint: disable=missing-class-docstring
|
||||
def test_unicode_input(self):
|
||||
query = Mock()
|
||||
unicode_payload = 'árvíztűrő tükörfúrógép'
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
# pylint: disable=missing-module-docstring
|
||||
|
||||
from searx import settings, engines
|
||||
from tests import SearxTestCase
|
||||
|
||||
|
||||
class TestEnginesInit(SearxTestCase):
|
||||
class TestEnginesInit(SearxTestCase): # pylint: disable=missing-class-docstring
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
settings['outgoing']['using_tor_proxy'] = False
|
||||
|
@ -19,7 +22,7 @@ class TestEnginesInit(SearxTestCase):
|
|||
self.assertIn('engine1', engines.engines)
|
||||
self.assertIn('engine2', engines.engines)
|
||||
|
||||
def test_initialize_engines_exclude_onions(self):
|
||||
def test_initialize_engines_exclude_onions(self): # pylint: disable=invalid-name
|
||||
settings['outgoing']['using_tor_proxy'] = False
|
||||
engine_list = [
|
||||
{'engine': 'dummy', 'name': 'engine1', 'shortcut': 'e1', 'categories': 'general'},
|
||||
|
@ -31,7 +34,7 @@ class TestEnginesInit(SearxTestCase):
|
|||
self.assertIn('engine1', engines.engines)
|
||||
self.assertNotIn('onions', engines.categories)
|
||||
|
||||
def test_initialize_engines_include_onions(self):
|
||||
def test_initialize_engines_include_onions(self): # pylint: disable=invalid-name
|
||||
settings['outgoing']['using_tor_proxy'] = True
|
||||
settings['outgoing']['extra_proxy_timeout'] = 100.0
|
||||
engine_list = [
|
||||
|
@ -59,7 +62,7 @@ class TestEnginesInit(SearxTestCase):
|
|||
engine_list = [
|
||||
{'engine': 'dummy', 'shortcut': 'e1', 'categories': 'general'},
|
||||
]
|
||||
with self.assertLogs('searx.engines', level='ERROR') as cm:
|
||||
with self.assertLogs('searx.engines', level='ERROR') as cm: # pylint: disable=invalid-name
|
||||
engines.load_engines(engine_list)
|
||||
self.assertEqual(len(engines.engines), 0)
|
||||
self.assertEqual(cm.output, ['ERROR:searx.engines:An engine does not have a "name" field'])
|
||||
|
@ -69,7 +72,7 @@ class TestEnginesInit(SearxTestCase):
|
|||
engine_list = [
|
||||
{'name': 'engine2', 'shortcut': 'e2', 'categories': 'onions'},
|
||||
]
|
||||
with self.assertLogs('searx.engines', level='ERROR') as cm:
|
||||
with self.assertLogs('searx.engines', level='ERROR') as cm: # pylint: disable=invalid-name
|
||||
engines.load_engines(engine_list)
|
||||
self.assertEqual(len(engines.engines), 0)
|
||||
self.assertEqual(
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
# pylint: disable=missing-module-docstring
|
||||
|
||||
from tests import SearxTestCase
|
||||
import searx.exceptions
|
||||
from searx import get_setting
|
||||
|
||||
|
||||
class TestExceptions(SearxTestCase):
|
||||
class TestExceptions(SearxTestCase): # pylint: disable=missing-class-docstring
|
||||
def test_default_suspend_time(self):
|
||||
with self.assertRaises(searx.exceptions.SearxEngineAccessDeniedException) as e:
|
||||
raise searx.exceptions.SearxEngineAccessDeniedException()
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
# pylint: disable=missing-module-docstring
|
||||
|
||||
from searx.external_bang import (
|
||||
get_node,
|
||||
resolve_bang_definition,
|
||||
|
@ -31,9 +34,9 @@ TEST_DB = {
|
|||
}
|
||||
|
||||
|
||||
class TestGetNode(SearxTestCase):
|
||||
class TestGetNode(SearxTestCase): # pylint: disable=missing-class-docstring
|
||||
|
||||
DB = {
|
||||
DB = { # pylint:disable=invalid-name
|
||||
'trie': {
|
||||
'exam': {
|
||||
'ple': 'test',
|
||||
|
@ -62,7 +65,7 @@ class TestGetNode(SearxTestCase):
|
|||
self.assertEqual(after, 's')
|
||||
|
||||
|
||||
class TestResolveBangDefinition(SearxTestCase):
|
||||
class TestResolveBangDefinition(SearxTestCase): # pylint:disable=missing-class-docstring
|
||||
def test_https(self):
|
||||
url, rank = resolve_bang_definition('//example.com/' + chr(2) + chr(1) + '42', 'query')
|
||||
self.assertEqual(url, 'https://example.com/query')
|
||||
|
@ -74,7 +77,7 @@ class TestResolveBangDefinition(SearxTestCase):
|
|||
self.assertEqual(rank, 0)
|
||||
|
||||
|
||||
class TestGetBangDefinitionAndAutocomplete(SearxTestCase):
|
||||
class TestGetBangDefinitionAndAutocomplete(SearxTestCase): # pylint:disable=missing-class-docstring
|
||||
def test_found(self):
|
||||
bang_definition, new_autocomplete = get_bang_definition_and_autocomplete('exam', external_bangs_db=TEST_DB)
|
||||
self.assertEqual(bang_definition, TEST_DB['trie']['exam'][LEAF_KEY])
|
||||
|
@ -106,7 +109,7 @@ class TestGetBangDefinitionAndAutocomplete(SearxTestCase):
|
|||
self.assertEqual(new_autocomplete, [])
|
||||
|
||||
|
||||
class TestExternalBangJson(SearxTestCase):
|
||||
class TestExternalBangJson(SearxTestCase): # pylint:disable=missing-class-docstring
|
||||
def test_no_external_bang_query(self):
|
||||
result = get_bang_url(SearchQuery('test', engineref_list=[EngineRef('wikipedia', 'general')]))
|
||||
self.assertEqual(result, None)
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
# lint: pylint
|
||||
# pylint: disable=missing-module-docstring
|
||||
"""Test some code from module :py:obj:`searx.locales`"""
|
||||
|
||||
from searx import locales
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
# pylint: disable=missing-module-docstring
|
||||
|
||||
from mock import Mock
|
||||
|
||||
from searx import (
|
||||
plugins,
|
||||
|
@ -6,21 +9,20 @@ from searx import (
|
|||
botdetection,
|
||||
)
|
||||
|
||||
from mock import Mock
|
||||
from tests import SearxTestCase
|
||||
|
||||
|
||||
def get_search_mock(query, **kwargs):
|
||||
return Mock(search_query=Mock(query=query, **kwargs), result_container=Mock(answers=dict()))
|
||||
return Mock(search_query=Mock(query=query, **kwargs), result_container=Mock(answers={}))
|
||||
|
||||
|
||||
class PluginMock:
|
||||
class PluginMock: # pylint: disable=missing-class-docstring, too-few-public-methods
|
||||
default_on = False
|
||||
name = 'Default plugin'
|
||||
description = 'Default plugin description'
|
||||
|
||||
|
||||
class PluginStoreTest(SearxTestCase):
|
||||
class PluginStoreTest(SearxTestCase): # pylint: disable=missing-class-docstring
|
||||
def test_PluginStore_init(self):
|
||||
store = plugins.PluginStore()
|
||||
self.assertTrue(isinstance(store.plugins, list) and len(store.plugins) == 0)
|
||||
|
@ -46,7 +48,7 @@ class PluginStoreTest(SearxTestCase):
|
|||
self.assertTrue(testplugin.asdf.called) # pylint: disable=E1101
|
||||
|
||||
|
||||
class SelfIPTest(SearxTestCase):
|
||||
class SelfIPTest(SearxTestCase): # pylint: disable=missing-class-docstring
|
||||
def test_PluginStore_init(self):
|
||||
plugin = plugins.load_and_initialize_plugin('searx.plugins.self_info', False, (None, {}))
|
||||
store = plugins.PluginStore()
|
||||
|
@ -99,7 +101,7 @@ class SelfIPTest(SearxTestCase):
|
|||
self.assertFalse('user-agent' in search.result_container.answers)
|
||||
|
||||
|
||||
class HashPluginTest(SearxTestCase):
|
||||
class HashPluginTest(SearxTestCase): # pylint: disable=missing-class-docstring
|
||||
def test_PluginStore_init(self):
|
||||
store = plugins.PluginStore()
|
||||
plugin = plugins.load_and_initialize_plugin('searx.plugins.hash_plugin', False, (None, {}))
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
# pylint: disable=missing-module-docstring, invalid-name
|
||||
|
||||
from searx.locales import locales_initialize
|
||||
from searx.preferences import (
|
||||
EnumStringSetting,
|
||||
|
@ -12,13 +15,13 @@ from tests import SearxTestCase
|
|||
locales_initialize()
|
||||
|
||||
|
||||
class PluginStub:
|
||||
class PluginStub: # pylint: disable=missing-class-docstring, too-few-public-methods
|
||||
def __init__(self, plugin_id, default_on):
|
||||
self.id = plugin_id
|
||||
self.default_on = default_on
|
||||
|
||||
|
||||
class TestSettings(SearxTestCase):
|
||||
class TestSettings(SearxTestCase): # pylint: disable=missing-class-docstring
|
||||
# map settings
|
||||
|
||||
def test_map_setting_invalid_default_value(self):
|
||||
|
@ -118,9 +121,9 @@ class TestSettings(SearxTestCase):
|
|||
self.assertEqual(set(setting.get_enabled()), set(['plugin1', 'plugin3']))
|
||||
|
||||
|
||||
class TestPreferences(SearxTestCase):
|
||||
class TestPreferences(SearxTestCase): # pylint: disable=missing-class-docstring
|
||||
def test_encode(self):
|
||||
from searx.preferences import Preferences
|
||||
from searx.preferences import Preferences # pylint: disable=import-outside-toplevel
|
||||
|
||||
pref = Preferences(['simple'], ['general'], {}, [])
|
||||
url_params = (
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
# pylint: disable=missing-module-docstring
|
||||
|
||||
from searx import settings
|
||||
from searx.engines import load_engines
|
||||
from searx.query import RawTextQuery
|
||||
|
@ -16,7 +19,7 @@ TEST_ENGINES = [
|
|||
]
|
||||
|
||||
|
||||
class TestQuery(SearxTestCase):
|
||||
class TestQuery(SearxTestCase): # pylint:disable=missing-class-docstring
|
||||
def test_simple_query(self):
|
||||
query_text = 'the query'
|
||||
query = RawTextQuery(query_text, [])
|
||||
|
@ -56,7 +59,7 @@ class TestQuery(SearxTestCase):
|
|||
self.assertEqual(query.getFullQuery(), '<8 another text')
|
||||
|
||||
|
||||
class TestLanguageParser(SearxTestCase):
|
||||
class TestLanguageParser(SearxTestCase): # pylint:disable=missing-class-docstring
|
||||
def test_language_code(self):
|
||||
language = 'es-ES'
|
||||
query_text = 'the query'
|
||||
|
@ -144,7 +147,7 @@ class TestLanguageParser(SearxTestCase):
|
|||
self.assertEqual(query.autocomplete_list, [':zh-cn', ':zh-hk', ':zh-tw'])
|
||||
|
||||
|
||||
class TestTimeoutParser(SearxTestCase):
|
||||
class TestTimeoutParser(SearxTestCase): # pylint:disable=missing-class-docstring
|
||||
def test_timeout_below100(self):
|
||||
query_text = '<3 the query'
|
||||
query = RawTextQuery(query_text, [])
|
||||
|
@ -196,7 +199,7 @@ class TestTimeoutParser(SearxTestCase):
|
|||
self.assertEqual(query.autocomplete_list, ['<3', '<850'])
|
||||
|
||||
|
||||
class TestExternalBangParser(SearxTestCase):
|
||||
class TestExternalBangParser(SearxTestCase): # pylint:disable=missing-class-docstring
|
||||
def test_external_bang(self):
|
||||
query_text = '!!ddg the query'
|
||||
query = RawTextQuery(query_text, [])
|
||||
|
@ -226,7 +229,7 @@ class TestExternalBangParser(SearxTestCase):
|
|||
self.assertEqual(query.get_autocomplete_full_query(a), a + ' the query')
|
||||
|
||||
|
||||
class TestBang(SearxTestCase):
|
||||
class TestBang(SearxTestCase): # pylint:disable=missing-class-docstring
|
||||
|
||||
SPECIFIC_BANGS = ['!dummy_engine', '!du', '!general']
|
||||
THE_QUERY = 'the query'
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
# pylint: disable=missing-module-docstring
|
||||
|
||||
from searx.results import ResultContainer
|
||||
from tests import SearxTestCase
|
||||
|
@ -17,8 +18,7 @@ def fake_result(url='https://aa.bb/cc?dd=ee#ff', title='aaa', content='bbb', eng
|
|||
return result
|
||||
|
||||
|
||||
# TODO
|
||||
class ResultContainerTestCase(SearxTestCase):
|
||||
class ResultContainerTestCase(SearxTestCase): # pylint: disable=missing-class-docstring
|
||||
def test_empty(self):
|
||||
c = ResultContainer()
|
||||
self.assertEqual(c.get_ordered_results(), [])
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
# pylint: disable=missing-module-docstring, invalid-name
|
||||
|
||||
from copy import copy
|
||||
|
||||
|
@ -23,7 +24,7 @@ TEST_ENGINES = [
|
|||
]
|
||||
|
||||
|
||||
class SearchQueryTestCase(SearxTestCase):
|
||||
class SearchQueryTestCase(SearxTestCase): # pylint: disable=missing-class-docstring
|
||||
def test_repr(self):
|
||||
s = SearchQuery('test', [EngineRef('bing', 'general')], 'all', 0, 1, '1', 5.0, 'g')
|
||||
self.assertEqual(
|
||||
|
@ -42,10 +43,10 @@ class SearchQueryTestCase(SearxTestCase):
|
|||
self.assertEqual(s, t)
|
||||
|
||||
|
||||
class SearchTestCase(SearxTestCase):
|
||||
class SearchTestCase(SearxTestCase): # pylint: disable=missing-class-docstring
|
||||
def setUp(self):
|
||||
|
||||
from searx import webapp # pylint disable=import-outside-toplevel
|
||||
from searx import webapp # pylint: disable=import-outside-toplevel
|
||||
|
||||
self.app = webapp.app
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
# pylint: disable=missing-module-docstring
|
||||
|
||||
from os.path import dirname, join, abspath
|
||||
from unittest.mock import patch
|
||||
|
@ -11,7 +12,7 @@ from tests import SearxTestCase
|
|||
test_dir = abspath(dirname(__file__))
|
||||
|
||||
|
||||
class TestLoad(SearxTestCase):
|
||||
class TestLoad(SearxTestCase): # pylint: disable=missing-class-docstring
|
||||
def test_load_zero(self):
|
||||
with self.assertRaises(SearxSettingsException):
|
||||
settings_loader.load_yaml('/dev/zero')
|
||||
|
@ -29,7 +30,7 @@ class TestLoad(SearxTestCase):
|
|||
self.assertEqual(settings_loader.existing_filename_or_none(bad_settings_path), bad_settings_path)
|
||||
|
||||
|
||||
class TestDefaultSettings(SearxTestCase):
|
||||
class TestDefaultSettings(SearxTestCase): # pylint: disable=missing-class-docstring
|
||||
def test_load(self):
|
||||
settings, msg = settings_loader.load_settings(load_user_settings=False)
|
||||
self.assertTrue(msg.startswith('load the default settings from'))
|
||||
|
@ -43,7 +44,7 @@ class TestDefaultSettings(SearxTestCase):
|
|||
self.assertTrue(isinstance(settings['default_doi_resolver'], str))
|
||||
|
||||
|
||||
class TestUserSettings(SearxTestCase):
|
||||
class TestUserSettings(SearxTestCase): # pylint: disable=missing-class-docstring
|
||||
def test_is_use_default_settings(self):
|
||||
self.assertFalse(settings_loader.is_use_default_settings({}))
|
||||
self.assertTrue(settings_loader.is_use_default_settings({'use_default_settings': True}))
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
# pylint: disable=missing-module-docstring, invalid-name
|
||||
|
||||
import lxml.etree
|
||||
from lxml import html
|
||||
|
||||
|
@ -8,7 +10,7 @@ from searx import utils
|
|||
from tests import SearxTestCase
|
||||
|
||||
|
||||
class TestUtils(SearxTestCase):
|
||||
class TestUtils(SearxTestCase): # pylint: disable=missing-class-docstring
|
||||
def test_gen_useragent(self):
|
||||
self.assertIsInstance(utils.gen_useragent(), str)
|
||||
self.assertIsNotNone(utils.gen_useragent())
|
||||
|
@ -85,8 +87,8 @@ class TestUtils(SearxTestCase):
|
|||
utils.extract_url([], 'https://example.com')
|
||||
|
||||
def test_html_to_text_invalid(self):
|
||||
html = '<p><b>Lorem ipsum</i>dolor sit amet</p>'
|
||||
self.assertEqual(utils.html_to_text(html), "Lorem ipsum")
|
||||
_html = '<p><b>Lorem ipsum</i>dolor sit amet</p>'
|
||||
self.assertEqual(utils.html_to_text(_html), "Lorem ipsum")
|
||||
|
||||
def test_ecma_unscape(self):
|
||||
self.assertEqual(utils.ecma_unescape('text%20with%20space'), 'text with space')
|
||||
|
@ -94,9 +96,9 @@ class TestUtils(SearxTestCase):
|
|||
self.assertEqual(utils.ecma_unescape('text using %u: %u5409, %u4E16%u754c'), 'text using %u: 吉, 世界')
|
||||
|
||||
|
||||
class TestHTMLTextExtractor(SearxTestCase):
|
||||
class TestHTMLTextExtractor(SearxTestCase): # pylint: disable=missing-class-docstring
|
||||
def setUp(self):
|
||||
self.html_text_extractor = utils._HTMLTextExtractor()
|
||||
self.html_text_extractor = utils._HTMLTextExtractor() # pylint: disable=protected-access
|
||||
|
||||
def test__init__(self):
|
||||
self.assertEqual(self.html_text_extractor.result, [])
|
||||
|
@ -117,11 +119,11 @@ class TestHTMLTextExtractor(SearxTestCase):
|
|||
|
||||
def test_invalid_html(self):
|
||||
text = '<p><b>Lorem ipsum</i>dolor sit amet</p>'
|
||||
with self.assertRaises(utils._HTMLTextExtractorException):
|
||||
with self.assertRaises(utils._HTMLTextExtractorException): # pylint: disable=protected-access
|
||||
self.html_text_extractor.feed(text)
|
||||
|
||||
|
||||
class TestXPathUtils(SearxTestCase):
|
||||
class TestXPathUtils(SearxTestCase): # pylint: disable=missing-class-docstring
|
||||
|
||||
TEST_DOC = """<ul>
|
||||
<li>Text in <b>bold</b> and <i>italic</i> </li>
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
# pylint: disable=missing-module-docstring
|
||||
|
||||
from searx.preferences import Preferences
|
||||
from searx.engines import engines
|
||||
|
@ -24,19 +25,19 @@ TEST_ENGINES = [
|
|||
SEARCHQUERY = [EngineRef(PRIVATE_ENGINE_NAME, 'general')]
|
||||
|
||||
|
||||
class ValidateQueryCase(SearxTestCase):
|
||||
class ValidateQueryCase(SearxTestCase): # pylint: disable=missing-class-docstring
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
searx.search.initialize(TEST_ENGINES)
|
||||
|
||||
def test_query_private_engine_without_token(self):
|
||||
def test_query_private_engine_without_token(self): # pylint:disable=invalid-name
|
||||
preferences = Preferences(['simple'], ['general'], engines, [])
|
||||
valid, unknown, invalid_token = validate_engineref_list(SEARCHQUERY, preferences)
|
||||
self.assertEqual(len(valid), 0)
|
||||
self.assertEqual(len(unknown), 0)
|
||||
self.assertEqual(len(invalid_token), 1)
|
||||
|
||||
def test_query_private_engine_with_incorrect_token(self):
|
||||
def test_query_private_engine_with_incorrect_token(self): # pylint:disable=invalid-name
|
||||
preferences_with_tokens = Preferences(['simple'], ['general'], engines, [])
|
||||
preferences_with_tokens.parse_dict({'tokens': 'bad-token'})
|
||||
valid, unknown, invalid_token = validate_engineref_list(SEARCHQUERY, preferences_with_tokens)
|
||||
|
@ -44,7 +45,7 @@ class ValidateQueryCase(SearxTestCase):
|
|||
self.assertEqual(len(unknown), 0)
|
||||
self.assertEqual(len(invalid_token), 1)
|
||||
|
||||
def test_query_private_engine_with_correct_token(self):
|
||||
def test_query_private_engine_with_correct_token(self): # pylint:disable=invalid-name
|
||||
preferences_with_tokens = Preferences(['simple'], ['general'], engines, [])
|
||||
preferences_with_tokens.parse_dict({'tokens': 'my-token'})
|
||||
valid, unknown, invalid_token = validate_engineref_list(SEARCHQUERY, preferences_with_tokens)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
# pylint: disable=missing-module-docstring
|
||||
|
||||
import json
|
||||
from urllib.parse import ParseResult
|
||||
|
@ -11,15 +12,15 @@ from searx.preferences import Preferences
|
|||
from tests import SearxTestCase
|
||||
|
||||
|
||||
class ViewsTestCase(SearxTestCase):
|
||||
class ViewsTestCase(SearxTestCase): # pylint: disable=missing-class-docstring, too-many-public-methods
|
||||
def setUp(self):
|
||||
# skip init function (no external HTTP request)
|
||||
def dummy(*args, **kwargs):
|
||||
def dummy(*args, **kwargs): # pylint: disable=unused-argument
|
||||
pass
|
||||
|
||||
self.setattr4test(searx.search.processors, 'initialize_processor', dummy)
|
||||
|
||||
from searx import webapp # pylint disable=import-outside-toplevel
|
||||
from searx import webapp # pylint: disable=import-outside-toplevel
|
||||
|
||||
webapp.app.config['TESTING'] = True # to get better error messages
|
||||
self.app = webapp.app.test_client()
|
||||
|
@ -60,10 +61,10 @@ class ViewsTestCase(SearxTestCase):
|
|||
Timing(engine='youtube', total=0.9, load=0.6),
|
||||
]
|
||||
|
||||
def search_mock(search_self, *args):
|
||||
def search_mock(search_self, *args): # pylint: disable=unused-argument
|
||||
search_self.result_container = Mock(
|
||||
get_ordered_results=lambda: test_results,
|
||||
answers=dict(),
|
||||
answers={},
|
||||
corrections=set(),
|
||||
suggestions=set(),
|
||||
infoboxes=[],
|
||||
|
@ -87,7 +88,8 @@ class ViewsTestCase(SearxTestCase):
|
|||
|
||||
self.setattr4test(Preferences, 'get_value', preferences_get_value)
|
||||
|
||||
self.maxDiff = None # to see full diffs
|
||||
# to see full diffs
|
||||
self.maxDiff = None # pylint: disable=invalid-name
|
||||
|
||||
def test_index_empty(self):
|
||||
result = self.app.post('/')
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
# pylint: disable=missing-module-docstring
|
||||
|
||||
import mock
|
||||
from searx import webutils
|
||||
from tests import SearxTestCase
|
||||
|
||||
|
||||
class TestWebUtils(SearxTestCase):
|
||||
class TestWebUtils(SearxTestCase): # pylint: disable=missing-class-docstring
|
||||
def test_prettify_url(self):
|
||||
data = (
|
||||
('https://searx.me/', 'https://searx.me/'),
|
||||
|
@ -32,6 +34,7 @@ class TestWebUtils(SearxTestCase):
|
|||
query = 'a test'
|
||||
self.assertEqual(webutils.highlight_content(content, query), '<span class="highlight">a</span>')
|
||||
|
||||
# pylint: disable=line-too-long
|
||||
data = (
|
||||
('" test "', 'a test string', 'a <span class="highlight">test</span> string'),
|
||||
('"a"', 'this is a test string', 'this is <span class="highlight">a</span> test string'),
|
||||
|
@ -67,7 +70,7 @@ class TestWebUtils(SearxTestCase):
|
|||
self.assertEqual(webutils.highlight_content(content, query), expected)
|
||||
|
||||
|
||||
class TestUnicodeWriter(SearxTestCase):
|
||||
class TestUnicodeWriter(SearxTestCase): # pylint: disable=missing-class-docstring
|
||||
def setUp(self):
|
||||
self.unicode_writer = webutils.CSVWriter(mock.MagicMock())
|
||||
|
||||
|
@ -82,7 +85,7 @@ class TestUnicodeWriter(SearxTestCase):
|
|||
self.assertEqual(self.unicode_writer.writerow.call_count, len(rows))
|
||||
|
||||
|
||||
class TestNewHmac(SearxTestCase):
|
||||
class TestNewHmac(SearxTestCase): # pylint: disable=missing-class-docstring
|
||||
def test_bytes(self):
|
||||
data = b'http://example.com'
|
||||
with self.assertRaises(AttributeError):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue