mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Make !include_dir_list use alphanumeric order (#21902)
* Make YAML includes such as !include_dir_list incorporate files in alphabetical order * Test for !include_dir_list sorting
This commit is contained in:
parent
4b1de61110
commit
88be786e82
@ -144,7 +144,7 @@ def _find_files(directory: str, pattern: str) -> Iterator[str]:
|
||||
"""Recursively load files in a directory."""
|
||||
for root, dirs, files in os.walk(directory, topdown=True):
|
||||
dirs[:] = [d for d in dirs if _is_file_valid(d)]
|
||||
for basename in files:
|
||||
for basename in sorted(files):
|
||||
if _is_file_valid(basename) and fnmatch.fnmatch(basename, pattern):
|
||||
filename = os.path.join(root, basename)
|
||||
yield filename
|
||||
|
@ -95,7 +95,7 @@ class TestYaml(unittest.TestCase):
|
||||
def test_include_dir_list(self, mock_walk):
|
||||
"""Test include dir list yaml."""
|
||||
mock_walk.return_value = [
|
||||
['/tmp', [], ['one.yaml', 'two.yaml']],
|
||||
['/tmp', [], ['two.yaml', 'one.yaml']],
|
||||
]
|
||||
|
||||
with patch_yaml_files({
|
||||
@ -105,7 +105,7 @@ class TestYaml(unittest.TestCase):
|
||||
conf = "key: !include_dir_list /tmp"
|
||||
with io.StringIO(conf) as file:
|
||||
doc = yaml.yaml.safe_load(file)
|
||||
assert sorted(doc["key"]) == sorted(["one", "two"])
|
||||
assert doc["key"] == sorted(["one", "two"])
|
||||
|
||||
@patch('homeassistant.util.yaml.os.walk')
|
||||
def test_include_dir_list_recursive(self, mock_walk):
|
||||
|
Loading…
x
Reference in New Issue
Block a user