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:
@@ -7,10 +7,3 @@ from clan_lib.bwrap import bubblewrap_works
|
|||||||
@pytest.mark.skipif(sys.platform != "linux", reason="bubblewrap only works on linux")
|
@pytest.mark.skipif(sys.platform != "linux", reason="bubblewrap only works on linux")
|
||||||
def test_bubblewrap_works_on_linux() -> None:
|
def test_bubblewrap_works_on_linux() -> None:
|
||||||
assert bubblewrap_works() is True
|
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
|
|
||||||
|
|||||||
@@ -132,7 +132,10 @@ class InventoryStore:
|
|||||||
- and more
|
- and more
|
||||||
"""
|
"""
|
||||||
raw_value = self._flake.select("clanInternals.inventoryClass.inventory")
|
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, [])
|
sanitized = sanitize(filtered, self._allowed_path_transforms, [])
|
||||||
|
|
||||||
return sanitized
|
return sanitized
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ from typing import Any
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from clan_lib.errors import ClanError
|
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.inventory_store import InventoryStore
|
||||||
from clan_lib.persist.util import delete_by_path, set_value_by_path
|
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 select, "NIX_SELECT environment variable is not set"
|
||||||
assert clan_core_path, "CLAN_CORE_PATH 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",
|
"--impure",
|
||||||
"--json",
|
|
||||||
"--expr",
|
"--expr",
|
||||||
f"""
|
f"""
|
||||||
let
|
let
|
||||||
@@ -54,6 +52,9 @@ class MockFlake:
|
|||||||
select "{selector}" result
|
select "{selector}" result
|
||||||
""",
|
""",
|
||||||
],
|
],
|
||||||
|
)
|
||||||
|
output = subprocess.run(
|
||||||
|
cmd,
|
||||||
capture_output=True,
|
capture_output=True,
|
||||||
)
|
)
|
||||||
res_str = output.stdout.decode()
|
res_str = output.stdout.decode()
|
||||||
@@ -71,6 +72,7 @@ class MockFlake:
|
|||||||
folder_path = Path(__file__).parent.resolve()
|
folder_path = Path(__file__).parent.resolve()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.with_core
|
||||||
def test_simple_read_write() -> None:
|
def test_simple_read_write() -> None:
|
||||||
entry_file = "1.nix"
|
entry_file = "1.nix"
|
||||||
inventory_file = entry_file.replace(".nix", ".json")
|
inventory_file = entry_file.replace(".nix", ".json")
|
||||||
@@ -90,7 +92,9 @@ def test_simple_read_write() -> None:
|
|||||||
store = InventoryStore(
|
store = InventoryStore(
|
||||||
flake=MockFlake(Path(tmp) / entry_file),
|
flake=MockFlake(Path(tmp) / entry_file),
|
||||||
inventory_file_name=inventory_file,
|
inventory_file_name=inventory_file,
|
||||||
|
_keys=[], # disable toplevel filtering
|
||||||
)
|
)
|
||||||
|
store._flake.invalidate_cache()
|
||||||
data: dict = store.read() # type: ignore
|
data: dict = store.read() # type: ignore
|
||||||
assert data == {"foo": "bar", "protected": "protected"}
|
assert data == {"foo": "bar", "protected": "protected"}
|
||||||
|
|
||||||
@@ -118,6 +122,7 @@ def test_simple_read_write() -> None:
|
|||||||
store.write(data, "test", commit=False) # type: ignore
|
store.write(data, "test", commit=False) # type: ignore
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.with_core
|
||||||
def test_read_deferred() -> None:
|
def test_read_deferred() -> None:
|
||||||
entry_file = "deferred.nix"
|
entry_file = "deferred.nix"
|
||||||
inventory_file = entry_file.replace(".nix", ".json")
|
inventory_file = entry_file.replace(".nix", ".json")
|
||||||
@@ -138,6 +143,7 @@ def test_read_deferred() -> None:
|
|||||||
flake=MockFlake(Path(tmp) / entry_file),
|
flake=MockFlake(Path(tmp) / entry_file),
|
||||||
inventory_file_name=inventory_file,
|
inventory_file_name=inventory_file,
|
||||||
_allowed_path_transforms=["foo.*"],
|
_allowed_path_transforms=["foo.*"],
|
||||||
|
_keys=[], # disable toplevel filtering
|
||||||
)
|
)
|
||||||
|
|
||||||
data = store.read()
|
data = store.read()
|
||||||
|
|||||||
@@ -83,7 +83,9 @@ let
|
|||||||
include = [
|
include = [
|
||||||
(
|
(
|
||||||
_root: path: _type:
|
_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
|
# limit build cores to 16
|
||||||
jobs="$((NIX_BUILD_CORES>16 ? 16 : NIX_BUILD_CORES))"
|
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
|
touch $out
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user