noop yaml loader refactor
This commit is contained in:
1 parent
0cf3f2706a
commit
97521097dc
17 files changed
+147
-93
No files matched your search
@@ -6,7 +6,11 @@ from fastapi.testclient import TestClient
|
||||
|
||||
from src.api.app import make_app
|
||||
from src.automations.types import Automation, ExtenededAutomation
|
||||
from tests.utils import HA_CONFIG2_EXAMPLE, HA_CONFIG6_EXAMPLE, get_example_automation_loader
|
||||
from tests.utils import (
|
||||
HA_CONFIG2_EXAMPLE,
|
||||
HA_CONFIG6_EXAMPLE,
|
||||
get_example_automation_loader,
|
||||
)
|
||||
|
||||
|
||||
class BaseTestCase(TestCase):
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
from pathlib import Path
|
||||
|
||||
from src.automations.types import ExtenededAutomation
|
||||
from src.automations.errors import DBDataError
|
||||
from src.automations.types import ExtenededAutomation
|
||||
|
||||
from .utils import TestWithDB
|
||||
|
||||
|
||||
|
||||
@@ -229,7 +229,8 @@ class manager_tests(TestWithDB):
|
||||
automation_manager.get("newlymade")
|
||||
|
||||
data = yaml_serializer.load_yaml(
|
||||
(config_path / "automations/include_dir_merge_list/sub/list2.yaml").open("r")
|
||||
(config_path / "automations/include_dir_merge_list/sub/list2.yaml").open("r"),
|
||||
root_path=config_path,
|
||||
)
|
||||
self.assertIsInstance(data, list)
|
||||
|
||||
@@ -254,7 +255,8 @@ class manager_tests(TestWithDB):
|
||||
automation_manager.get("newlymade")
|
||||
|
||||
data = yaml_serializer.load_yaml(
|
||||
(config_path / "automations/include_dir_list/home/down.yaml").open("r")
|
||||
(config_path / "automations/include_dir_list/home/down.yaml").open("r"),
|
||||
config_path,
|
||||
)
|
||||
self.assertIsInstance(data, dict)
|
||||
|
||||
|
||||
@@ -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