pytest: fixtures offline_flake_hook init

This commit is contained in:
Johannes Kirschbauer
2025-07-22 18:06:47 +02:00
parent 9257cb02ee
commit 4597b207e7
2 changed files with 32 additions and 0 deletions

View File

@@ -3,4 +3,5 @@ pytest_plugins = [
"clan_cli.tests.hosts",
"clan_cli.tests.sshd",
"clan_cli.tests.runtime",
"clan_lib.fixtures.flake_hooks",
]

View File

@@ -0,0 +1,31 @@
from collections.abc import Callable
from pathlib import Path
import pytest
from clan_lib.cmd import RunOpts, run
from clan_lib.nix import nix_command
def substitute_flake_inputs(clan_dir: Path, clan_core_path: Path) -> None:
flake_nix = clan_dir / "flake.nix"
assert flake_nix.exists()
content = flake_nix.read_text()
content = content.replace(
"https://git.clan.lol/clan/clan-core/archive/main.tar.gz",
f"path://{clan_core_path}",
)
flake_nix.write_text(content)
run(nix_command(["flake", "update"]), RunOpts(cwd=clan_dir))
flake_lock = clan_dir / "flake.lock"
assert flake_lock.exists(), "flake.lock should exist after flake update"
@pytest.fixture
def offline_flake_hook(clan_core: Path) -> Callable[[Path], None]:
def patch(clan_dir: Path) -> None:
substitute_flake_inputs(clan_dir, clan_core)
return patch