This repository has been archived on 2024-06-02. You can view files and clone it, but cannot push or open issues or pull requests.
spud-py/tests/test_config.py
Marc Cataford 3dad2071ff
All checks were successful
/ Tests (push) Successful in 52s
/ Static Analysis (push) Successful in 1m4s
refactor: extract configuration handling to own class
2024-04-13 23:17:42 -04:00

32 lines
778 B
Python

import json
import pytest
from spud.config import Configuration
@pytest.fixture(name="sample_config")
def sample_config_fixture():
return {}
def test_from_file_creates_configuration_from_file(tmpdir, sample_config):
config_file = tmpdir / "config.json"
config_file.write(json.dumps(sample_config))
config = Configuration.from_file(config_file)
assert config.model_dump() == sample_config
def test_from_file_raises_if_file_not_found(tmpdir):
with pytest.raises(RuntimeError):
Configuration.from_file(tmpdir / "nonfile.json")
def test_from_file_raises_if_file_not_json(tmpdir):
config_file = tmpdir / "config.json"
config_file.write("notjson")
with pytest.raises(RuntimeError):
Configuration.from_file(config_file)