[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.
This commit is contained in:
Grant Lanham 2024-09-23 23:37:30 -04:00 committed by Markus Heiser
parent 042c7190e6
commit 44a06190bb
12 changed files with 341 additions and 342 deletions

View file

@ -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