From 3ea1a593288b18814dbd951890ba7079f7547cb6 Mon Sep 17 00:00:00 2001 From: Bernhard Ryeng Date: Mon, 2 Dec 2024 12:02:47 +0100 Subject: [PATCH] Improve test coverage for config.py. --- src/ssb_timeseries/config.py | 5 +++++ tests/test_config.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/ssb_timeseries/config.py b/src/ssb_timeseries/config.py index f805a49..412987f 100644 --- a/src/ssb_timeseries/config.py +++ b/src/ssb_timeseries/config.py @@ -182,6 +182,11 @@ def apply(self, configs: dict) -> None: else: raise ValidationError(f"Invalid configuration {configs}.") + @property + def is_valid(self) -> bool: + """Check if the configuration has all required fields.""" + return is_valid_config(self.__dict__) + def save(self, path: PathStr = "") -> None: """Saves configurations to the JSON file defined by `configuration_file`. diff --git a/tests/test_config.py b/tests/test_config.py index 1b8a0b2..e5325f3 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -85,6 +85,34 @@ def test_config_defaults(reset_config_after: config.Config) -> None: assert cfg_0.timeseries_root == cfg_1.timeseries_root == cfg_2.timeseries_root +@pytest.mark.parametrize( + "preset_name,attr,value", + [ + ("defaults", "", ""), + ("home", "", ""), + ("gcs", "", ""), + ("shared-test", "", ""), + ("shared-prod", "", ""), + ("jovyan", "", ""), + ("dapla", "", ""), + ], +) +def test_config_presets( + reset_config_after: config.Config, + preset_name, + attr, + value, +) -> None: + # all of these should result in the same information, but in different objects + + cfg = config.Config(preset=preset_name) + + assert isinstance(cfg, config.Config) + assert cfg.is_valid + if attr: + assert cfg.__getattribute__(attr) == value + + def test_config_change(reset_config_after: config.Config) -> None: cfg = config.CONFIG old_value = cfg.timeseries_root