mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-04-19 10:47:15 +00:00
54 lines
1.8 KiB
Python
54 lines
1.8 KiB
Python
"""test yaml."""
|
|
|
|
import pytest
|
|
|
|
from supervisor.const import FILE_SUFFIX_CONFIGURATION
|
|
from supervisor.exceptions import ConfigurationFileError
|
|
from supervisor.utils.common import find_one_filetype, read_json_or_yaml_file
|
|
from supervisor.utils.json import write_json_file
|
|
from supervisor.utils.yaml import read_yaml_file, write_yaml_file
|
|
|
|
|
|
def test_reading_yaml(tmp_path):
|
|
"""Test reading YAML file."""
|
|
tempfile = tmp_path / "test.yaml"
|
|
write_yaml_file(tempfile, {"test": "test"})
|
|
read = read_yaml_file(tempfile)
|
|
assert read["test"] == "test"
|
|
|
|
|
|
def test_get_file_from_type(tmp_path):
|
|
"""Test get file from type."""
|
|
tempfile = tmp_path / "test1.yaml"
|
|
write_yaml_file(tempfile, {"test": "test"})
|
|
found = find_one_filetype(tmp_path, "test1", FILE_SUFFIX_CONFIGURATION)
|
|
assert found.parts[-1] == "test1.yaml"
|
|
|
|
tempfile = tmp_path / "test2.yml"
|
|
write_yaml_file(tempfile, {"test": "test"})
|
|
found = find_one_filetype(tmp_path, "test2", FILE_SUFFIX_CONFIGURATION)
|
|
assert found.parts[-1] == "test2.yml"
|
|
|
|
tempfile = tmp_path / "test3.json"
|
|
write_yaml_file(tempfile, {"test": "test"})
|
|
found = find_one_filetype(tmp_path, "test3", FILE_SUFFIX_CONFIGURATION)
|
|
assert found.parts[-1] == "test3.json"
|
|
|
|
tempfile = tmp_path / "test.config"
|
|
write_yaml_file(tempfile, {"test": "test"})
|
|
with pytest.raises(ConfigurationFileError):
|
|
find_one_filetype(tmp_path, "test4", FILE_SUFFIX_CONFIGURATION)
|
|
|
|
|
|
def test_read_json_or_yaml_file(tmp_path):
|
|
"""Read JSON or YAML file."""
|
|
tempfile = tmp_path / "test.json"
|
|
write_json_file(tempfile, {"test": "test"})
|
|
read = read_json_or_yaml_file(tempfile)
|
|
assert read["test"] == "test"
|
|
|
|
tempfile = tmp_path / "test.yaml"
|
|
write_yaml_file(tempfile, {"test": "test"})
|
|
read = read_json_or_yaml_file(tempfile)
|
|
assert read["test"] == "test"
|