clan_lib flake_test: fix on darwin

This commit is contained in:
lassulus
2025-05-23 12:29:34 +02:00
parent 57cd50ae35
commit 98b0f97d45

View File

@@ -2,7 +2,7 @@ import contextlib
import logging import logging
import subprocess import subprocess
from pathlib import Path from pathlib import Path
from tempfile import TemporaryDirectory from sys import platform
from unittest.mock import patch from unittest.mock import patch
import pytest import pytest
@@ -365,40 +365,40 @@ def test_caching_works(flake: ClanFlake) -> None:
@pytest.mark.with_core @pytest.mark.with_core
def test_cache_gc(monkeypatch: pytest.MonkeyPatch) -> None: def test_cache_gc(temp_dir: Path, monkeypatch: pytest.MonkeyPatch) -> None:
with TemporaryDirectory() as tempdir_: monkeypatch.setenv("NIX_STATE_DIR", str(temp_dir / "var"))
tempdir = Path(tempdir_) 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(temp_dir / "build"))
monkeypatch.setenv("NIX_STATE_DIR", str(tempdir / "var")) test_file = temp_dir / "flake" / "testfile"
monkeypatch.setenv("NIX_LOG_DIR", str(tempdir / "var" / "log")) test_file.parent.mkdir(parents=True, exist_ok=True)
monkeypatch.setenv("NIX_STORE_DIR", str(tempdir / "store")) test_file.write_text("test")
monkeypatch.setenv("NIX_CACHE_HOME", str(tempdir / "cache"))
monkeypatch.setenv("HOME", str(tempdir / "home"))
with contextlib.suppress(KeyError):
monkeypatch.delenv("CLAN_TEST_STORE")
monkeypatch.setenv("NIX_BUILD_TOP", str(tempdir / "build"))
test_file = tempdir / "flake" / "testfile" test_flake = temp_dir / "flake" / "flake.nix"
test_file.parent.mkdir(parents=True, exist_ok=True) test_flake.write_text("""
test_file.write_text("test") {
outputs = _: {
testfile = ./testfile;
};
}
""")
test_flake = tempdir / "flake" / "flake.nix" my_flake = Flake(str(temp_dir / "flake"))
test_flake.write_text(""" if platform == "darwin":
{ my_flake.select("testfile")
outputs = _: { else:
testfile = ./testfile;
};
}
""")
my_flake = Flake(str(tempdir / "flake"))
my_flake.select( 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 not None # noqa: SLF001
assert my_flake._cache.is_cached("testfile") # noqa: SLF001 assert my_flake._cache.is_cached("testfile") # noqa: SLF001
subprocess.run(["nix-collect-garbage"], check=True) subprocess.run(["nix-collect-garbage"], check=True)
assert not my_flake._cache.is_cached("testfile") # noqa: SLF001 assert not my_flake._cache.is_cached("testfile") # noqa: SLF001
# This test fails because the CI sandbox does not have the required packages to run the generators # This test fails because the CI sandbox does not have the required packages to run the generators