44 lines
1009 B
Python
44 lines
1009 B
Python
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from dopt_basics import configs
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
def config_file(root_data_folder) -> Path:
|
|
pth = root_data_folder / "config.toml"
|
|
assert pth.exists()
|
|
assert pth.is_file()
|
|
|
|
return pth
|
|
|
|
|
|
def test_load_toml_SuccessPath(config_file):
|
|
cfg = configs.load_toml(config_file)
|
|
assert isinstance(cfg, dict)
|
|
assert "test" in cfg
|
|
assert cfg["test"]["entry"] == "test123"
|
|
|
|
|
|
def test_load_toml_SuccessStringPath(config_file):
|
|
str_pth = str(config_file)
|
|
cfg = configs.load_toml(str_pth)
|
|
assert isinstance(cfg, dict)
|
|
assert "test" in cfg
|
|
assert cfg["test"]["entry"] == "test123"
|
|
|
|
|
|
def test_load_toml_FailWrongPath(tmp_path):
|
|
wrong_pth = tmp_path / "config.toml"
|
|
|
|
with pytest.raises(FileNotFoundError):
|
|
_ = configs.load_toml(wrong_pth)
|
|
|
|
|
|
def test_load_toml_FailIsDirectory(config_file):
|
|
wrong_pth = config_file.parent
|
|
|
|
with pytest.raises(ValueError):
|
|
_ = configs.load_toml(wrong_pth)
|