mirror of
https://github.com/esphome/esphome.git
synced 2025-09-02 03:12:20 +01:00
Fallback to pure-python loader for better error when YAML loading fails (#6081)
This commit is contained in:
18
tests/unit_tests/fixtures/yaml_util/broken_includetest.yaml
Normal file
18
tests/unit_tests/fixtures/yaml_util/broken_includetest.yaml
Normal file
@@ -0,0 +1,18 @@
|
||||
---
|
||||
substitutions:
|
||||
name: original
|
||||
|
||||
wifi: !include
|
||||
file: includes/broken_included.yaml.txt
|
||||
vars:
|
||||
name: my_custom_ssid
|
||||
|
||||
esphome:
|
||||
# should be substituted as 'original',
|
||||
# not overwritten by vars in the !include above
|
||||
name: ${name}
|
||||
name_add_mac_suffix: true
|
||||
platform: esp8266
|
||||
board: !include {file: includes/scalar.yaml, vars: {var1: nodemcu}}
|
||||
|
||||
libraries: !include {file: includes/list.yaml, vars: {var1: Wire}}
|
@@ -0,0 +1,5 @@
|
||||
---
|
||||
# yamllint disable-line
|
||||
ssid: ${name}
|
||||
# yamllint disable-line
|
||||
fdf: error
|
@@ -1,5 +1,6 @@
|
||||
from esphome import yaml_util
|
||||
from esphome.components import substitutions
|
||||
from esphome.core import EsphomeError
|
||||
|
||||
|
||||
def test_include_with_vars(fixture_path):
|
||||
@@ -11,3 +12,13 @@ def test_include_with_vars(fixture_path):
|
||||
assert actual["esphome"]["libraries"][0] == "Wire"
|
||||
assert actual["esphome"]["board"] == "nodemcu"
|
||||
assert actual["wifi"]["ssid"] == "my_custom_ssid"
|
||||
|
||||
|
||||
def test_loading_a_broken_yaml_file(fixture_path):
|
||||
"""Ensure we fallback to pure python to give good errors."""
|
||||
yaml_file = fixture_path / "yaml_util" / "broken_includetest.yaml"
|
||||
|
||||
try:
|
||||
yaml_util.load_yaml(yaml_file)
|
||||
except EsphomeError as err:
|
||||
assert "broken_included.yaml" in str(err)
|
||||
|
Reference in New Issue
Block a user