35 lines
926 B
Python
35 lines
926 B
Python
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)
|