32 lines
778 B
Python
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)
|