Skip to content

Commit

Permalink
Improve test coverage for config.py.
Browse files Browse the repository at this point in the history
  • Loading branch information
bryeng committed Dec 2, 2024
1 parent 20b6299 commit 3ea1a59
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/ssb_timeseries/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
28 changes: 28 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3ea1a59

Please sign in to comment.