mirror of
https://github.com/searxng/searxng.git
synced 2025-07-19 03:09:25 +02:00
[refactor] add type hints & remove Setting._post_init
Previously the Setting classes used a horrible _post_init hack that prevented proper type checking.
This commit is contained in:
parent
93c6829b27
commit
bb06758a7b
4 changed files with 133 additions and 139 deletions
|
@ -1,7 +1,6 @@
|
|||
from searx.preferences import (
|
||||
EnumStringSetting,
|
||||
MapSetting,
|
||||
MissingArgumentException,
|
||||
SearchLanguageSetting,
|
||||
MultipleChoiceSetting,
|
||||
PluginsSetting,
|
||||
|
@ -19,10 +18,6 @@ class PluginStub:
|
|||
class TestSettings(SearxTestCase):
|
||||
# map settings
|
||||
|
||||
def test_map_setting_invalid_initialization(self):
|
||||
with self.assertRaises(MissingArgumentException):
|
||||
MapSetting(3, wrong_argument={'0': 0})
|
||||
|
||||
def test_map_setting_invalid_default_value(self):
|
||||
with self.assertRaises(ValidationException):
|
||||
MapSetting(3, map={'dog': 1, 'bat': 2})
|
||||
|
@ -43,9 +38,6 @@ class TestSettings(SearxTestCase):
|
|||
self.assertEqual(setting.get_value(), 2)
|
||||
|
||||
# enum settings
|
||||
def test_enum_setting_invalid_initialization(self):
|
||||
with self.assertRaises(MissingArgumentException):
|
||||
EnumStringSetting('cat', wrong_argument=[0, 1, 2])
|
||||
|
||||
def test_enum_setting_invalid_default_value(self):
|
||||
with self.assertRaises(ValidationException):
|
||||
|
@ -67,9 +59,6 @@ class TestSettings(SearxTestCase):
|
|||
self.assertEqual(setting.get_value(), 2)
|
||||
|
||||
# multiple choice settings
|
||||
def test_multiple_setting_invalid_initialization(self):
|
||||
with self.assertRaises(MissingArgumentException):
|
||||
MultipleChoiceSetting(['2'], wrong_argument=['0', '1', '2'])
|
||||
|
||||
def test_multiple_setting_invalid_default_value(self):
|
||||
with self.assertRaises(ValidationException):
|
||||
|
@ -115,14 +104,14 @@ class TestSettings(SearxTestCase):
|
|||
def test_plugins_setting_all_default_enabled(self):
|
||||
plugin1 = PluginStub('plugin1', True)
|
||||
plugin2 = PluginStub('plugin2', True)
|
||||
setting = PluginsSetting(['3'], choices=[plugin1, plugin2])
|
||||
setting = PluginsSetting(['3'], plugins=[plugin1, plugin2])
|
||||
self.assertEqual(setting.get_enabled(), set(['plugin1', 'plugin2']))
|
||||
|
||||
def test_plugins_setting_few_default_enabled(self):
|
||||
plugin1 = PluginStub('plugin1', True)
|
||||
plugin2 = PluginStub('plugin2', False)
|
||||
plugin3 = PluginStub('plugin3', True)
|
||||
setting = PluginsSetting('name', choices=[plugin1, plugin2, plugin3])
|
||||
setting = PluginsSetting('name', plugins=[plugin1, plugin2, plugin3])
|
||||
self.assertEqual(setting.get_enabled(), set(['plugin1', 'plugin3']))
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue