Create FileConfiguration baseclass (#2651)

This commit is contained in:
Joakim Sørensen
2021-03-01 12:26:43 +01:00
committed by GitHub
parent 7a542aeb38
commit bee55d08fb
23 changed files with 197 additions and 150 deletions

View File

@@ -1,40 +1,37 @@
"""test yaml."""
import json
from ruamel.yaml import YAML as _YAML
from supervisor.const import FILE_SUFFIX_CONFIGURATION
from supervisor.utils import find_one_filetype, read_json_or_yaml_file, yaml
YAML = _YAML()
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"
YAML.dump({"test": "test"}, tempfile)
yaml.read_yaml_file(tempfile)
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"
YAML.dump({"test": "test"}, tempfile)
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"
YAML.dump({"test": "test"}, tempfile)
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"
YAML.dump({"test": "test"}, tempfile)
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"
YAML.dump({"test": "test"}, tempfile)
write_yaml_file(tempfile, {"test": "test"})
found = find_one_filetype(tmp_path, "test4", FILE_SUFFIX_CONFIGURATION)
assert not found
@@ -42,12 +39,11 @@ def test_get_file_from_type(tmp_path):
def test_read_json_or_yaml_file(tmp_path):
"""Read JSON or YAML file."""
tempfile = tmp_path / "test.json"
with open(tempfile, "w") as outfile:
json.dump({"test": "test"}, outfile)
write_json_file(tempfile, {"test": "test"})
read = read_json_or_yaml_file(tempfile)
assert read["test"] == "test"
tempfile = tmp_path / "test.yaml"
YAML.dump({"test": "test"}, tempfile)
write_yaml_file(tempfile, {"test": "test"})
read = read_json_or_yaml_file(tempfile)
assert read["test"] == "test"