fix(sam21): broader httpx catch + tighter test assertions
Catch httpx.RequestError so DecodingError etc. trigger the bbox fallback instead of propagating raw. Lock the intrinsics dict shape in the happy-path test, drop unused imports. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
75da9add84
commit
0bc1e02f11
2 files changed
+6
-3
No files matched your search
@@ -63,7 +63,7 @@ class Sam21Client:
|
|||||||
try:
|
try:
|
||||||
with httpx.Client(timeout=self.timeout_s) as c:
|
with httpx.Client(timeout=self.timeout_s) as c:
|
||||||
r = c.post(url, json=body)
|
r = c.post(url, json=body)
|
||||||
except (httpx.ConnectError, httpx.TimeoutException, httpx.NetworkError) as e:
|
except httpx.RequestError as e:
|
||||||
raise Sam21Unavailable(f"sam21 unreachable: {e}") from e
|
raise Sam21Unavailable(f"sam21 unreachable: {e}") from e
|
||||||
|
|
||||||
# Try to parse the envelope even on non-2xx, because SAM21 always
|
# Try to parse the envelope even on non-2xx, because SAM21 always
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
"""Unit tests for Sam21Client."""
|
"""Unit tests for Sam21Client."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import json
|
from unittest.mock import patch
|
||||||
from unittest.mock import MagicMock, patch
|
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
import numpy as np
|
import numpy as np
|
||||||
@@ -56,6 +55,10 @@ def test_segment_pointcloud_happy_path():
|
|||||||
assert body["return_mask"] is False
|
assert body["return_mask"] is False
|
||||||
assert isinstance(body["rgb_png_base64"], str) and len(body["rgb_png_base64"]) > 0
|
assert isinstance(body["rgb_png_base64"], str) and len(body["rgb_png_base64"]) > 0
|
||||||
assert isinstance(body["depth_png_base64"], str) and len(body["depth_png_base64"]) > 0
|
assert isinstance(body["depth_png_base64"], str) and len(body["depth_png_base64"]) > 0
|
||||||
|
assert body["intrinsics"] == {
|
||||||
|
"fx": 600.0, "fy": 600.0, "cx": 320.0, "cy": 240.0,
|
||||||
|
"width": 640, "height": 480,
|
||||||
|
}
|
||||||
# Output is in meters: mm/1000.
|
# Output is in meters: mm/1000.
|
||||||
assert out.shape == (2, 3)
|
assert out.shape == (2, 3)
|
||||||
assert out.dtype == np.float64
|
assert out.dtype == np.float64
|
||||||
|
|||||||
Reference in new issue
Block a user