mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-07-31 14:49:56 +00:00
feat: allow append list options
This commit is contained in:
@ -1,4 +1,6 @@
|
||||
import configparser
|
||||
from io import StringIO
|
||||
|
||||
import pytest
|
||||
|
||||
from pathlib import Path
|
||||
@ -180,6 +182,32 @@ def test_getlist_unmatched_quote(configuration: Configuration) -> None:
|
||||
configuration.getlist("build", "test_list")
|
||||
|
||||
|
||||
def test_getlist_append() -> None:
|
||||
"""
|
||||
must correctly append list values
|
||||
"""
|
||||
configuration = Configuration()
|
||||
configuration._read(
|
||||
StringIO("""
|
||||
[section]
|
||||
list1[] = value1
|
||||
list1[] = value2
|
||||
|
||||
list2[] = value3
|
||||
list2[] =
|
||||
list2[] = value4
|
||||
list2[] = value5
|
||||
|
||||
list3[] = value6
|
||||
list3 = value7
|
||||
list3[] = value8
|
||||
"""), "io")
|
||||
|
||||
assert configuration.getlist("section", "list1") == ["value1", "value2"]
|
||||
assert configuration.getlist("section", "list2") == ["value4", "value5"]
|
||||
assert configuration.getlist("section", "list3") == ["value7", "value8"]
|
||||
|
||||
|
||||
def test_getpath_absolute_to_absolute(configuration: Configuration) -> None:
|
||||
"""
|
||||
must not change path for absolute path in settings
|
||||
|
@ -0,0 +1,54 @@
|
||||
import pytest
|
||||
|
||||
from ahriman.core.configuration.configuration_multi_dict import ConfigurationMultiDict
|
||||
from ahriman.core.exceptions import OptionError
|
||||
|
||||
|
||||
def test_setitem_non_list() -> None:
|
||||
"""
|
||||
must insert not list correctly
|
||||
"""
|
||||
instance = ConfigurationMultiDict()
|
||||
instance["key"] = "value"
|
||||
assert instance["key"] == "value"
|
||||
|
||||
|
||||
def test_setitem_remove() -> None:
|
||||
"""
|
||||
must remove key
|
||||
"""
|
||||
instance = ConfigurationMultiDict()
|
||||
instance["key"] = "value"
|
||||
instance["key"] = [""]
|
||||
|
||||
assert "key" not in instance
|
||||
|
||||
|
||||
def test_setitem_array() -> None:
|
||||
"""
|
||||
must set array correctly
|
||||
"""
|
||||
instance = ConfigurationMultiDict()
|
||||
instance["key[]"] = ["value1"]
|
||||
instance["key[]"] = ["value2"]
|
||||
|
||||
assert instance["key"] == ["value1 value2"]
|
||||
|
||||
|
||||
def test_setitem_array_exception() -> None:
|
||||
"""
|
||||
must raise exception if the current value is not a single value array
|
||||
"""
|
||||
instance = ConfigurationMultiDict()
|
||||
instance["key[]"] = ["value1", "value2"]
|
||||
with pytest.raises(OptionError):
|
||||
instance["key[]"] = ["value3"]
|
||||
|
||||
|
||||
def test_setitem_exception() -> None:
|
||||
"""
|
||||
must raise exception on invalid key
|
||||
"""
|
||||
instance = ConfigurationMultiDict()
|
||||
with pytest.raises(OptionError):
|
||||
instance["prefix[]suffix"] = "value"
|
Reference in New Issue
Block a user