From aa8f0d9e6a2943a755e0d2163c978d6bdc1f5449 Mon Sep 17 00:00:00 2001 From: ldericher <40151420+ldericher@users.noreply.github.com> Date: Mon, 21 Feb 2022 22:46:50 +0100 Subject: [PATCH] prefer "long" project configs --- kiwi_scp/config.py | 9 ++++----- kiwi_scp/yaml.py | 2 +- tests/test_config.py | 7 ++++++- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/kiwi_scp/config.py b/kiwi_scp/config.py index 3280f9a..ad9e923 100644 --- a/kiwi_scp/config.py +++ b/kiwi_scp/config.py @@ -45,13 +45,12 @@ class ProjectConfig(BaseModel): def kiwi_dict(self) -> Dict[str, Any]: """write this object as a dictionary of strings""" - if self.override_storage is None: - return {self.name: self.enabled} + result = self.dict(exclude={"override_storage"}) - else: - result = self.dict(exclude={"override_storage"}) + if self.override_storage is not None: result["override_storage"] = self.override_storage.kiwi_dict - return result + + return result @validator("name") @classmethod diff --git a/kiwi_scp/yaml.py b/kiwi_scp/yaml.py index 5caff50..2d7a606 100644 --- a/kiwi_scp/yaml.py +++ b/kiwi_scp/yaml.py @@ -10,7 +10,7 @@ from ._constants import HEADER_KIWI_CONF_NAME class YAML(ruamel.yaml.YAML): def __init__(self, *args, **kwargs) -> None: super().__init__(*args, **kwargs) - self.indent(offset=2) + self.indent(sequence=4, offset=2) def dump(self, data, stream=None, **kwargs) -> Optional[str]: into_str: bool = False diff --git a/tests/test_config.py b/tests/test_config.py index 3a344e0..33a4421 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -221,7 +221,12 @@ class TestProject: assert p.name == "project" assert not p.enabled assert p.override_storage is None - assert p.kiwi_dict == kiwi_dict + + resulting_kiwi_dict = { + "name": "project", + "enabled": False, + } + assert p.kiwi_dict == resulting_kiwi_dict def test_dict(self): c = KiwiConfig(projects={"name": "project"})