Skip to content

Commit

Permalink
✅ Cover flatten, unflatten and update config routines
Browse files Browse the repository at this point in the history
  • Loading branch information
valentingol committed Dec 13, 2023
1 parent 4b75ddf commit 6ade49b
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion tests/unit/test_config_routines.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@
import pytest_check as check

from cliconfig.base import Config
from cliconfig.config_routines import load_config, make_config, save_config, show_config
from cliconfig.config_routines import (
flatten_config,
load_config,
make_config,
save_config,
show_config,
unflatten_config,
update_config,
)
from cliconfig.processing.base import Processing


Expand Down Expand Up @@ -163,3 +171,28 @@ def test_save_config() -> None:
save_config(config, "tests/tmp/config.yaml")
check.is_true(os.path.exists("tests/tmp/config.yaml"))
shutil.rmtree("tests/tmp")


def test_flatten_config() -> None:
"""Test flatten_config."""
config = Config({"a": 1, "b": {"c": 2, "d": 3}, "e": "f"}, [])
flat_config = flatten_config(config)
expected_dict = {"a": 1, "b.c": 2, "b.d": 3, "e": "f"}
check.equal(flat_config.dict, expected_dict)


def test_unflatten_config() -> None:
"""Test unflatten_config."""
config = Config({"a": 1, "b.c": 2, "b.d": 3, "e": "f"}, [])
flat_config = unflatten_config(config)
expected_dict = {"a": 1, "b": {"c": 2, "d": 3}, "e": "f"}
check.equal(flat_config.dict, expected_dict)


def test_update_config() -> None:
"""Test update_config."""
config = Config({"a": 1, "b": {"c": 2, "d": 3}, "e": "f"}, [])
new_dict = {"b": {"c": 3}, "g": "h"}
new_config = update_config(config, new_dict)
expected_dict = {"a": 1, "b": {"c": 3, "d": 3}, "e": "f", "g": "h"}
check.equal(new_config.dict, expected_dict)

0 comments on commit 6ade49b

Please sign in to comment.