Files
AnyImage/tests/tools/nodes/test_cli.py
nan 9debab5c0c Add comprehensive tests for image processing nodes and refactor node imports
- Introduced new test files for image layer, image plane, normal scale, object normal rotation, shadeless, and temporary attributes.
- Implemented tests to validate the behavior of alpha curves, depth layers, and normal scales in various rendering engines.
- Refactored import paths for node groups to align with the new directory structure.
- Added checks for temporary attribute lifetimes and ensured proper cleanup without warnings.
- Enhanced CLI commands to require the Blender group and validate the presence of generated node assets before packaging.
- Updated packaging scripts to enforce the existence of necessary assets, preventing build failures.
2026-09-19 21:23:19 +08:00

93 lines
3.0 KiB
Python

from tests.support.paths import PROJECT_ROOT
import importlib.util
import subprocess
from unittest.mock import patch
import pytest
SCRIPT_PATH = PROJECT_ROOT / "tools" / "nodes" / "cli.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_commands_require_the_blender_group(monkeypatch):
launcher = load_launcher()
monkeypatch.setattr("sys.argv", ["node-group", "check"])
with patch.object(launcher.importlib.util, "find_spec", return_value=None):
with pytest.raises(RuntimeError, match="--group blender"):
launcher.main()
@pytest.mark.parametrize("arguments,commands", [
(["build"], [
("tools.nodes.build", ()),
("tools.nodes.check", ()),
("pytest", ("tests/nodes", "tests/tools/nodes")),
]),
(["check", "--skip-tests"], [("tools.nodes.check", ())]),
(["preview", "--fragment"], [
("tools.nodes.preview.export", "preview"),
]),
])
def test_commands_dispatch_requested_work(monkeypatch, tmp_path, arguments, commands):
launcher = load_launcher()
output = tmp_path / "node groups.html"
command = ["node-group", *arguments]
if arguments[0] == "preview":
command += ["--output", str(output)]
monkeypatch.setattr("sys.argv", command)
with (
patch.object(launcher, "require_bpy"),
patch.object(launcher, "run_module") as run_module,
patch.object(launcher, "run") as run,
patch.object(launcher.webbrowser, "open") as open_browser,
):
launcher.main()
if arguments[0] == "preview":
run_module.assert_called_once_with(
"tools.nodes.preview.export",
["--output", str(output), "--fragment"],
)
open_browser.assert_not_called()
else:
expected_modules = [item[0] for item in commands if item[0] != "pytest"]
assert [call.args[0] for call in run_module.call_args_list] == expected_modules
if any(item[0] == "pytest" for item in commands):
run.assert_called_once_with(
(
launcher.sys.executable,
"-m",
"pytest",
"tests/nodes",
"tests/tools/nodes",
)
)
else:
run.assert_not_called()
def test_module_failure_stops_later_steps(monkeypatch):
launcher = load_launcher()
monkeypatch.setattr("sys.argv", ["node-group", "build"])
with (
patch.object(launcher, "require_bpy"),
patch.object(
launcher,
"run_module",
side_effect=subprocess.CalledProcessError(1, "build"),
) as run_module,
patch.object(launcher, "run") as run,
):
with pytest.raises(subprocess.CalledProcessError):
launcher.main()
run_module.assert_called_once_with("tools.nodes.build")
run.assert_not_called()