Skip to content

Commit

Permalink
Merge pull request home-assistant#2068 from home-assistant/yaml_env
Browse files Browse the repository at this point in the history
Add test for yaml enviroment
  • Loading branch information
Danielhiversen committed May 14, 2016
2 parents c5401b2 + 24788b1 commit 0626a80
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/util/test_yaml.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Test Home Assistant yaml loader."""
import io
import unittest
import os

from homeassistant.util import yaml

Expand Down Expand Up @@ -32,3 +33,23 @@ def test_duplicate_key(self):
pass
else:
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

0 comments on commit 0626a80

Please sign in to comment.