tests/functional2: provide a way to easily access often used assets

Change-Id: I461ee08d9752d972e7485e15186426f98e68ba13
This commit is contained in:
Commentator2.0
2025-08-24 10:38:39 +02:00
committed by Commentator2.0
parent e2641cb890
commit 7b6a85982b
4 changed files with 122 additions and 0 deletions
+29
View File
@@ -1,4 +1,5 @@
import builtins
import os
import types
import typing
from pathlib import Path
@@ -10,6 +11,8 @@ from functional2.testlib.fixtures.file_helper import (
CopyTree,
FileDeclaration,
merge_file_declaration,
Fileish,
CopyTemplate,
)
# Things have to be resolved from top to bottom, because otherwise the tests behave flakey
@@ -131,3 +134,29 @@ def is_value_of_type(value: Any, expected_type: type[Any] | UnionType) -> bool:
case _:
msg = f"Unsupported expected_type. Must be a non-generic or one of {supported_origin_types!r}"
raise ValueError(msg)
def get_global_asset(name: str) -> Fileish:
if name == "config.nix":
return CopyTemplate(
functional2_base_folder / "testlib" / "global_assets" / "config.nix.template",
{
"system": os.environ.get("system"), # noqa: SIM112 # system is actually lowercase here
# Either just the build shell or entire global path if we are darwin
"path": os.environ.get("BUILD_TEST_SHELL") or os.environ.get("PATH"),
},
)
return CopyFile(functional2_base_folder / "testlib" / "global_assets" / name)
def get_global_asset_pack(name: Literal["dependencies"]) -> FileDeclaration:
match name:
case "dependencies":
return {
"config.nix": get_global_asset("config.nix"),
"dependencies.nix": get_global_asset("dependencies.nix"),
"dependencies.builder0.sh": get_global_asset("dependencies.builder0.sh"),
}
case _:
msg = f"invalid pack name {name!r}"
raise ValueError(msg)