noop yaml loader refactor
This commit is contained in:
1 parent
0cf3f2706a
commit
97521097dc
17 files changed
+147
-93
No files matched your search
@@ -1,11 +1,13 @@
|
||||
import io
|
||||
from pathlib import Path
|
||||
from unittest import TestCase
|
||||
|
||||
from src.yaml_serializer import dump_yaml, load_yaml
|
||||
from src.yaml_serializer import (
|
||||
IncludedYaml,
|
||||
IncludedYamlDir,
|
||||
SecretValue,
|
||||
dump_yaml,
|
||||
load_yaml,
|
||||
)
|
||||
|
||||
|
||||
@@ -14,23 +16,29 @@ class dumping_yamls_tests(TestCase):
|
||||
yaml = dump_yaml(
|
||||
{
|
||||
"automations": IncludedYaml(
|
||||
"automations.yaml",
|
||||
Path.cwd() / "automations.yaml",
|
||||
)
|
||||
}
|
||||
},
|
||||
Path.cwd(),
|
||||
)
|
||||
self.assertEqual(yaml, "automations: !include 'automations.yaml'\n")
|
||||
|
||||
def test_dumping_secrets(self):
|
||||
yaml = dump_yaml({"google_password": SecretValue("gpass", "supersec")})
|
||||
yaml = dump_yaml({"google_password": SecretValue("gpass", "supersec")}, Path.cwd())
|
||||
self.assertEqual(yaml, "google_password: !secret 'gpass'\n")
|
||||
|
||||
def test_dumping_include_dir_list(self):
|
||||
yaml = dump_yaml({"sensor": IncludedYamlDir("include_dir_list", "sensors/*yaml")})
|
||||
self.assertEqual(yaml, "sensor: !include_dir_list 'sensors/*yaml'\n")
|
||||
yaml = dump_yaml(
|
||||
{"sensor": IncludedYamlDir("include_dir_list", Path.cwd() / "sensors")}, Path.cwd()
|
||||
)
|
||||
self.assertEqual(yaml, "sensor: !include_dir_list 'sensors'\n")
|
||||
|
||||
def test_dumping_include_dir_merge_list(self):
|
||||
yaml = dump_yaml({"sensor": IncludedYamlDir("include_dir_merge_list", "sensors/*yaml")})
|
||||
self.assertEqual(yaml, "sensor: !include_dir_merge_list 'sensors/*yaml'\n")
|
||||
yaml = dump_yaml(
|
||||
{"sensor": IncludedYamlDir("include_dir_merge_list", Path.cwd() / "sensors")},
|
||||
Path.cwd(),
|
||||
)
|
||||
self.assertEqual(yaml, "sensor: !include_dir_merge_list 'sensors'\n")
|
||||
|
||||
def test_load_complex_automation_setup(self):
|
||||
yaml_obj = load_yaml(
|
||||
@@ -41,19 +49,20 @@ class dumping_yamls_tests(TestCase):
|
||||
automation: !include automations/base.yaml
|
||||
automation cools: !include_dir_merge_list automations/include_dir_merge_list
|
||||
"""
|
||||
)
|
||||
),
|
||||
Path.cwd(),
|
||||
)
|
||||
self.assertDictEqual(
|
||||
dict(yaml_obj),
|
||||
{
|
||||
"automation manual": IncludedYamlDir(
|
||||
"include_dir_list", "./automations/include_dir_list"
|
||||
"include_dir_list", Path.cwd() / "automations/include_dir_list"
|
||||
),
|
||||
"automation ui": IncludedYaml("automations/ui.yaml"),
|
||||
"automation ui": IncludedYaml(Path.cwd() / "automations/ui.yaml"),
|
||||
"automation cools": IncludedYamlDir(
|
||||
"include_dir_merge_list", "automations/include_dir_merge_list"
|
||||
"include_dir_merge_list", Path.cwd() / "automations/include_dir_merge_list"
|
||||
),
|
||||
"automation": IncludedYaml("automations/base.yaml"),
|
||||
"automation": IncludedYaml(Path.cwd() / "automations/base.yaml"),
|
||||
},
|
||||
)
|
||||
|
||||
@@ -71,10 +80,11 @@ class dumping_yamls_tests(TestCase):
|
||||
bobIsNull:
|
||||
bobIsNull2: null
|
||||
google_password: !secret gpass
|
||||
sensor: !include_dir_list sensors/*yaml
|
||||
sensor: !include_dir_list sensors
|
||||
automations: !include automations.yaml
|
||||
"""
|
||||
)
|
||||
),
|
||||
Path.cwd(),
|
||||
)
|
||||
self.assertDictEqual(
|
||||
dict(yaml_obj),
|
||||
@@ -85,12 +95,12 @@ class dumping_yamls_tests(TestCase):
|
||||
"bobIsNull": None,
|
||||
"bobIsNull2": None,
|
||||
"google_password": SecretValue("gpass", "n/a"),
|
||||
"sensor": IncludedYamlDir("include_dir_list", "sensors/*yaml"),
|
||||
"automations": IncludedYaml("automations.yaml"),
|
||||
"sensor": IncludedYamlDir("include_dir_list", Path.cwd() / "sensors"),
|
||||
"automations": IncludedYaml(Path.cwd() / "automations.yaml"),
|
||||
},
|
||||
)
|
||||
self.assertEqual(
|
||||
dump_yaml(yaml_obj),
|
||||
dump_yaml(yaml_obj, Path.cwd()),
|
||||
"""name: cool
|
||||
date: '10:00'
|
||||
bools:
|
||||
@@ -101,7 +111,7 @@ bools:
|
||||
bobIsNull: null
|
||||
bobIsNull2: null
|
||||
google_password: !secret 'gpass'
|
||||
sensor: !include_dir_list 'sensors/*yaml'
|
||||
sensor: !include_dir_list 'sensors'
|
||||
automations: !include 'automations.yaml'
|
||||
""",
|
||||
)
|
||||
Reference in new issue
Block a user