|
1 | 1 | """Tests for the ObstaclePhotoTrait.""" |
2 | 2 |
|
3 | 3 | import gzip |
4 | | -from unittest.mock import AsyncMock |
| 4 | +from unittest.mock import AsyncMock, patch |
5 | 5 |
|
6 | 6 | import pytest |
7 | 7 |
|
|
11 | 11 | parse_photo_data, |
12 | 12 | ) |
13 | 13 | from roborock.exceptions import RoborockException |
| 14 | +from roborock.protocol import Utils |
14 | 15 | from roborock.protocols.v1_protocol import create_blob_response_decoder |
15 | 16 | from roborock.roborock_message import RoborockMessage, RoborockMessageProtocol |
16 | 17 | from roborock.roborock_typing import RoborockCommand |
@@ -81,6 +82,35 @@ def test_decode_blob_response() -> None: |
81 | 82 | assert response.data == decompressed |
82 | 83 |
|
83 | 84 |
|
| 85 | +def test_decode_blob_response_wraps_decompression_errors() -> None: |
| 86 | + """Test expected gzip decompression errors are wrapped.""" |
| 87 | + payload = bytearray(25) |
| 88 | + payload[:8] = b"ROBOROCK" |
| 89 | + payload[16:18] = (24).to_bytes(2, "little") |
| 90 | + payload[20:24] = (1).to_bytes(4, "little") |
| 91 | + |
| 92 | + with pytest.raises(RoborockException, match="Failed to decode blob message payload"): |
| 93 | + create_blob_response_decoder()( |
| 94 | + RoborockMessage(protocol=RoborockMessageProtocol.MAP_RESPONSE, payload=bytes(payload)) |
| 95 | + ) |
| 96 | + |
| 97 | + |
| 98 | +def test_decode_blob_response_does_not_wrap_unexpected_errors() -> None: |
| 99 | + """Test unexpected decompression errors propagate unchanged.""" |
| 100 | + payload = bytearray(25) |
| 101 | + payload[:8] = b"ROBOROCK" |
| 102 | + payload[16:18] = (24).to_bytes(2, "little") |
| 103 | + payload[20:24] = (1).to_bytes(4, "little") |
| 104 | + |
| 105 | + with ( |
| 106 | + patch.object(Utils, "decompress", side_effect=RuntimeError("unexpected")), |
| 107 | + pytest.raises(RuntimeError, match="unexpected"), |
| 108 | + ): |
| 109 | + create_blob_response_decoder()( |
| 110 | + RoborockMessage(protocol=RoborockMessageProtocol.MAP_RESPONSE, payload=bytes(payload)) |
| 111 | + ) |
| 112 | + |
| 113 | + |
84 | 114 | def test_obstacle_photo_trait_metadata() -> None: |
85 | 115 | """Test obstacle photos use the blob RPC channel when discovered.""" |
86 | 116 | assert ObstaclePhotoTrait.blob_rpc_channel is True |
|
0 commit comments