Add tests for lookup_dict() and load_yaml()
This commit is contained in:
parent
28c9d1810a
commit
e6c3682652
|
@ -3,6 +3,10 @@ from pathlib import Path
|
|||
import pytest
|
||||
|
||||
from operator_repo.utils import load_yaml
|
||||
|
||||
from operator_repo.utils import lookup_dict
|
||||
|
||||
from operator_repo.exceptions import OperatorRepoException
|
||||
from tests import create_files
|
||||
|
||||
|
||||
|
@ -22,3 +26,24 @@ def test_load_yaml(tmp_path: Path) -> None:
|
|||
_ = load_yaml(tmp_path / "data/something.yaml")
|
||||
with pytest.raises(FileNotFoundError):
|
||||
_ = load_yaml(tmp_path / "data/something.yml")
|
||||
|
||||
|
||||
def test_load_yaml_invalid(tmp_path: Path) -> None:
|
||||
create_files(
|
||||
tmp_path,
|
||||
{"data/multi-doc.yml": "---\nhello: world\n---\nfoo: bar\n"},
|
||||
{"data/invalid.yaml": "{This is not a valid\nyaml document]\n"},
|
||||
)
|
||||
with pytest.raises(OperatorRepoException, match="contains multiple yaml documents"):
|
||||
_ = load_yaml(tmp_path / "data/multi-doc.yml")
|
||||
with pytest.raises(OperatorRepoException, match="is not a valid yaml document"):
|
||||
_ = load_yaml(tmp_path / "data/invalid.yml")
|
||||
|
||||
|
||||
def test_lookup_dict() -> None:
|
||||
data = {"hello": "world", "sub1": {"sub3": "value1"}}
|
||||
assert lookup_dict(data, "hello") == "world"
|
||||
assert lookup_dict(data, "sub1.sub3") == "value1"
|
||||
assert lookup_dict(data, "sub1/sub3", separator="/") == "value1"
|
||||
assert lookup_dict(data, "sub2") is None
|
||||
assert lookup_dict(data, "sub2", default="") == ""
|
||||
|
|
Loading…
Reference in New Issue