added simpler loader
This commit is contained in:
1 parent
d6adbb897d
commit
c493c0a3d0
6 files changed
+118
-12
No files matched your search
@@ -1,6 +1,13 @@
|
||||
import io
|
||||
from pathlib import Path
|
||||
from unittest import TestCase
|
||||
from src.yaml_serializer import dump_yaml, IncludedYaml, SecretValue
|
||||
from src.yaml_serializer import (
|
||||
dump_yaml,
|
||||
IncludedYaml,
|
||||
SecretValue,
|
||||
IncludedYamlDir,
|
||||
simple_load_yaml,
|
||||
)
|
||||
|
||||
|
||||
class dumping_yamls_tests(TestCase):
|
||||
@@ -21,3 +28,35 @@ class dumping_yamls_tests(TestCase):
|
||||
def test_dumping_secrets(self):
|
||||
yaml = dump_yaml({"google_password": SecretValue("gpass", "supersec")})
|
||||
self.assertEqual(yaml, "google_password: !secret gpass\n")
|
||||
|
||||
def test_dumping_stub(self):
|
||||
yaml = dump_yaml({"sensor": IncludedYamlDir("include_dir_list", "sensors/*yaml")})
|
||||
self.assertEqual(yaml, "sensor: !include_dir_list sensors/*yaml\n")
|
||||
|
||||
def test_load_stub(self):
|
||||
yaml_obj = simple_load_yaml(
|
||||
io.StringIO(
|
||||
"""
|
||||
name: cool
|
||||
google_password: !secret gpass
|
||||
sensor: !include_dir_list sensors/*yaml
|
||||
automations: !include automations.yaml
|
||||
"""
|
||||
)
|
||||
)
|
||||
self.assertDictEqual(
|
||||
dict(yaml_obj),
|
||||
{
|
||||
"name": "cool",
|
||||
"google_password": SecretValue("gpass", "n/a"),
|
||||
"sensor": IncludedYamlDir("include_dir_list", "sensors/*yaml"),
|
||||
"automations": IncludedYaml("automations.yaml", Path("/"), "n/a"),
|
||||
},
|
||||
)
|
||||
self.assertEqual(
|
||||
dump_yaml(yaml_obj),
|
||||
"name: cool\n"
|
||||
"google_password: !secret gpass\n"
|
||||
"sensor: !include_dir_list sensors/*yaml\n"
|
||||
"automations: !include automations.yaml\n",
|
||||
)
|
||||
Reference in new issue
Block a user