clan_lib flake_test: fix on darwin

This commit is contained in:
lassulus
2025-05-23 12:29:34 +02:00
parent a9b1e5f6aa
commit c7384a60c2

View File

@@ -2,7 +2,7 @@ import contextlib
import logging
import subprocess
from pathlib import Path
from tempfile import TemporaryDirectory
from sys import platform
from unittest.mock import patch
import pytest
@@ -365,24 +365,21 @@ def test_caching_works(flake: ClanFlake) -> None:
@pytest.mark.with_core
def test_cache_gc(monkeypatch: pytest.MonkeyPatch) -> None:
with TemporaryDirectory() as tempdir_:
tempdir = Path(tempdir_)
monkeypatch.setenv("NIX_STATE_DIR", str(tempdir / "var"))
monkeypatch.setenv("NIX_LOG_DIR", str(tempdir / "var" / "log"))
monkeypatch.setenv("NIX_STORE_DIR", str(tempdir / "store"))
monkeypatch.setenv("NIX_CACHE_HOME", str(tempdir / "cache"))
monkeypatch.setenv("HOME", str(tempdir / "home"))
def test_cache_gc(temp_dir: Path, monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setenv("NIX_STATE_DIR", str(temp_dir / "var"))
monkeypatch.setenv("NIX_LOG_DIR", str(temp_dir / "var" / "log"))
monkeypatch.setenv("NIX_STORE_DIR", str(temp_dir / "store"))
monkeypatch.setenv("NIX_CACHE_HOME", str(temp_dir / "cache"))
monkeypatch.setenv("HOME", str(temp_dir / "home"))
with contextlib.suppress(KeyError):
monkeypatch.delenv("CLAN_TEST_STORE")
monkeypatch.setenv("NIX_BUILD_TOP", str(tempdir / "build"))
monkeypatch.setenv("NIX_BUILD_TOP", str(temp_dir / "build"))
test_file = tempdir / "flake" / "testfile"
test_file = temp_dir / "flake" / "testfile"
test_file.parent.mkdir(parents=True, exist_ok=True)
test_file.write_text("test")
test_flake = tempdir / "flake" / "flake.nix"
test_flake = temp_dir / "flake" / "flake.nix"
test_flake.write_text("""
{
outputs = _: {
@@ -391,9 +388,12 @@ def test_cache_gc(monkeypatch: pytest.MonkeyPatch) -> None:
}
""")
my_flake = Flake(str(tempdir / "flake"))
my_flake = Flake(str(temp_dir / "flake"))
if platform == "darwin":
my_flake.select("testfile")
else:
my_flake.select(
"testfile", nix_options=["--sandbox-build-dir", str(tempdir / "build")]
"testfile", nix_options=["--sandbox-build-dir", str(temp_dir / "build")]
)
assert my_flake._cache is not None # noqa: SLF001
assert my_flake._cache.is_cached("testfile") # noqa: SLF001