Skip to content

Commit

Permalink
chore: replaced test config files with default config
Browse files Browse the repository at this point in the history
this fixes the problem that these config files always need to be updated as well if the default config changes

and there is one additional advantage: the default config is tested and the tests make sure that it is valid
  • Loading branch information
jstucke authored and maringuu committed Nov 14, 2024
1 parent 6dee673 commit 56ba201
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 253 deletions.
2 changes: 1 addition & 1 deletion src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def _validate_temp_dir_path(cls, value):
return value


def load(path: str | None = None):
def load(path: str | Path | None = None):
"""Load the config file located at ``path``.
The file must be a toml file and is read into instances of :py:class:`~config.Backend`,
:py:class:`~config.Frontend` and :py:class:`~config.Common`.
Expand Down
123 changes: 0 additions & 123 deletions src/test/data/fact-core-config.toml

This file was deleted.

123 changes: 0 additions & 123 deletions src/test/data/fact-core-config.toml-missing-entrys

This file was deleted.

22 changes: 16 additions & 6 deletions src/test/unit/test_config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from pathlib import Path
from tempfile import TemporaryDirectory

import pydantic
import pytest

Expand All @@ -6,14 +9,15 @@
# We explicitly don't want the patch_cfg fixture to be able to patch this function
# This is why we import it here
from config import load
from test.common_helper import get_test_data_dir
from helperFunctions.fileSystem import get_config_dir

CONFIG_PATH = Path(get_config_dir()) / 'fact-core-config.toml'


def test_load(monkeypatch):
# Undo all monkeypatching which includes what `patch_config` patched.
monkeypatch.undo()
cfg_path = f'{get_test_data_dir()}/fact-core-config.toml'
load(path=cfg_path)
load(path=CONFIG_PATH)

assert config.common is not None, 'common global was not set'
assert config.backend is not None, 'backend global was not set'
Expand All @@ -23,6 +27,12 @@ def test_load(monkeypatch):


def test_load_missing_entries():
cfg_path = get_test_data_dir() + '/fact-core-config.toml-missing-entrys'
with pytest.raises(pydantic.ValidationError, match='server'):
load(path=cfg_path)
cfg_contents = CONFIG_PATH.read_text()
assert '[common.postgres]\nserver =' in cfg_contents
# comment out server
cfg_contents = cfg_contents.replace('[common.postgres]\nserver =', '[common.postgres]\n# server =')
with TemporaryDirectory() as tmp_dir:
cfg_path = Path(tmp_dir) / 'config.toml'
cfg_path.write_text(cfg_contents)
with pytest.raises(pydantic.ValidationError, match='server'):
load(path=cfg_path)

0 comments on commit 56ba201

Please sign in to comment.