Added nested_delete and config_delete

This commit is contained in:
2024-05-26 15:40:29 +02:00
parent ce691b2eda
commit 7032bef956
10 changed files with 279 additions and 126 deletions

View File

@@ -2,7 +2,7 @@ from typing import Any, Dict, List
import pytest
from libbot import sync
from libbot.sync._nested import nested_delete, nested_set
@pytest.mark.parametrize(
@@ -33,9 +33,7 @@ def test_nested_set_valid(
create_missing: bool,
expected: Any,
):
assert (
sync.nested_set(target, value, *path, create_missing=create_missing)
) == expected
assert (nested_set(target, value, *path, create_missing=create_missing)) == expected
@pytest.mark.parametrize(
@@ -59,5 +57,25 @@ def test_nested_set_invalid(
):
with pytest.raises(expected):
assert (
sync.nested_set(target, value, *path, create_missing=create_missing)
nested_set(target, value, *path, create_missing=create_missing)
) == expected
@pytest.mark.parametrize(
"target, path, expected",
[
({"foo": "bar"}, ["foo"], {}),
({"foo": "bar", "bar": "foo"}, ["bar"], {"foo": "bar"}),
(
{"foo": {"bar": {}}},
["foo", "bar"],
{"foo": {}},
),
],
)
def test_nested_delete(
target: Dict[str, Any],
path: List[str],
expected: Any,
):
assert (nested_delete(target, *path)) == expected