Skip to content

Commit f505883

Browse files
committed
inference api: add tests for invalid/empty 2d predictions
1 parent 46d09fe commit f505883

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

tests/fmpose3d_api/test_fmpose3d.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,36 @@ def test_predict_applies_partial_2d_mask_to_3d(self):
646646
assert np.all(np.isnan(result.poses_3d[1]))
647647
assert np.all(np.isnan(result.poses_3d_world[1]))
648648

649+
@pytest.mark.parametrize(
650+
"mask,expected_status",
651+
[
652+
(
653+
np.array([False, False], dtype=bool),
654+
ResultStatus.EMPTY,
655+
),
656+
(
657+
np.array([True], dtype=bool),
658+
ResultStatus.INVALID,
659+
),
660+
],
661+
)
662+
def test_predict_raises_on_unusable_2d_status(self, mask, expected_status):
663+
"""predict() raises for EMPTY/INVALID 2D status and skips 3D lifting."""
664+
api = _make_ready_api("fmpose3d_humans", test_augmentation=False)
665+
mock_kpts = np.random.randn(1, 2, 17, 2).astype("float32")
666+
mock_scores = np.ones((1, 2, 17), dtype="float32")
667+
api._estimator_2d = MagicMock()
668+
api._estimator_2d.predict.return_value = (mock_kpts, mock_scores, mask)
669+
api._estimator_2d.setup_runtime = MagicMock()
670+
api.pose_3d = MagicMock()
671+
672+
frame = np.random.randint(0, 255, (480, 640, 3), dtype=np.uint8)
673+
with pytest.raises(ValueError) as exc_info:
674+
api.predict([frame, frame], seed=42)
675+
676+
assert f": {expected_status.value}." in str(exc_info.value)
677+
api.pose_3d.assert_not_called()
678+
649679

650680
# =========================================================================
651681
# Unit tests — dataclasses

0 commit comments

Comments
 (0)