Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replaced test config files with default config #1296

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)