diff --git a/tests/test_camera.py b/tests/test_camera.py index 229a8b750..0905bb75d 100644 --- a/tests/test_camera.py +++ b/tests/test_camera.py @@ -11,9 +11,9 @@ from viam.media.video import CameraMimeType, NamedImage, ViamImage from viam.proto.common import DoCommandRequest, DoCommandResponse, GetGeometriesRequest, GetGeometriesResponse, ResponseMetadata from viam.proto.component.camera import ( + Format, CameraServiceStub, DistortionParameters, - Format, GetImageRequest, GetImageResponse, GetImagesRequest, diff --git a/tests/test_vision_service.py b/tests/test_vision_service.py index 071ead48e..baa44c0be 100644 --- a/tests/test_vision_service.py +++ b/tests/test_vision_service.py @@ -104,7 +104,9 @@ ), ] -VISION_IMAGE = ViamImage(bytes([0, 100]), CameraMimeType.JPEG) +# Use string value of CameraMimeType because ViamImage accepts a string mime type in the worst case +# and it may not have the expected CameraMimeType methods defined on it. +VISION_IMAGE = ViamImage(bytes([0, 100]), CameraMimeType.JPEG.value) PROPERTIES = Vision.Properties( classifications_supported=True, @@ -174,7 +176,9 @@ async def test_get_detections(self, vision: MockVision): async def test_get_classifications_from_camera(self, vision: MockVision): extra = {"foo": "get_classifications_from_camera"} - response = await vision.get_classifications_from_camera("fake-camera", 1, extra=extra) + response = await vision.get_classifications_from_camera( + "fake-camera", 1, extra=extra + ) assert response == CLASSIFICATIONS assert vision.extra == extra @@ -197,16 +201,25 @@ async def test_do(self, vision: MockVision): class TestService: - async def test_capture_all_from_camera(self, vision: MockVision, service: VisionRPCService): + async def test_capture_all_from_camera( + self, vision: MockVision, service: VisionRPCService + ): async with ChannelFor([service]) as channel: client = VisionServiceStub(channel) extra = {"foo": "capture_all_from_camera"} request = CaptureAllFromCameraRequest( - name=vision.name, camera_name="fake-camera", return_image=True, return_classifications=True, extra=dict_to_struct(extra) + name=vision.name, + camera_name="fake-camera", + return_image=True, + return_classifications=True, + extra=dict_to_struct(extra), + ) + response: CaptureAllFromCameraResponse = await client.CaptureAllFromCamera( + request ) - response: CaptureAllFromCameraResponse = await client.CaptureAllFromCamera(request) assert response.image.image == VISION_IMAGE.data assert response.image.mime_type == VISION_IMAGE.mime_type + # TODO(RSDK-11728): remove this once we deleted the format field assert response.image.format == VISION_IMAGE.mime_type.to_proto() assert response.classifications == CLASSIFICATIONS assert response.detections == [] @@ -217,19 +230,33 @@ async def test_get_properties(self, vision: MockVision, service: VisionRPCServic async with ChannelFor([service]) as channel: client = VisionServiceStub(channel) extra = {"foo": "get_properties"} - request = GetPropertiesRequest(name=vision.name, extra=dict_to_struct(extra)) + request = GetPropertiesRequest( + name=vision.name, extra=dict_to_struct(extra) + ) response: GetPropertiesResponse = await client.GetProperties(request) - assert response.classifications_supported == PROPERTIES.classifications_supported + assert ( + response.classifications_supported + == PROPERTIES.classifications_supported + ) assert response.detections_supported == PROPERTIES.detections_supported - assert response.object_point_clouds_supported == PROPERTIES.object_point_clouds_supported + assert ( + response.object_point_clouds_supported + == PROPERTIES.object_point_clouds_supported + ) assert vision.extra == extra - async def test_get_detections_from_camera(self, vision: MockVision, service: VisionRPCService): + async def test_get_detections_from_camera( + self, vision: MockVision, service: VisionRPCService + ): async with ChannelFor([service]) as channel: client = VisionServiceStub(channel) extra = {"foo": "get_detections_from_camera"} - request = GetDetectionsFromCameraRequest(name=vision.name, camera_name="fake-camera", extra=dict_to_struct(extra)) - response: GetDetectionsFromCameraResponse = await client.GetDetectionsFromCamera(request) + request = GetDetectionsFromCameraRequest( + name=vision.name, camera_name="fake-camera", extra=dict_to_struct(extra) + ) + response: GetDetectionsFromCameraResponse = ( + await client.GetDetectionsFromCamera(request) + ) assert response.detections == DETECTIONS assert vision.extra == extra @@ -249,16 +276,27 @@ async def test_get_detections(self, vision: MockVision, service: VisionRPCServic assert response.detections == DETECTIONS assert vision.extra == extra - async def test_get_classifications_from_camera(self, vision: MockVision, service: VisionRPCService): + async def test_get_classifications_from_camera( + self, vision: MockVision, service: VisionRPCService + ): async with ChannelFor([service]) as channel: client = VisionServiceStub(channel) extra = {"foo": "get_classifications_from_camera"} - request = GetClassificationsFromCameraRequest(name=vision.name, camera_name="fake-camera", n=1, extra=dict_to_struct(extra)) - response: GetClassificationsFromCameraResponse = await client.GetClassificationsFromCamera(request) + request = GetClassificationsFromCameraRequest( + name=vision.name, + camera_name="fake-camera", + n=1, + extra=dict_to_struct(extra), + ) + response: GetClassificationsFromCameraResponse = ( + await client.GetClassificationsFromCamera(request) + ) assert response.classifications == CLASSIFICATIONS assert vision.extra == extra - async def test_get_classifications(self, vision: MockVision, service: VisionRPCService): + async def test_get_classifications( + self, vision: MockVision, service: VisionRPCService + ): async with ChannelFor([service]) as channel: client = VisionServiceStub(channel) extra = {"foo": "get_classifications"} @@ -271,11 +309,15 @@ async def test_get_classifications(self, vision: MockVision, service: VisionRPCS n=1, extra=dict_to_struct(extra), ) - response: GetClassificationsResponse = await client.GetClassifications(request) + response: GetClassificationsResponse = await client.GetClassifications( + request + ) assert response.classifications == CLASSIFICATIONS assert vision.extra == extra - async def test_get_object_point_clouds(self, vision: MockVision, service: VisionRPCService): + async def test_get_object_point_clouds( + self, vision: MockVision, service: VisionRPCService + ): async with ChannelFor([service]) as channel: client = VisionServiceStub(channel) extra = {"foo": "get_object_point_clouds"} @@ -285,7 +327,9 @@ async def test_get_object_point_clouds(self, vision: MockVision, service: Vision mime_type=CameraMimeType.PCD, extra=dict_to_struct(extra), ) - response: GetObjectPointCloudsResponse = await client.GetObjectPointClouds(request) + response: GetObjectPointCloudsResponse = await client.GetObjectPointClouds( + request + ) assert response.objects == POINT_CLOUDS assert vision.extra == extra @@ -293,7 +337,9 @@ async def test_do(self, vision: MockVision, service: VisionRPCService): async with ChannelFor([service]) as channel: client = VisionServiceStub(channel) command = {"command": "args"} - request = DoCommandRequest(name=vision.name, command=dict_to_struct(command)) + request = DoCommandRequest( + name=vision.name, command=dict_to_struct(command) + ) response: DoCommandResponse = await client.DoCommand(request) assert struct_to_dict(response.result)["cmd"] == command @@ -307,7 +353,9 @@ async def test_get_properties(self, vision: MockVision, service: VisionRPCServic assert response == PROPERTIES assert vision.extra == extra - async def test_capture_all_from_camera(self, vision: MockVision, service: VisionRPCService): + async def test_capture_all_from_camera( + self, vision: MockVision, service: VisionRPCService + ): async with ChannelFor([service]) as channel: client = VisionClient(VISION_SERVICE_NAME, channel) extra = {"foo": "capture_all_from_camera"} @@ -325,11 +373,15 @@ async def test_capture_all_from_camera(self, vision: MockVision, service: Vision assert response.objects == POINT_CLOUDS assert vision.extra == extra - async def test_get_detections_from_camera(self, vision: MockVision, service: VisionRPCService): + async def test_get_detections_from_camera( + self, vision: MockVision, service: VisionRPCService + ): async with ChannelFor([service]) as channel: client = VisionClient(VISION_SERVICE_NAME, channel) extra = {"foo": "get_detections_from_camera"} - response = await client.get_detections_from_camera("fake-camera", extra=extra) + response = await client.get_detections_from_camera( + "fake-camera", extra=extra + ) assert response == DETECTIONS assert vision.extra == extra @@ -341,15 +393,21 @@ async def test_get_detections(self, vision: MockVision, service: VisionRPCServic assert response == DETECTIONS assert vision.extra == extra - async def test_get_classifications_from_camera(self, vision: MockVision, service: VisionRPCService): + async def test_get_classifications_from_camera( + self, vision: MockVision, service: VisionRPCService + ): async with ChannelFor([service]) as channel: client = VisionClient(VISION_SERVICE_NAME, channel) extra = {"foo": "get_classifications_from_camera"} - response = await client.get_classifications_from_camera("fake-camera", 1, extra=extra) + response = await client.get_classifications_from_camera( + "fake-camera", 1, extra=extra + ) assert response == CLASSIFICATIONS assert vision.extra == extra - async def test_get_classifications(self, vision: MockVision, service: VisionRPCService): + async def test_get_classifications( + self, vision: MockVision, service: VisionRPCService + ): async with ChannelFor([service]) as channel: client = VisionClient(VISION_SERVICE_NAME, channel) extra = {"foo": "get_classifications"} @@ -357,7 +415,9 @@ async def test_get_classifications(self, vision: MockVision, service: VisionRPCS assert response == CLASSIFICATIONS assert vision.extra == extra - async def test_get_object_point_clouds(self, vision: MockVision, service: VisionRPCService): + async def test_get_object_point_clouds( + self, vision: MockVision, service: VisionRPCService + ): async with ChannelFor([service]) as channel: client = VisionClient(VISION_SERVICE_NAME, channel) extra = {"foo": "get_object_point_clouds"}