mirror of
https://github.com/home-assistant/core
synced 2024-08-06 09:34:49 +02:00
Merge pull request #2068 from home-assistant/yaml_env
Add test for yaml enviroment
This commit is contained in:
commit
0626a80186
@ -1,6 +1,7 @@
|
|||||||
"""Test Home Assistant yaml loader."""
|
"""Test Home Assistant yaml loader."""
|
||||||
import io
|
import io
|
||||||
import unittest
|
import unittest
|
||||||
|
import os
|
||||||
|
|
||||||
from homeassistant.util import yaml
|
from homeassistant.util import yaml
|
||||||
|
|
||||||
@ -32,3 +33,23 @@ class TestYaml(unittest.TestCase):
|
|||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
assert 0
|
assert 0
|
||||||
|
|
||||||
|
def test_enviroment_variable(self):
|
||||||
|
"""Test config file with enviroment variable."""
|
||||||
|
os.environ["PASSWORD"] = "secret_password"
|
||||||
|
conf = "password: !env_var PASSWORD"
|
||||||
|
with io.StringIO(conf) as f:
|
||||||
|
doc = yaml.yaml.safe_load(f)
|
||||||
|
assert doc['password'] == "secret_password"
|
||||||
|
del os.environ["PASSWORD"]
|
||||||
|
|
||||||
|
def test_invalid_enviroment_variable(self):
|
||||||
|
"""Test config file with no enviroment variable sat."""
|
||||||
|
conf = "password: !env_var PASSWORD"
|
||||||
|
try:
|
||||||
|
with io.StringIO(conf) as f:
|
||||||
|
yaml.yaml.safe_load(f)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
assert 0
|
||||||
|
Loading…
Reference in New Issue
Block a user