Files
AnyImage/tests/test_node_asset_launcher.py
nan 4c902ed7db feat(node_assets): add image plane geometry nodes and validation scripts
- Implemented `image_plane.py` to build the Image Plane Geometry Nodes group with customizable parameters for geometry, subdivide, and thickness.
- Created `image_plane_validation.py` to validate the functionality of the image plane, ensuring correct geometry generation and material assignment.
- Developed `material_layers.py` to construct shader node groups for image materials, including depth and normal handling.
- Authored `plane_layouts.py` to define node arrangements for image geometry assets.
- Introduced `shadeless.py` to create a shadeless shader node group that displays color without scene lighting while preserving shadows and reflections.
2026-09-08 23:24:27 +08:00

93 lines
2.7 KiB
Python

import importlib.util
from pathlib import Path
from unittest.mock import patch
import pytest
PROJECT_ROOT = Path(__file__).resolve().parents[1]
SCRIPT_PATH = PROJECT_ROOT / "tools" / "build_node.py"
def load_launcher():
specification = importlib.util.spec_from_file_location(
"node_asset_launcher",
SCRIPT_PATH,
)
module = importlib.util.module_from_spec(specification)
specification.loader.exec_module(module)
return module
def test_blender_path_prefers_explicit_path(tmp_path):
launcher = load_launcher()
executable = tmp_path / "blender"
executable.touch()
with patch.dict("os.environ", {"BLENDER_BIN": "ignored"}):
assert launcher.blender_path(executable) == executable
def test_blender_path_reads_environment(tmp_path):
launcher = load_launcher()
executable = tmp_path / "blender"
executable.touch()
with patch.dict("os.environ", {"BLENDER_BIN": str(executable)}):
assert launcher.blender_path() == executable
def test_blender_path_reads_project_dotenv(tmp_path):
launcher = load_launcher()
executable = tmp_path / "Blender 4.5" / "blender.exe"
executable.parent.mkdir()
executable.touch()
env_path = tmp_path / ".env"
env_path.write_text(
f'BLENDER_BIN="{executable}"\n',
encoding="utf-8",
)
with patch.dict("os.environ", {}, clear=True), patch.object(
launcher,
"PROJECT_ROOT",
tmp_path,
):
assert launcher.blender_path() == executable
def test_blender_path_reports_missing_configuration(tmp_path):
launcher = load_launcher()
with patch.dict("os.environ", {}, clear=True), patch.object(
launcher.shutil,
"which",
return_value=None,
), patch.object(
launcher,
"PROJECT_ROOT",
tmp_path,
):
with pytest.raises(RuntimeError, match="Blender not found"):
launcher.blender_path()
def test_launcher_runs_asset_build_and_validations_before_tests(monkeypatch, tmp_path):
launcher = load_launcher()
executable = tmp_path / "blender"
executable.touch()
calls = []
monkeypatch.setattr(launcher, "blender_path", lambda _: executable)
monkeypatch.setattr(launcher, "run", calls.append)
monkeypatch.setattr("sys.argv", ["build_node"])
launcher.main()
scripts = [Path(command[-1]) for command in calls[:-1]]
assert [path.name for path in scripts] == [
"asset_library.py", "asset_validation.py",
"image_plane_validation.py", "cutout_validation.py",
]
assert all(path.is_file() for path in scripts)
assert all(command[1:4] == ("--factory-startup", "--background", "--python") for command in calls[:-1])
assert calls[-1][1:] == ("-m", "pytest")