summaryrefslogtreecommitdiff
path: root/tests
AgeCommit message (Collapse)Author
2025-12-02[mod] client/simple: client plugins (#5406)Ivan Gabaldon
* [mod] client/simple: client plugins Defines a new interface for client side *"plugins"* that coexist with server side plugin system. Each plugin (e.g., `InfiniteScroll`) extends the base `ts Plugin`. Client side plugins are independent and lazy‑loaded via `router.ts` when their `load()` conditions are met. On each navigation request, all applicable plugins are instanced. Since these are client side plugins, we can only invoke them once DOM is fully loaded. E.g. `Calculator` will not render a new `answer` block until fully loaded and executed. For some plugins, we might want to handle its availability in `settings.yml` and toggle in UI, like we do for server side plugins. In that case, we extend `py Plugin` instancing only the information and then checking client side if [`settings.plugins`](https://github.com/inetol/searxng/blob/1ad832b1dc33f3f388da361ff2459b05dc86a164/client/simple/src/js/toolkit.ts#L134) array has the plugin id. * [mod] client/simple: rebuild static
2025-11-25[mod] replace js_variable_to_python by js_obj_str_to_python (#2792) (#5477)Markus Heiser
This patch is based on PR #2792 (old PR from 2023) - js_obj_str_to_python handle more cases - bring tests from chompjs .. - comment out tests do not pass The tests from chompjs give some overview of what is not implemented. Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
2025-11-25[fix] engines initialization - if engine load fails, set to inactiveMarkus Heiser
- if engine load fails, set the engine to inactive - dont' load a engine, when the config says its inactive Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
2025-10-10[mod] brand - partial migration of settings to msgspec.Struct (#5280)Markus Heiser
The settings are currently an untyped key/value structure, whose types are dynamically built at runtime. The construction process of this structure is *hand-crafted*. In the long term, we want a static typing of this structure, based on a standard tool. The ``msgspec.Struct`` structures are suitable as a standard tool. This patch makes a first step towards static typing and implements the "brand" section using ``msgspec.Struct`` structures. BTW: searx/settings_defaults.py - ``git_url`` and ``git_branch`` had been removed in aee613d256, this is a leftover. Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
2025-09-18[mod] addition of various type hints / engine processorsMarkus Heiser
Continuation of #5147 .. typification of the engine processors. BTW: - removed obsolete engine property https_support - fixed & improved currency_convert - engine instances can now implement a engine.setup method [#5147] https://github.com/searxng/searxng/pull/5147 Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
2025-09-03[mod] drop: from __future__ import annotationsMarkus Heiser
Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
2025-09-03[mod] addition of various type hints / tbcMarkus Heiser
- pyright configuration [1]_ - stub files: types-lxml [2]_ - addition of various type hints - enable use of new type system features on older Python versions [3]_ - ``.tool-versions`` - set python to lowest version we support (3.10.18) [4]_: Older versions typically lack some typing features found in newer Python versions. Therefore, for local type checking (before commit), it is necessary to use the older Python interpreter. .. [1] https://docs.basedpyright.com/v1.20.0/configuration/config-files/ .. [2] https://pypi.org/project/types-lxml/ .. [3] https://typing-extensions.readthedocs.io/en/latest/# .. [4] https://mise.jdx.dev/configuration.html#tool-versions Signed-off-by: Markus Heiser <markus.heiser@darmarit.de> Format: reST
2025-09-01[mod] typification of SearXNG: add new result type CodeMarkus Heiser
This patch adds a new result type: Code - Python class: searx/result_types/code.py - Jinja template: searx/templates/simple/result_templates/code.html - CSS (less) client/simple/src/less/result_types/code.less Signed-of-by: Markus Heiser <markus.heiser@darmarIT.de>
2025-08-20[feat] engines: add GitHub Code Search engine (#5074)Filip Mikina
This patch adds GitHub Code Search [1] engine to allow querying the codebases. Template code.html is changed to allow passthrough of strip and highlighting options. Engine Searchcode is adjusted to pass filename and not rely on hardcoded extensions. GitHub search code API does not return the exact code line indices, this implementation assigns the code arbitrary numbers starting from 1 (effectively relabeling the code). The API allows for unauth calls, and the default engine settings default to that, although the calls are heavily rate limited. The 'text' lexer is the default pygments lexer when parsing fails. [1] https://docs.github.com/en/rest/search/search?apiVersion=2022-11-28#search-code Co-authored-by: Markus Heiser <markus.heiser@darmarIT.de>
2025-08-18[fix] revision of utils.HTMLTextExtractor (#5125)Markus Heiser
Related: - https://github.com/searxng/searxng/pull/5073#issuecomment-3196282632
2025-08-09[mod] limiter: trusted proxies (#4911)Ivan Gabaldon
Replaces `x_for` functionality with `trusted_proxies`. This allows defining which IP / ranges to trust extracting the client IP address from X-Forwarded-For and X-Real-IP headers. We don't know if the proxy chain will give us the proper client address (REMOTE_ADDR in the WSGI environment), so we rely on reading the headers of the proxy before SearXNG (if there is one, in that case it must be added to trusted_proxies) hoping it has done the proper checks. In case a proxy in the chain does not check the client address correctly, integrity is compromised and this should be fixed by whoever manages the proxy, not us. Closes: - https://github.com/searxng/searxng/issues/4940 - https://github.com/searxng/searxng/issues/4939 - https://github.com/searxng/searxng/issues/4907 - https://github.com/searxng/searxng/issues/3632 - https://github.com/searxng/searxng/issues/3191 - https://github.com/searxng/searxng/issues/1237 Related: - https://github.com/searxng/searxng-docker/issues/386 - https://github.com/inetol-infrastructure/searxng-container/issues/81
2025-07-29[test] calculator plugin: report the DeprecationWarning once (#5070)Markus Heiser
Reporting the DeprecationWarning once should be sufficient when running tests.
2025-07-26[fix] cleanup: rename `searx` leftovers to `SearXNG` (#5049)Markus Heiser
Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
2025-07-11[mod] remove option ui.static_use_hash (cache busting) (#5004)Markus Heiser
Cache busting has caused serious problems for users in the past, here are two examples: - https://github.com/searxng/searxng/issues/4419 - https://github.com/searxng/searxng/issues/4481 And it makes development and deployment significantly more complex because it binds the client side to the server side: - https://github.com/searxng/searxng/pull/4466 In the light of a decoupled development of the WEB clients from the server side: - https://github.com/searxng/searxng/pull/4988 is it appropriate to abandon this feature. In fact, it has been ineffective since #4436 anyway. However, the benefit has always been questionable, since at best only a few kB of data are saved (at least in the context of an image_proxy, the effect is below the detection limit). Ultimately, the client is responsible for caching. Related: https://github.com/searxng/searxng/issues?q=label%3A%22clear%20browser%20cache%22 Closes: https://github.com/searxng/searxng/pull/4466 Closes: https://github.com/searxng/searxng/issues/1326 Closes: https://github.com/searxng/searxng/issues/964 Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
2025-06-22[fix] remove dissem.in due to its closure (#4930)Nanashi
remove dissem.in due to its closure [1] [1] https://association.dissem.in/dissemin-closure.html
2025-05-30[mod] UI footer: correct capitalization of "SearXNG" in base.htmlbenpiano800
2025-05-13[enh] tidy: clean old morty, filtron, searx referencesIvan Gabaldon
Everyone should have already switched from legacy methods
2025-04-22[fix] issues when launching a local development serverMarkus Heiser
A local development server can be launched by one of these command lines:: $ flask --app searx.webapp run $ python -m searx.webapp The different ways of starting the server should lead to the same result, which is generally the case. However, if the modules are reloaded after code changes (reload option), it must be avoided that the application is initialized twice at startup. We have already discussed this in 2022 [1][2]. Further information on this topic can be found in [3][4][5]. To test a bash in the ./local environment was started and the follwing commands had been executed:: $ ./manage pyenv.cmd bash --norc --noprofile (py3) SEARXNG_DEBUG=1 flask --app searx.webapp run --reload (py3) SEARXNG_DEBUG=1 python -m searx.webapp Since the generic parts of the docs also initialize the app to generate doc from it, the build of the docs was also tested:: $ make docs.clean docs.live [1] https://github.com/searxng/searxng/pull/1656#issuecomment-1214198941 [2] https://github.com/searxng/searxng/pull/1616#issuecomment-1206137468 [3] https://flask.palletsprojects.com/en/stable/api/#flask.Flask.run [4] https://github.com/pallets/flask/issues/5307#issuecomment-1774646119 [5] https://stackoverflow.com/a/25504196 Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
2025-03-29[refactor] migrate plugins from "module" to class SXNGPluginMarkus Heiser
This patch brings two major changes: - ``Result.filter_urls(..)`` to pass a filter function for URL fields - The ``enabled_plugins:`` section in SearXNG's settings do no longer exists. To understand plugin development compile documentation: $ make docs.clean docs.live and read http://0.0.0.0:8000/dev/plugins/development.html There is no longer a distinction between built-in and external plugin, all plugins are registered via the settings in the ``plugins:`` section. In SearXNG, plugins can be registered via a fully qualified class name. A configuration (`PluginCfg`) can be transferred to the plugin, e.g. to activate it by default / *opt-in* or *opt-out* from user's point of view. built-in plugins ================ The built-in plugins are all located in the namespace `searx.plugins`. .. code:: yaml plugins: searx.plugins.calculator.SXNGPlugin: active: true searx.plugins.hash_plugin.SXNGPlugin: active: true searx.plugins.self_info.SXNGPlugin: active: true searx.plugins.tracker_url_remover.SXNGPlugin: active: true searx.plugins.unit_converter.SXNGPlugin: active: true searx.plugins.ahmia_filter.SXNGPlugin: active: true searx.plugins.hostnames.SXNGPlugin: active: true searx.plugins.oa_doi_rewrite.SXNGPlugin: active: false searx.plugins.tor_check.SXNGPlugin: active: false external plugins ================ SearXNG supports *external plugins* / there is no need to install one, SearXNG runs out of the box. - Only show green hosted results: https://github.com/return42/tgwf-searx-plugins/ To get a developer installation in a SearXNG developer environment: .. code:: sh $ git clone git@github.com:return42/tgwf-searx-plugins.git $ ./manage pyenv.cmd python -m \ pip install -e tgwf-searx-plugins To register the plugin in SearXNG add ``only_show_green_results.SXNGPlugin`` to the ``plugins:``: .. code:: yaml plugins: # ... only_show_green_results.SXNGPlugin: active: false Result.filter_urls(..) ====================== The ``Result.filter_urls(..)`` can be used to filter and/or modify URL fields. In the following example, the filter function ``my_url_filter``: .. code:: python def my_url_filter(result, field_name, url_src) -> bool | str: if "google" in url_src: return False # remove URL field from result if "facebook" in url_src: new_url = url_src.replace("facebook", "fb-dummy") return new_url # return modified URL return True # leave URL in field unchanged is applied to all URL fields in the :py:obj:`Plugin.on_result` hook: .. code:: python class MyUrlFilter(Plugin): ... def on_result(self, request, search, result) -> bool: result.filter_urls(my_url_filter) return True Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
2025-03-15container: add default support for IPv6 (#4448)Ivan Gabaldon
* Initial update * update docs and test files
2025-03-15[refactor] typification of SearXNG (MainResult) / result items (part 2)Markus Heiser
The class ReslutContainer has been revised, it can now handle the typed Result items of classes: - MainResult - LegacyResult (a dict wrapper for backward compatibility) Due to the now complete typing of theses three clases, instead of the *getitem* accesses, the fields can now be accessed directly via attributes (which is also supported by the IDE). Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
2025-03-01[fix] add backward compatibility for the "enabled_plugins:"Markus Heiser
Before #4183 a builtin plugin was *defautlt_on* when it is listed in the "enabled_plugins" settings, this patch restores the previous behavior. Not part of this patch but just to mentioning in context of #4263: In the long term, we will abolish the "enabled_plugins:" setting and combine all options for the plugins in the "plugins:" setting, as is already planned in the PR #4282 Closes: https://github.com/searxng/searxng/issues/4263 Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
2025-02-07[fix] selenium: binary is not a Firefox executableMarkus Heiser
Since Ubuntu installs firefox frrom snap, we can't use any longer ``Browser('firefox')``. [1] https://github.com/searxng/searxng/pull/3663#issuecomment-2255963036 [2] https://splinter.readthedocs.io/en/latest/drivers/firefox.html#custom-binary-path Suggested-by: @allendema Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
2025-01-29[mod] rudimentary implementation of a MainResult typeMarkus Heiser
Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
2025-01-28[refactor] typification of SearXNG / EngineResultsMarkus Heiser
In [1] and [2] we discussed the need of a Result.results property and how we can avoid unclear code. This patch implements a class for the reslut-lists of engines:: searx.result_types.EngineResults A simple example for the usage in engine development:: from searx.result_types import EngineResults ... def response(resp) -> EngineResults: res = EngineResults() ... res.add( res.types.Answer(answer="lorem ipsum ..", url="https://example.org") ) ... return res [1] https://github.com/searxng/searxng/pull/4183#pullrequestreview-257400034 [2] https://github.com/searxng/searxng/pull/4183#issuecomment-2614301580 Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
2025-01-28[refactor] typification of SearXNG (initial) / result items (part 1)Markus Heiser
Typification of SearXNG ======================= This patch introduces the typing of the results. The why and how is described in the documentation, please generate the documentation .. $ make docs.clean docs.live and read the following articles in the "Developer documentation": - result types --> http://0.0.0.0:8000/dev/result_types/index.html The result types are available from the `searx.result_types` module. The following have been implemented so far: - base result type: `searx.result_type.Result` --> http://0.0.0.0:8000/dev/result_types/base_result.html - answer results --> http://0.0.0.0:8000/dev/result_types/answer.html including the type for translations (inspired by #3925). For all other types (which still need to be set up in subsequent PRs), template documentation has been created for the transition period. Doc of the fields used in Templates =================================== The template documentation is the basis for the typing and is the first complete documentation of the results (needed for engine development). It is the "working paper" (the plan) with which further typifications can be implemented in subsequent PRs. - https://github.com/searxng/searxng/issues/357 Answer Templates ================ With the new (sub) types for `Answer`, the templates for the answers have also been revised, `Translation` are now displayed with collapsible entries (inspired by #3925). !en-de dog Plugins & Answerer ================== The implementation for `Plugin` and `Answer` has been revised, see documentation: - Plugin: http://0.0.0.0:8000/dev/plugins/index.html - Answerer: http://0.0.0.0:8000/dev/answerers/index.html With `AnswerStorage` and `AnswerStorage` to manage those items (in follow up PRs, `ArticleStorage`, `InfoStorage` and .. will be implemented) Autocomplete ============ The autocompletion had a bug where the results from `Answer` had not been shown in the past. To test activate autocompletion and try search terms for which we have answerers - statistics: type `min 1 2 3` .. in the completion list you should find an entry like `[de] min(1, 2, 3) = 1` - random: type `random uuid` .. in the completion list, the first item is a random UUID Extended Types ============== SearXNG extends e.g. the request and response types of flask and httpx, a module has been set up for type extensions: - Extended Types --> http://0.0.0.0:8000/dev/extended_types.html Unit-Tests ========== The unit tests have been completely revised. In the previous implementation, the runtime (the global variables such as `searx.settings`) was not initialized before each test, so the runtime environment with which a test ran was always determined by the tests that ran before it. This was also the reason why we sometimes had to observe non-deterministic errors in the tests in the past: - https://github.com/searxng/searxng/issues/2988 is one example for the Runtime issues, with non-deterministic behavior .. - https://github.com/searxng/searxng/pull/3650 - https://github.com/searxng/searxng/pull/3654 - https://github.com/searxng/searxng/pull/3642#issuecomment-2226884469 - https://github.com/searxng/searxng/pull/3746#issuecomment-2300965005 Why msgspec.Struct ================== We have already discussed typing based on e.g. `TypeDict` or `dataclass` in the past: - https://github.com/searxng/searxng/pull/1562/files - https://gist.github.com/dalf/972eb05e7a9bee161487132a7de244d2 - https://github.com/searxng/searxng/pull/1412/files - https://github.com/searxng/searxng/pull/1356 In my opinion, TypeDict is unsuitable because the objects are still dictionaries and not instances of classes / the `dataclass` are classes but ... The `msgspec.Struct` combine the advantages of typing, runtime behaviour and also offer the option of (fast) serializing (incl. type check) the objects. Currently not possible but conceivable with `msgspec`: Outsourcing the engines into separate processes, what possibilities this opens up in the future is left to the imagination! Internally, we have already defined that it is desirable to decouple the development of the engines from the development of the SearXNG core / The serialization of the `Result` objects is a prerequisite for this. HINT: The threads listed above were the template for this PR, even though the implementation here is based on msgspec. They should also be an inspiration for the following PRs of typification, as the models and implementations can provide a good direction. Why just one commit? ==================== I tried to create several (thematically separated) commits, but gave up at some point ... there are too many things to tackle at once / The comprehensibility of the commits would not be improved by a thematic separation. On the contrary, we would have to make multiple changes at the same places and the goal of a change would be vaguely recognizable in the fog of the commits. Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
2025-01-14[json_engine] Add unit testLucki
2024-11-29[fix] unit tests: call searx.search.initialize in test's setUpMarkus Heiser
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-11-29[enh] use longest title and test get_ordered_results()Allen
2024-11-25[chore] rss: rename from searx to SearXNGBnyro
2024-11-24[test] add additional tests for preferencesGrant Lanham
2024-11-24[chore] *: fix typos detected by typos-cliBnyro
2024-10-28[fix] calculator: use locale from UI (not from selected language)Markus Heiser
Closes: https://github.com/searxng/searxng/issues/3956 Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
2024-10-26[mod] add test to check compat.py moduleMarkus Heiser
Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
2024-10-15[fix] float operations in calculator pluginGrant Lanham
This patch adds an additional *isinstance* check within the ast parser to check for float along with int, fixing the underlying issue. Co-Authored: Markus Heiser <markus.heiser@darmarit.de>
2024-10-15[refactor] unit tests (continued) - pluginsGrant Lanham
This commit includes some refactoring in unit tests. As we test more plugins, it seems unweildy to include every test class in the test_plugins.py file. This patch split apart all of the test plugins to their own respective files, including the new test_plugin_calculator.py file.
2024-10-15[enh] engine: mojeek - add language support0xhtml
Improve region and language detection / all locale Testing has shown the following behaviour for the different default and empty values of Mojeeks parameters: | param | idx | value | behaviour | | -------- | --- | ------ | ------------------------- | | region | 0 | '' | detect region based on IP | | region | 1 | 'none' | all regions | | language | 0 | '' | all languages |
2024-10-05[mod] Revision of the favicon solutionMarkus Heiser
All favicons implementations have been documented and moved to the Python package: searx.favicons There is a configuration (based on Pydantic) for the favicons and all its components: searx.favicons.config A solution for caching favicons has been implemented: searx.favicon.cache If the favicon is already in the cache, the returned URL is a data URL [1] (something like `data:image/png;base64,...`). By generating a data url from the FaviconCache, additional HTTP roundtripps via the favicon_proxy are saved: favicons.proxy.favicon_url The favicon proxy service now sets a HTTP header "Cache-Control: max-age=...": favicons.proxy.favicon_proxy The resolvers now also provide the mime type (data, mime): searx.favicon.resolvers [1] https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
2024-10-05[feat] add favicons to result urlsBrock Vojkovic
2024-10-03[refactor] unit tests to utilize paramaterized and break down monolithic testsGrant Lanham
- for tests which perform the same arrange/act/assert pattern but with different data, the data portion has been moved to the ``paramaterized.expand`` fields - for monolithic tests which performed multiple arrange/act/asserts, they have been broken up into different unit tests. - when possible, change generic assert statements to more concise asserts (i.e. ``assertIsNone``) This work ultimately is focused on creating smaller and more concise tests. While paramaterized may make adding new configurations for existing tests easier, that is just a beneficial side effect. The main benefit is that smaller tests are easier to reason about, meaning they are easier to debug when they start failing. This improves the developer experience in debugging what went wrong when refactoring the project. Total number of tests went from 192 -> 259; or, broke apart larger tests into 69 more concise ones.
2024-10-03[feat] implement mariadb engineGrant Lanham
2024-09-22Add paramaterized with example of refactorGrant Lanham
reduce test name size fix imports
2024-08-30[fix] self_info: request.user_agent is not a strAlexander Sulfrian
The user_agent attribute of the Flask request object is an instance of the werkzeug.user_agent.UserAgent class. This will fix the following error of the self_info plugin: > ERROR:searx.plugins.self_info: Exception while calling post_search > Traceback (most recent call last): > File "searx/plugins/__init__.py", line 203, in call > ret = getattr(plugin, plugin_type)(*args, **kwargs) > File "searx/plugins/self_info.py", line 31, in post_search > search.result_container.answers['user-agent'] = {'answer': gettext('Your user-agent is: ') + ua} > TypeError: can only concatenate str (not "UserAgent") to str
2024-08-21Fix tineye engine url, datetime parsing, and minor refactorGrant Lanham
Changes made to tineye engine: 1. Importing logging if TYPE_CHECKING is enabled 2. Remove unecessary try-catch around json parsing the response, as this masked the original error and had no immediate benefit 3. Improve error handling explicitely for status code 422 and 400 upfront, deferring json_parsing only for these status codes and successful status codes 4. Unit test all new applicable changes to ensure compatability
2024-08-21[fix] unit tests: fix load / unload engines & fix messagesMarkus Heiser
- https://github.com/searxng/searxng/pull/3746#issuecomment-2300965005 - https://github.com/searxng/searxng/issues/2988#issuecomment-2226929084 Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
2024-07-14[mod] revision of the settings_loaderMarkus Heiser
The intention of this PR is to modernize the settings_loader implementations. The concept is old (remember, this is partly from 2014), back then we only had one config file, meanwhile we have had a folder with config files for a very long time. Callers can now load a YAML configuration from this folder as follows :: settings_loader.get_yaml_cfg('my-config.yml') - BTW this is a fix of #3557. - Further the `existing_filename_or_none` construct dates back to times when there was not yet a `pathlib.Path` in all Python versions we supported in the past. - Typehints have been added wherever appropriate At the same time, this patch should also be downward compatible and not introduce a new environment variable. The localization of the folder with the configurations is further based on: SEARXNG_SETTINGS_PATH (wich defaults to /etc/searxng/settings.yml) Which means, the default config folder is `/etc/searxng/`. ATTENTION: intended functional changes! If SEARXNG_SETTINGS_PATH was set and pointed to a not existing file, the previous implementation silently loaded the default configuration. This behavior has been changed: if the file or folder does not exist, an EnvironmentError exception will be thrown in future. Closes: https://github.com/searxng/searxng/issues/3557 Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
2024-07-13[fix] tear down TEST_ENGINES after TestBang is proceededMarkus Heiser
Engines are loaded into global name `searx.engines.engines` other applications such as statistics or the histogram use this global variable to search for values in their own memories, which can lead to key errors as described in - https://github.com/searxng/searxng/issues/2988 Signed-off-by: Markus Heiser <markus.heiser@darmarit.de> Closes: https://github.com/searxng/searxng/issues/2988
2024-06-28[fix] unit test_xpath.py: name 'logger' is not definedMarkus Heiser
Depending on the order in which the unit tests are executed, the python modules of the engines are initialized (monkey patched) or not. As the order of the tests is not static, random errors may occur. To avaoid random `NameError: name 'logger' is not defined` in the unit tests of the xpath engine, a logger is monkey patched into the xpath py-module. ``` make test.unit TEST tests/unit ......EE................... ====================================================================== ERROR: test_response (tests.unit.engines.test_xpath.TestXpathEngine.test_response) ---------------------------------------------------------------------- Traceback (most recent call last): File "./tests/unit/engines/test_xpath.py", line 60, in test_response self.assertEqual(xpath.response(response), []) ^^^^^^^^^^^^^^^^^^^^^^^^ File "./searx/engines/xpath.py", line 309, in response logger.debug("found %s results", len(results)) ^^^^^^ NameError: name 'logger' is not defined ====================================================================== ERROR: test_response_results_xpath (tests.unit.engines.test_xpath.TestXpathEngine.test_response_results_xpath) ---------------------------------------------------------------------- Traceback (most recent call last): File "./tests/unit/engines/test_xpath.py", line 102, in test_response_results_xpath self.assertEqual(xpath.response(response), []) ^^^^^^^^^^^^^^^^^^^^^^^^ File "./searx/engines/xpath.py", line 309, in response logger.debug("found %s results", len(results)) ^^^^^^ NameError: name 'logger' is not defined ``` Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
2024-06-23[fix] implement tests and remove usage of gen_useragent in enginesGrant Lanham
2024-06-23[fix] engine unit tests.Richard Lyons
Enables unit tests in the engines directory by adding __init__.py, and fixups for the enabled tests.