mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Improve tests of backup exclusion (#141303)
This commit is contained in:
parent
6661218220
commit
3132cba51f
@ -61,24 +61,48 @@ def path_glob_fixture(hass: HomeAssistant) -> Generator[MagicMock]:
|
|||||||
|
|
||||||
|
|
||||||
CONFIG_DIR = {
|
CONFIG_DIR = {
|
||||||
"testing_config": [
|
"tests/testing_config": [
|
||||||
Path("test.txt"),
|
Path("test.txt"),
|
||||||
Path(".DS_Store"),
|
Path(".DS_Store"),
|
||||||
Path(".storage"),
|
Path(".storage"),
|
||||||
|
Path("another_subdir"),
|
||||||
Path("backups"),
|
Path("backups"),
|
||||||
Path("tmp_backups"),
|
Path("tmp_backups"),
|
||||||
|
Path("tts"),
|
||||||
Path("home-assistant_v2.db"),
|
Path("home-assistant_v2.db"),
|
||||||
],
|
],
|
||||||
"backups": [
|
"/backups": [
|
||||||
Path("backups/backup.tar"),
|
Path("backups/backup.tar"),
|
||||||
Path("backups/not_backup"),
|
Path("backups/not_backup"),
|
||||||
],
|
],
|
||||||
"tmp_backups": [
|
"/another_subdir": [
|
||||||
|
Path("another_subdir/backups"),
|
||||||
|
Path("another_subdir/tts"),
|
||||||
|
],
|
||||||
|
"another_subdir/backups": [
|
||||||
|
Path("another_subdir/backups/backup.tar"),
|
||||||
|
Path("another_subdir/backups/not_backup"),
|
||||||
|
],
|
||||||
|
"another_subdir/tts": [
|
||||||
|
Path("another_subdir/tts/voice.mp3"),
|
||||||
|
],
|
||||||
|
"/tmp_backups": [ # noqa: S108
|
||||||
Path("tmp_backups/forgotten_backup.tar"),
|
Path("tmp_backups/forgotten_backup.tar"),
|
||||||
Path("tmp_backups/not_backup"),
|
Path("tmp_backups/not_backup"),
|
||||||
],
|
],
|
||||||
|
"/tts": [
|
||||||
|
Path("tts/voice.mp3"),
|
||||||
|
],
|
||||||
|
}
|
||||||
|
CONFIG_DIR_DIRS = {
|
||||||
|
Path(".storage"),
|
||||||
|
Path("another_subdir"),
|
||||||
|
Path("another_subdir/backups"),
|
||||||
|
Path("another_subdir/tts"),
|
||||||
|
Path("backups"),
|
||||||
|
Path("tmp_backups"),
|
||||||
|
Path("tts"),
|
||||||
}
|
}
|
||||||
CONFIG_DIR_DIRS = {Path(".storage"), Path("backups"), Path("tmp_backups")}
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="create_backup")
|
@pytest.fixture(name="create_backup")
|
||||||
@ -105,7 +129,10 @@ def mock_backup_generation_fixture(
|
|||||||
"""Mock backup generator."""
|
"""Mock backup generator."""
|
||||||
|
|
||||||
with (
|
with (
|
||||||
patch("pathlib.Path.iterdir", lambda x: CONFIG_DIR.get(x.name, [])),
|
patch(
|
||||||
|
"pathlib.Path.iterdir",
|
||||||
|
lambda x: CONFIG_DIR.get(f"{x.parent.name}/{x.name}", []),
|
||||||
|
),
|
||||||
patch("pathlib.Path.stat", return_value=MagicMock(st_size=123)),
|
patch("pathlib.Path.stat", return_value=MagicMock(st_size=123)),
|
||||||
patch("pathlib.Path.is_file", lambda x: x not in CONFIG_DIR_DIRS),
|
patch("pathlib.Path.is_file", lambda x: x not in CONFIG_DIR_DIRS),
|
||||||
patch("pathlib.Path.is_dir", lambda x: x in CONFIG_DIR_DIRS),
|
patch("pathlib.Path.is_dir", lambda x: x in CONFIG_DIR_DIRS),
|
||||||
|
@ -68,10 +68,15 @@ from tests.typing import ClientSessionGenerator, WebSocketGenerator
|
|||||||
_EXPECTED_FILES = [
|
_EXPECTED_FILES = [
|
||||||
"test.txt",
|
"test.txt",
|
||||||
".storage",
|
".storage",
|
||||||
|
"another_subdir",
|
||||||
|
"another_subdir/backups",
|
||||||
|
"another_subdir/backups/not_backup",
|
||||||
|
"another_subdir/tts",
|
||||||
"backups",
|
"backups",
|
||||||
"backups/not_backup",
|
"backups/not_backup",
|
||||||
"tmp_backups",
|
"tmp_backups",
|
||||||
"tmp_backups/not_backup",
|
"tmp_backups/not_backup",
|
||||||
|
"tts",
|
||||||
]
|
]
|
||||||
_EXPECTED_FILES_WITH_DATABASE = {
|
_EXPECTED_FILES_WITH_DATABASE = {
|
||||||
True: [*_EXPECTED_FILES, "home-assistant_v2.db"],
|
True: [*_EXPECTED_FILES, "home-assistant_v2.db"],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user