Merge pull request 'Tests(clan_lib): enable clan_lib pytests not marked with_core' (#3779) from inventory-0 into main

Reviewed-on: https://git.clan.lol/clan/clan-core/pulls/3779
This commit is contained in:
hsjobeki
2025-05-28 09:45:56 +00:00
4 changed files with 18 additions and 14 deletions

View File

@@ -7,10 +7,3 @@ from clan_lib.bwrap import bubblewrap_works
@pytest.mark.skipif(sys.platform != "linux", reason="bubblewrap only works on linux")
def test_bubblewrap_works_on_linux() -> None:
assert bubblewrap_works() is True
@pytest.mark.skipif(
sys.platform == "linux", reason="bubblewrap does not work on non-linux"
)
def test_bubblewrap_detection_non_linux() -> None:
assert bubblewrap_works() is False

View File

@@ -132,7 +132,10 @@ class InventoryStore:
- and more
"""
raw_value = self._flake.select("clanInternals.inventoryClass.inventory")
filtered = {k: v for k, v in raw_value.items() if k in self._keys}
if self._keys:
filtered = {k: v for k, v in raw_value.items() if k in self._keys}
else:
filtered = raw_value
sanitized = sanitize(filtered, self._allowed_path_transforms, [])
return sanitized

View File

@@ -10,6 +10,7 @@ from typing import Any
import pytest
from clan_lib.errors import ClanError
from clan_lib.nix import nix_eval
from clan_lib.persist.inventory_store import InventoryStore
from clan_lib.persist.util import delete_by_path, set_value_by_path
@@ -36,12 +37,9 @@ class MockFlake:
assert select, "NIX_SELECT environment variable is not set"
assert clan_core_path, "CLAN_CORE_PATH environment variable is not set"
output = subprocess.run(
cmd = nix_eval(
[
"nix",
"eval",
"--impure",
"--json",
"--expr",
f"""
let
@@ -54,6 +52,9 @@ class MockFlake:
select "{selector}" result
""",
],
)
output = subprocess.run(
cmd,
capture_output=True,
)
res_str = output.stdout.decode()
@@ -71,6 +72,7 @@ class MockFlake:
folder_path = Path(__file__).parent.resolve()
@pytest.mark.with_core
def test_simple_read_write() -> None:
entry_file = "1.nix"
inventory_file = entry_file.replace(".nix", ".json")
@@ -90,7 +92,9 @@ def test_simple_read_write() -> None:
store = InventoryStore(
flake=MockFlake(Path(tmp) / entry_file),
inventory_file_name=inventory_file,
_keys=[], # disable toplevel filtering
)
store._flake.invalidate_cache()
data: dict = store.read() # type: ignore
assert data == {"foo": "bar", "protected": "protected"}
@@ -118,6 +122,7 @@ def test_simple_read_write() -> None:
store.write(data, "test", commit=False) # type: ignore
@pytest.mark.with_core
def test_read_deferred() -> None:
entry_file = "deferred.nix"
inventory_file = entry_file.replace(".nix", ".json")
@@ -138,6 +143,7 @@ def test_read_deferred() -> None:
flake=MockFlake(Path(tmp) / entry_file),
inventory_file_name=inventory_file,
_allowed_path_transforms=["foo.*"],
_keys=[], # disable toplevel filtering
)
data = store.read()

View File

@@ -83,7 +83,9 @@ let
include = [
(
_root: path: _type:
(builtins.match "test_.*\.py" path) == null
(builtins.match ".*/test_[^/]+\.py" path) == null
&& (builtins.match ".*/[^/]+_test\.py" path) == null
# && (builtins.match ".*/tests/.+" path) == null
)
];
}
@@ -176,7 +178,7 @@ pythonRuntime.pkgs.buildPythonApplication {
# limit build cores to 16
jobs="$((NIX_BUILD_CORES>16 ? 16 : NIX_BUILD_CORES))"
python -m pytest -m "not impure and not with_core" -n $jobs ./clan_cli/tests
python -m pytest -m "not impure and not with_core" -n $jobs ./clan_cli ./clan_lib
touch $out
'';
}