Refactor tests and remove unused imports

- Cleaned up test files by removing unnecessary imports and unused parameters.
- Simplified test functions by eliminating redundant parameterization and consolidating logic.
- Updated test cases to directly use defined values instead of parameterized inputs where applicable.
- Enhanced readability and maintainability of the test code across various test files.
This commit is contained in:
2026-09-17 10:02:05 +08:00
parent ac7f5a7f6d
commit 0aeb61f818
22 changed files with 95 additions and 372 deletions

View File

@@ -5,16 +5,31 @@ import numpy as np
import pytest
from tools.nodes.build import build_node_groups
from tools.nodes.check import ASSET_PATH, GEOMETRY_NAMES, SHADER_NAMES
from tools.nodes.arrangement.arrange import arrange_nodes
from tools.nodes.arrangement.dimensions import estimate_node_dimensions
from tools.nodes.check import ASSET_PATH, SHADER_NAMES
from tools.nodes.groups.image_depth_cutout import build_image_depth_cutout_group
from tools.nodes.groups.image_depth_layer import build_image_depth_layer_group
from tools.nodes.groups.image_layer import build_image_layer_group
from tools.nodes.groups.shadeless import build_shadeless_group
@pytest.fixture(params=sorted(GEOMETRY_NAMES | SHADER_NAMES))
BUILDERS = (
("O Image Depth Cutout", build_image_depth_cutout_group),
("O Image Layer", build_image_layer_group),
)
SHADER_BUILDERS = {
"O Image Layer": build_image_layer_group,
"O Image Depth Layer": build_image_depth_layer_group,
"O Shadeless": build_shadeless_group,
}
@pytest.fixture(params=[name for name, _ in BUILDERS])
def node_group(request):
bpy.ops.wm.read_factory_settings(use_empty=True)
return next(group for group in build_node_groups() if group.name == request.param)
return next(builder() for name, builder in BUILDERS if name == request.param)
def _source(socket):
@@ -148,16 +163,12 @@ def test_arrangement_preserves_program_and_evaluation(node_group):
assert all(not (box[0] < other[2] and box[2] > other[0]
and box[1] < other[3] and box[3] > other[1]) for other in boxes), node.name
boxes.append(box)
input_count = sum(node.bl_idname == "NodeGroupInput" for node in display_nodes)
arrange_nodes(node_group)
assert _program(node_group) == program
assert sum(node.bl_idname == "NodeGroupInput" for node in node_group.nodes) == input_count
@pytest.mark.parametrize("name", sorted(SHADER_NAMES))
def test_shader_asset_preserves_definition(name):
bpy.ops.wm.read_factory_settings(use_empty=True)
definition = next(group for group in build_node_groups() if group.name == name)
definition = SHADER_BUILDERS[name]()
expected = _program(definition)
with bpy.data.libraries.load(str(ASSET_PATH)) as (_, target):
target.node_groups = [name]