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:
@@ -102,7 +102,7 @@ CONFIG_SCHEMA = cv.Any(
|
||||
str: PACKAGE_SCHEMA,
|
||||
}
|
||||
),
|
||||
cv.ensure_list(PACKAGE_SCHEMA),
|
||||
[PACKAGE_SCHEMA],
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user