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

36 lines
926 B
Python
Raw Permalink Normal View History

import json
import pytest
from spud.config import Configuration
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)
def test_from_file_raises_if_wrong_schema(tmpdir):
config_file = tmpdir / "config.json"
config_file.write(json.dumps({"random-key": 1}))
with pytest.raises(RuntimeError):
Configuration.from_file(config_file)