Skip to content

Commit 3132cba

Browse files
authored
Improve tests of backup exclusion (#141303)
1 parent 6661218 commit 3132cba

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

tests/components/backup/conftest.py

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,24 +61,48 @@ def path_glob_fixture(hass: HomeAssistant) -> Generator[MagicMock]:
6161

6262

6363
CONFIG_DIR = {
64-
"testing_config": [
64+
"tests/testing_config": [
6565
Path("test.txt"),
6666
Path(".DS_Store"),
6767
Path(".storage"),
68+
Path("another_subdir"),
6869
Path("backups"),
6970
Path("tmp_backups"),
71+
Path("tts"),
7072
Path("home-assistant_v2.db"),
7173
],
72-
"backups": [
74+
"/backups": [
7375
Path("backups/backup.tar"),
7476
Path("backups/not_backup"),
7577
],
76-
"tmp_backups": [
78+
"/another_subdir": [
79+
Path("another_subdir/backups"),
80+
Path("another_subdir/tts"),
81+
],
82+
"another_subdir/backups": [
83+
Path("another_subdir/backups/backup.tar"),
84+
Path("another_subdir/backups/not_backup"),
85+
],
86+
"another_subdir/tts": [
87+
Path("another_subdir/tts/voice.mp3"),
88+
],
89+
"/tmp_backups": [ # noqa: S108
7790
Path("tmp_backups/forgotten_backup.tar"),
7891
Path("tmp_backups/not_backup"),
7992
],
93+
"/tts": [
94+
Path("tts/voice.mp3"),
95+
],
96+
}
97+
CONFIG_DIR_DIRS = {
98+
Path(".storage"),
99+
Path("another_subdir"),
100+
Path("another_subdir/backups"),
101+
Path("another_subdir/tts"),
102+
Path("backups"),
103+
Path("tmp_backups"),
104+
Path("tts"),
80105
}
81-
CONFIG_DIR_DIRS = {Path(".storage"), Path("backups"), Path("tmp_backups")}
82106

83107

84108
@pytest.fixture(name="create_backup")
@@ -105,7 +129,10 @@ def mock_backup_generation_fixture(
105129
"""Mock backup generator."""
106130

107131
with (
108-
patch("pathlib.Path.iterdir", lambda x: CONFIG_DIR.get(x.name, [])),
132+
patch(
133+
"pathlib.Path.iterdir",
134+
lambda x: CONFIG_DIR.get(f"{x.parent.name}/{x.name}", []),
135+
),
109136
patch("pathlib.Path.stat", return_value=MagicMock(st_size=123)),
110137
patch("pathlib.Path.is_file", lambda x: x not in CONFIG_DIR_DIRS),
111138
patch("pathlib.Path.is_dir", lambda x: x in CONFIG_DIR_DIRS),

tests/components/backup/test_manager.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,15 @@
6868
_EXPECTED_FILES = [
6969
"test.txt",
7070
".storage",
71+
"another_subdir",
72+
"another_subdir/backups",
73+
"another_subdir/backups/not_backup",
74+
"another_subdir/tts",
7175
"backups",
7276
"backups/not_backup",
7377
"tmp_backups",
7478
"tmp_backups/not_backup",
79+
"tts",
7580
]
7681
_EXPECTED_FILES_WITH_DATABASE = {
7782
True: [*_EXPECTED_FILES, "home-assistant_v2.db"],

0 commit comments

Comments
 (0)