summaryrefslogtreecommitdiff
path: root/tests/unit/test_preferences.py
diff options
context:
space:
mode:
authorGrant Lanham <contact@grantlanham.com>2024-09-23 23:37:30 -0400
committerMarkus Heiser <markus.heiser@darmarIT.de>2024-10-03 13:20:32 +0200
commit44a06190bbb1b412f0ed16a76b0a4aeef80975b7 (patch)
treedd6e94d656fe4b11918e6cb5bd6183535dcc7254 /tests/unit/test_preferences.py
parent042c7190e6fe092a8a85997713a2511fffb09625 (diff)
downloadsearxng-44a06190bbb1b412f0ed16a76b0a4aeef80975b7.tar.gz
searxng-44a06190bbb1b412f0ed16a76b0a4aeef80975b7.zip
[refactor] unit tests to utilize paramaterized and break down monolithic tests
- 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.
Diffstat (limited to 'tests/unit/test_preferences.py')
-rw-r--r--tests/unit/test_preferences.py23
1 files changed, 12 insertions, 11 deletions
diff --git a/tests/unit/test_preferences.py b/tests/unit/test_preferences.py
index 5855c12a6..8bf157a7e 100644
--- a/tests/unit/test_preferences.py
+++ b/tests/unit/test_preferences.py
@@ -1,6 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-or-later
# pylint: disable=missing-module-docstring, invalid-name
+from tests import SearxTestCase
from searx.locales import locales_initialize
from searx.preferences import (
EnumStringSetting,
@@ -10,12 +11,12 @@ from searx.preferences import (
PluginsSetting,
ValidationException,
)
-from tests import SearxTestCase
+from searx.plugins import Plugin
locales_initialize()
-class PluginStub: # pylint: disable=missing-class-docstring, too-few-public-methods
+class PluginStub(Plugin): # 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
@@ -47,22 +48,22 @@ class TestSettings(SearxTestCase): # pylint: disable=missing-class-docstring
def test_enum_setting_invalid_default_value(self):
with self.assertRaises(ValidationException):
- EnumStringSetting(3, choices=[0, 1, 2])
+ EnumStringSetting('3', choices=['0', '1', '2'])
def test_enum_setting_invalid_choice(self):
- setting = EnumStringSetting(0, choices=[0, 1, 2])
+ setting = EnumStringSetting('0', choices=['0', '1', '2'])
with self.assertRaises(ValidationException):
- setting.parse(3)
+ setting.parse('3')
def test_enum_setting_valid_default(self):
- setting = EnumStringSetting(3, choices=[1, 2, 3])
- self.assertEqual(setting.get_value(), 3)
+ setting = EnumStringSetting('3', choices=['1', '2', '3'])
+ self.assertEqual(setting.get_value(), '3')
def test_enum_setting_valid_choice(self):
- setting = EnumStringSetting(3, choices=[1, 2, 3])
- self.assertEqual(setting.get_value(), 3)
- setting.parse(2)
- self.assertEqual(setting.get_value(), 2)
+ setting = EnumStringSetting('3', choices=['1', '2', '3'])
+ self.assertEqual(setting.get_value(), '3')
+ setting.parse('2')
+ self.assertEqual(setting.get_value(), '2')
# multiple choice settings