From 24788b106b9cdd70e7240dc3eccac82fba290c85 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sat, 14 May 2016 20:18:33 +0200 Subject: [PATCH] Add test for yaml enviroment --- tests/util/test_yaml.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/util/test_yaml.py b/tests/util/test_yaml.py index e865b5bba32f..106cb01264e7 100644 --- a/tests/util/test_yaml.py +++ b/tests/util/test_yaml.py @@ -1,6 +1,7 @@ """Test Home Assistant yaml loader.""" import io import unittest +import os from homeassistant.util import yaml @@ -32,3 +33,23 @@ class TestYaml(unittest.TestCase): 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