diff --git a/tests/transforms/test_rand_grid_distortiond.py b/tests/transforms/test_rand_grid_distortiond.py index b31849f20f..98cb23688b 100644 --- a/tests/transforms/test_rand_grid_distortiond.py +++ b/tests/transforms/test_rand_grid_distortiond.py @@ -88,6 +88,15 @@ def test_rand_grid_distortiond(self, input_param, seed, input_data, expected_val assert_allclose(result["img"], expected_val_img, type_test=False, rtol=1e-4, atol=1e-4) assert_allclose(result["mask"], expected_val_mask, type_test=False, rtol=1e-4, atol=1e-4) + def test_no_transform_preserves_non_image_keys(self): + """Non-image dict entries must not be coerced to tensors when the transform is skipped.""" + img = np.indices([6, 6]).astype(np.float32) + data = {"img": img, "label": 42, "filename": "scan.nii"} + g = RandGridDistortiond(keys=["img"], prob=0.0) + result = g(data) + self.assertIsInstance(result["label"], int) + self.assertIsInstance(result["filename"], str) + def test_no_transform_with_non_tensor_metadata(self): """When _do_transform is False, non-tensor values in the dict should not cause an error.""" img = np.indices([6, 6]).astype(np.float32)