1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-30 06:33:51 +00:00

[packages] Tighten package validation (#11584)

This commit is contained in:
Javier Peletier
2025-10-28 23:18:47 +01:00
committed by GitHub
parent f1bce262ed
commit e462217500
2 changed files with 46 additions and 2 deletions

View File

@@ -102,7 +102,7 @@ CONFIG_SCHEMA = cv.Any(
str: PACKAGE_SCHEMA,
}
),
cv.ensure_list(PACKAGE_SCHEMA),
[PACKAGE_SCHEMA],
)

View File

@@ -5,7 +5,7 @@ from unittest.mock import MagicMock, patch
import pytest
from esphome.components.packages import do_packages_pass
from esphome.components.packages import CONFIG_SCHEMA, do_packages_pass
from esphome.config import resolve_extend_remove
from esphome.config_helpers import Extend, Remove
import esphome.config_validation as cv
@@ -94,6 +94,50 @@ def test_package_invalid_dict(basic_esphome, basic_wifi):
packages_pass(config)
@pytest.mark.parametrize(
"package",
[
{"package1": "github://esphome/non-existant-repo/file1.yml@main"},
{"package2": "github://esphome/non-existant-repo/file1.yml"},
{"package3": "github://esphome/non-existant-repo/other-folder/file1.yml"},
[
"github://esphome/non-existant-repo/file1.yml@main",
"github://esphome/non-existant-repo/file1.yml",
"github://esphome/non-existant-repo/other-folder/file1.yml",
],
],
)
def test_package_shorthand(package):
CONFIG_SCHEMA(package)
@pytest.mark.parametrize(
"package",
[
# not github
{"package1": "someplace://esphome/non-existant-repo/file1.yml@main"},
# missing repo
{"package2": "github://esphome/file1.yml"},
# missing file
{"package3": "github://esphome/non-existant-repo/@main"},
{"a": "invalid string, not shorthand"},
"some string",
3,
False,
{"a": 8},
["someplace://esphome/non-existant-repo/file1.yml@main"],
["github://esphome/file1.yml"],
["github://esphome/non-existant-repo/@main"],
["some string"],
[True],
[3],
],
)
def test_package_invalid(package):
with pytest.raises(cv.Invalid):
CONFIG_SCHEMA(package)
def test_package_include(basic_wifi, basic_esphome):
"""
Tests the simple case where an independent config present in a package is added to the top-level config as is.