1
0
mirror of https://github.com/home-assistant/supervisor.git synced 2025-12-24 20:35:55 +00:00

Refactor builtin repositories to enum (#5976)

This commit is contained in:
Mike Degatano
2025-06-30 13:22:00 -04:00
committed by GitHub
parent d1c1a2d418
commit 38750d74a8
5 changed files with 101 additions and 44 deletions

View File

@@ -15,6 +15,13 @@ from supervisor.store.git import GitRepo
REPO_URL = "https://github.com/awesome-developer/awesome-repo"
class GitRepoTest(GitRepo):
"""Implementation of GitRepo for tests that allows direct setting of path."""
async def remove(self) -> None:
"""Not implemented."""
@pytest.fixture(name="clone_from")
async def fixture_clone_from():
"""Mock git clone_from."""
@@ -28,7 +35,7 @@ async def test_git_clone(
):
"""Test git clone."""
fragment = f"#{branch}" if branch else ""
repo = GitRepo(coresys, tmp_path, f"{REPO_URL}{fragment}")
repo = GitRepoTest(coresys, tmp_path, f"{REPO_URL}{fragment}")
await repo.clone.__wrapped__(repo)
@@ -56,7 +63,7 @@ async def test_git_clone_error(
coresys: CoreSys, tmp_path: Path, clone_from: AsyncMock, git_error: Exception
):
"""Test git clone error."""
repo = GitRepo(coresys, tmp_path, REPO_URL)
repo = GitRepoTest(coresys, tmp_path, REPO_URL)
clone_from.side_effect = git_error
with pytest.raises(StoreGitCloneError):
@@ -68,7 +75,7 @@ async def test_git_clone_error(
async def test_git_load(coresys: CoreSys, tmp_path: Path):
"""Test git load."""
repo_dir = tmp_path / "repo"
repo = GitRepo(coresys, repo_dir, REPO_URL)
repo = GitRepoTest(coresys, repo_dir, REPO_URL)
repo.clone = AsyncMock()
# Test with non-existing git repo root directory
@@ -106,7 +113,7 @@ async def test_git_load(coresys: CoreSys, tmp_path: Path):
async def test_git_load_error(coresys: CoreSys, tmp_path: Path, git_errors: Exception):
"""Test git load error."""
coresys.hardware.disk.get_disk_free_space = lambda x: 5000
repo = GitRepo(coresys, tmp_path, REPO_URL)
repo = GitRepoTest(coresys, tmp_path, REPO_URL)
# Pretend we have a repo
(tmp_path / ".git").mkdir()