From d448def1a66afe9e0b702ac25ca921526a3f0ca2 Mon Sep 17 00:00:00 2001 From: Grant Lanham Date: Sat, 5 Oct 2024 16:10:21 +0200 Subject: [refactor] unit tests (continued) - plugins 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. --- tests/unit/test_utils.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'tests/unit/test_utils.py') diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py index 4306d0790..4c7ebaec7 100644 --- a/tests/unit/test_utils.py +++ b/tests/unit/test_utils.py @@ -1,16 +1,21 @@ # SPDX-License-Identifier: AGPL-3.0-or-later # pylint: disable=missing-module-docstring, invalid-name +import random +import string import lxml.etree from lxml import html from parameterized.parameterized import parameterized from searx.exceptions import SearxXPathSyntaxException, SearxEngineXPathException from searx import utils - from tests import SearxTestCase +def random_string(length, choices=string.ascii_letters): + return ''.join(random.choice(choices) for _ in range(length)) + + class TestUtils(SearxTestCase): # pylint: disable=missing-class-docstring def test_gen_useragent(self): self.assertIsInstance(utils.gen_useragent(), str) @@ -234,4 +239,4 @@ class TestXPathUtils(SearxTestCase): # pylint: disable=missing-class-docstring self.assertIsNone(l) with self.assertRaises(ValueError): - utils.detect_language(None) + utils.detect_language(None) # type: ignore -- cgit v1.2.3