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:
@@ -8,7 +8,6 @@ import pytest
|
||||
from scipy.spatial import cKDTree
|
||||
|
||||
from anyimage.common.object import modifier_input_identifier, set_modifier_input
|
||||
from anyimage.operators.cutout_tool.object import load_cutout_node_group
|
||||
from tests.support.depth_surface import assert_closed, evaluated
|
||||
from tools.nodes.common.normal_map import AXIS_ATTRIBUTE, FACE_ATTRIBUTE, ROTATION_ATTRIBUTE
|
||||
from tools.nodes.groups.image_depth_cutout import build_image_depth_cutout_group
|
||||
@@ -28,8 +27,8 @@ def _set_value(obj, modifier, group):
|
||||
return setter
|
||||
|
||||
|
||||
@pytest.fixture(params=["definition", "asset"])
|
||||
def symmetry(request):
|
||||
@pytest.fixture
|
||||
def symmetry():
|
||||
bpy.ops.wm.read_factory_settings(use_empty=True)
|
||||
count = 5
|
||||
z, x = np.meshgrid(
|
||||
@@ -70,16 +69,8 @@ def symmetry(request):
|
||||
obj = bpy.data.objects.new("Symmetry", mesh)
|
||||
bpy.context.collection.objects.link(obj)
|
||||
|
||||
cutout_group = (
|
||||
build_image_depth_cutout_group()
|
||||
if request.param == "definition"
|
||||
else load_cutout_node_group("DEPTH_SOLID")
|
||||
)
|
||||
mirror_group = (
|
||||
build_image_cutout_symmetry_group()
|
||||
if request.param == "definition"
|
||||
else load_cutout_node_group("DEPTH_SYMMETRY")
|
||||
)
|
||||
cutout_group = build_image_depth_cutout_group()
|
||||
mirror_group = build_image_cutout_symmetry_group()
|
||||
cutout = obj.modifiers.new(cutout_group.name, "NODES")
|
||||
cutout.node_group = cutout_group
|
||||
mirror = obj.modifiers.new(mirror_group.name, "NODES")
|
||||
@@ -240,59 +231,6 @@ def test_fill_smooth_relaxes_the_junction_band(symmetry):
|
||||
assert cKDTree(smooth_points).query(smooth_points * (-1, 1, 1))[0].max() < 1e-5
|
||||
|
||||
|
||||
def test_fill_smooth_band_reaches_beyond_two_rings():
|
||||
"""Smooth 平滑的是衔接带,覆盖范围比原先的两圈更宽。"""
|
||||
from tools.nodes.common.depth_surface import _math
|
||||
from tools.nodes.groups.image_cutout_symmetry import SMOOTH_RINGS, _falloff
|
||||
|
||||
bpy.ops.wm.read_factory_settings(use_empty=True)
|
||||
size, rows = SMOOTH_RINGS + 4, 3
|
||||
points = [(x, 0.0, y) for y in range(rows) for x in range(size)]
|
||||
faces = [
|
||||
(
|
||||
y * size + x,
|
||||
y * size + x + 1,
|
||||
(y + 1) * size + x + 1,
|
||||
(y + 1) * size + x,
|
||||
)
|
||||
for y in range(rows - 1)
|
||||
for x in range(size - 1)
|
||||
]
|
||||
mesh = bpy.data.meshes.new("Fill band")
|
||||
mesh.from_pydata(points, [], faces)
|
||||
obj = bpy.data.objects.new("Fill band", mesh)
|
||||
bpy.context.collection.objects.link(obj)
|
||||
group = bpy.data.node_groups.new("Fill band", "GeometryNodeTree")
|
||||
for direction in ("INPUT", "OUTPUT"):
|
||||
group.interface.new_socket(
|
||||
name="Geometry", in_out=direction, socket_type="NodeSocketGeometry"
|
||||
)
|
||||
source = group.nodes.new("NodeGroupInput")
|
||||
position = group.nodes.new("GeometryNodeInputPosition")
|
||||
axes = group.nodes.new("ShaderNodeSeparateXYZ")
|
||||
group.links.new(position.outputs[0], axes.inputs[0])
|
||||
outline = _math(group, "COMPARE", axes.outputs["X"], 0)
|
||||
store = group.nodes.new("GeometryNodeStoreNamedAttribute")
|
||||
store.data_type, store.domain = "FLOAT", "POINT"
|
||||
store.inputs["Name"].default_value = "fill_band"
|
||||
group.links.new(source.outputs["Geometry"], store.inputs["Geometry"])
|
||||
group.links.new(_falloff(group, outline, SMOOTH_RINGS), store.inputs["Value"])
|
||||
group.links.new(
|
||||
store.outputs["Geometry"], group.nodes.new("NodeGroupOutput").inputs["Geometry"]
|
||||
)
|
||||
obj.modifiers.new("Fill band", "NODES").node_group = group
|
||||
result = obj.evaluated_get(bpy.context.evaluated_depsgraph_get())
|
||||
data = result.to_mesh()
|
||||
try:
|
||||
band = np.array(
|
||||
[item.value for item in data.attributes["fill_band"].data]
|
||||
).reshape(rows, size)
|
||||
finally:
|
||||
result.to_mesh_clear()
|
||||
assert (band[:, 3] > 0).all()
|
||||
assert (band[:, SMOOTH_RINGS + 1] == 0).all()
|
||||
|
||||
|
||||
def test_object_normal_attributes_follow_final_orientation(symmetry):
|
||||
obj, _cutout, _mirror, cutout_setter, _mirror_setter = symmetry
|
||||
cutout_setter("Mode", 1)
|
||||
|
||||
Reference in New Issue
Block a user