Add comprehensive tests for edge depth extension, empty image edits, and material view adaptation

- Introduced `test_edge_depth.py` to validate the functionality of edge depth extension, ensuring core alpha preservation, proper depth handling, and edge padding behavior.
- Created `test_empty_image_edits.py` to verify the behavior of image edits in Blender, focusing on shared edits, preservation of image properties, and handling of failed operations.
- Developed `test_material_view_adaptation.py` to test material adaptation preferences, ensuring color space and alpha settings are correctly applied and preserved across various scenarios.
This commit is contained in:
2026-09-06 21:43:47 +08:00
parent 1994d38ccd
commit 7e55af6722
58 changed files with 3607 additions and 200 deletions

View File

@@ -144,7 +144,7 @@ def test_image_edit_result_uses_complete_shared_source_name():
np.zeros(4 * 4 * 4, dtype=np.float32),
(4, 4),
)
image_data.replace_empty_image(source, result_image)
result_image = image_data.replace_empty_image(source, result_image)
assert shared.data == source_image
assert source_image.alpha_mode == "STRAIGHT"
@@ -168,7 +168,7 @@ def test_image_edit_result_recovers_unshared_source_name():
np.zeros(4 * 4 * 4, dtype=np.float32),
(4, 4),
)
image_data.replace_empty_image(source, result_image)
result_image = image_data.replace_empty_image(source, result_image)
assert source.data == result_image
assert result_image.name == "Poster.png"
@@ -208,7 +208,7 @@ def test_mask_frame_mask_add_preserves_packed_hidden_rgb():
(descriptor,), ((0, 4), (4, 4), (4, 0), (0, 0)), (4, 4)
)
result = image_data.create_image_edit_result(source.data, framed, (4, 4))
image_data.replace_empty_image(source, result)
result = image_data.replace_empty_image(source, result)
assert result.alpha_mode == "PREMUL"
assert source.use_empty_image_alpha
assert result.packed_file is not None
@@ -261,7 +261,7 @@ def test_frame_restored_alpha_keeps_foreground_blended_into_white():
sources, ((0, 4 / 3), (6, 4 / 3), (6, 2 / 3), (0, 2 / 3)), (6, 2)
)
result = image_data.create_image_edit_result(front["object"].data, pixels, (6, 2))
image_data.replace_empty_image(front["object"], result)
result = image_data.replace_empty_image(front["object"], result)
encoded = np.asarray(Image.open(BytesIO(result.packed_file.data)).convert("RGBA")) / 255
np.testing.assert_allclose(encoded[..., :3], expected, atol=1 / 255)
np.testing.assert_allclose(encoded[..., 3:4], source_alpha, atol=1 / 255)
@@ -437,7 +437,11 @@ def test_cutout_axes_produce_the_same_world_geometry(shape):
expected = np.asarray(sorted(map(tuple, world_positions(positive_x))))
actual = np.asarray(sorted(map(tuple, world_positions(negative_z))))
assert np.allclose(actual, expected, atol=2e-6)
from scipy.optimize import linear_sum_assignment
distances = np.linalg.norm(actual[:, None] - expected[None], axis=2)
rows, columns = linear_sum_assignment(distances)
assert distances[rows, columns].max() < 2e-6
assert np.allclose(negative_z.matrix_world, source.matrix_world)
@@ -2100,7 +2104,9 @@ def test_cutout_content_merge_keeps_the_geometric_selection_unchanged():
original = selection.copy()
alpha = np.asarray(((1.0, 0.5), (0.0, 0.25)), dtype=np.float32)
content = cutout_main._cutout_content_values(alpha, selection)
content = cutout_main._cutout_content_values(
alpha, selection, alpha_threshold=0.5
)
np.testing.assert_array_equal(selection, original)
np.testing.assert_allclose(content, alpha * original)
@@ -2140,6 +2146,7 @@ def test_local_cutout_builds_from_blender_image_pixels_without_a_job():
content_values = cutout_main._cutout_content_values(
rgba[top:bottom, left:right, 3],
selection_mask.values,
alpha_threshold=0.5,
)
color_image = cutout_object.create_cropped_color_image(
source,
@@ -2153,6 +2160,7 @@ def test_local_cutout_builds_from_blender_image_pixels_without_a_job():
16,
content_values,
selection_mask.bounds,
alpha_threshold=0.5,
color_image=color_image,
)