1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-25 05:26:47 +00:00

Fix yaml loader tests to test both C and Python implementations (#103606)

This commit is contained in:
Erik Montnemery
2023-11-07 23:49:31 +01:00
committed by GitHub
parent e8c568a243
commit 859c5c48c4

View File

@@ -57,7 +57,7 @@ def test_simple_list(try_both_loaders) -> None:
"""Test simple list."""
conf = "config:\n - simple\n - list"
with io.StringIO(conf) as file:
doc = yaml_loader.yaml.load(file, Loader=yaml_loader.SafeLineLoader)
doc = yaml_loader.parse_yaml(file)
assert doc["config"] == ["simple", "list"]
@@ -65,7 +65,7 @@ def test_simple_dict(try_both_loaders) -> None:
"""Test simple dict."""
conf = "key: value"
with io.StringIO(conf) as file:
doc = yaml_loader.yaml.load(file, Loader=yaml_loader.SafeLineLoader)
doc = yaml_loader.parse_yaml(file)
assert doc["key"] == "value"
@@ -88,7 +88,7 @@ def test_environment_variable(try_both_loaders) -> None:
os.environ["PASSWORD"] = "secret_password"
conf = "password: !env_var PASSWORD"
with io.StringIO(conf) as file:
doc = yaml_loader.yaml.load(file, Loader=yaml_loader.SafeLineLoader)
doc = yaml_loader.parse_yaml(file)
assert doc["password"] == "secret_password"
del os.environ["PASSWORD"]
@@ -97,7 +97,7 @@ def test_environment_variable_default(try_both_loaders) -> None:
"""Test config file with default value for environment variable."""
conf = "password: !env_var PASSWORD secret_password"
with io.StringIO(conf) as file:
doc = yaml_loader.yaml.load(file, Loader=yaml_loader.SafeLineLoader)
doc = yaml_loader.parse_yaml(file)
assert doc["password"] == "secret_password"
@@ -105,7 +105,7 @@ def test_invalid_environment_variable(try_both_loaders) -> None:
"""Test config file with no environment variable sat."""
conf = "password: !env_var PASSWORD"
with pytest.raises(HomeAssistantError), io.StringIO(conf) as file:
yaml_loader.yaml.load(file, Loader=yaml_loader.SafeLineLoader)
yaml_loader.parse_yaml(file)
@pytest.mark.parametrize(
@@ -118,7 +118,7 @@ def test_include_yaml(
"""Test include yaml."""
conf = "key: !include test.yaml"
with io.StringIO(conf) as file:
doc = yaml_loader.yaml.load(file, Loader=yaml_loader.SafeLineLoader)
doc = yaml_loader.parse_yaml(file)
assert doc["key"] == value
@@ -134,7 +134,7 @@ def test_include_dir_list(
conf = "key: !include_dir_list /test"
with io.StringIO(conf) as file:
doc = yaml_loader.yaml.load(file, Loader=yaml_loader.SafeLineLoader)
doc = yaml_loader.parse_yaml(file)
assert doc["key"] == sorted(["one", "two"])
@@ -162,7 +162,7 @@ def test_include_dir_list_recursive(
conf = "key: !include_dir_list /test"
with io.StringIO(conf) as file:
assert ".ignore" in mock_walk.return_value[0][1], "Expecting .ignore in here"
doc = yaml_loader.yaml.load(file, Loader=yaml_loader.SafeLineLoader)
doc = yaml_loader.parse_yaml(file)
assert "tmp2" in mock_walk.return_value[0][1]
assert ".ignore" not in mock_walk.return_value[0][1]
assert sorted(doc["key"]) == sorted(["zero", "one", "two"])
@@ -184,7 +184,7 @@ def test_include_dir_named(
conf = "key: !include_dir_named /test"
correct = {"first": "one", "second": "two"}
with io.StringIO(conf) as file:
doc = yaml_loader.yaml.load(file, Loader=yaml_loader.SafeLineLoader)
doc = yaml_loader.parse_yaml(file)
assert doc["key"] == correct
@@ -213,7 +213,7 @@ def test_include_dir_named_recursive(
correct = {"first": "one", "second": "two", "third": "three"}
with io.StringIO(conf) as file:
assert ".ignore" in mock_walk.return_value[0][1], "Expecting .ignore in here"
doc = yaml_loader.yaml.load(file, Loader=yaml_loader.SafeLineLoader)
doc = yaml_loader.parse_yaml(file)
assert "tmp2" in mock_walk.return_value[0][1]
assert ".ignore" not in mock_walk.return_value[0][1]
assert doc["key"] == correct
@@ -232,7 +232,7 @@ def test_include_dir_merge_list(
conf = "key: !include_dir_merge_list /test"
with io.StringIO(conf) as file:
doc = yaml_loader.yaml.load(file, Loader=yaml_loader.SafeLineLoader)
doc = yaml_loader.parse_yaml(file)
assert sorted(doc["key"]) == sorted(["one", "two", "three"])
@@ -260,7 +260,7 @@ def test_include_dir_merge_list_recursive(
conf = "key: !include_dir_merge_list /test"
with io.StringIO(conf) as file:
assert ".ignore" in mock_walk.return_value[0][1], "Expecting .ignore in here"
doc = yaml_loader.yaml.load(file, Loader=yaml_loader.SafeLineLoader)
doc = yaml_loader.parse_yaml(file)
assert "tmp2" in mock_walk.return_value[0][1]
assert ".ignore" not in mock_walk.return_value[0][1]
assert sorted(doc["key"]) == sorted(["one", "two", "three", "four"])
@@ -284,7 +284,7 @@ def test_include_dir_merge_named(
conf = "key: !include_dir_merge_named /test"
with io.StringIO(conf) as file:
doc = yaml_loader.yaml.load(file, Loader=yaml_loader.SafeLineLoader)
doc = yaml_loader.parse_yaml(file)
assert doc["key"] == {"key1": "one", "key2": "two", "key3": "three"}
@@ -312,7 +312,7 @@ def test_include_dir_merge_named_recursive(
conf = "key: !include_dir_merge_named /test"
with io.StringIO(conf) as file:
assert ".ignore" in mock_walk.return_value[0][1], "Expecting .ignore in here"
doc = yaml_loader.yaml.load(file, Loader=yaml_loader.SafeLineLoader)
doc = yaml_loader.parse_yaml(file)
assert "tmp2" in mock_walk.return_value[0][1]
assert ".ignore" not in mock_walk.return_value[0][1]
assert doc["key"] == {