|
1 | 1 | import asyncio |
| 2 | +from collections.abc import Iterator, Mapping |
2 | 3 | from types import MappingProxyType |
3 | 4 |
|
4 | 5 | import pytest |
@@ -183,6 +184,59 @@ def test_parse_session_recordings_response_data_wraps_invalid_items(): |
183 | 184 | assert exc_info.value.original_error is not None |
184 | 185 |
|
185 | 186 |
|
| 187 | +def test_parse_session_recordings_response_data_wraps_unreadable_recording_items(): |
| 188 | + class _BrokenRecordingMapping(Mapping[str, object]): |
| 189 | + def __iter__(self) -> Iterator[str]: |
| 190 | + raise RuntimeError("cannot iterate recording object") |
| 191 | + |
| 192 | + def __len__(self) -> int: |
| 193 | + return 1 |
| 194 | + |
| 195 | + def __getitem__(self, key: str) -> object: |
| 196 | + _ = key |
| 197 | + return "ignored" |
| 198 | + |
| 199 | + with pytest.raises( |
| 200 | + HyperbrowserError, |
| 201 | + match="Failed to read session recording object at index 0", |
| 202 | + ) as exc_info: |
| 203 | + parse_session_recordings_response_data([_BrokenRecordingMapping()]) |
| 204 | + |
| 205 | + assert exc_info.value.original_error is not None |
| 206 | + |
| 207 | + |
| 208 | +def test_parse_session_recordings_response_data_preserves_hyperbrowser_recording_read_errors(): |
| 209 | + class _BrokenRecordingMapping(Mapping[str, object]): |
| 210 | + def __iter__(self) -> Iterator[str]: |
| 211 | + raise HyperbrowserError("custom recording read failure") |
| 212 | + |
| 213 | + def __len__(self) -> int: |
| 214 | + return 1 |
| 215 | + |
| 216 | + def __getitem__(self, key: str) -> object: |
| 217 | + _ = key |
| 218 | + return "ignored" |
| 219 | + |
| 220 | + with pytest.raises( |
| 221 | + HyperbrowserError, match="custom recording read failure" |
| 222 | + ) as exc_info: |
| 223 | + parse_session_recordings_response_data([_BrokenRecordingMapping()]) |
| 224 | + |
| 225 | + assert exc_info.value.original_error is None |
| 226 | + |
| 227 | + |
| 228 | +def test_parse_session_recordings_response_data_rejects_non_string_recording_keys(): |
| 229 | + with pytest.raises( |
| 230 | + HyperbrowserError, |
| 231 | + match="Expected session recording object keys to be strings at index 0", |
| 232 | + ): |
| 233 | + parse_session_recordings_response_data( |
| 234 | + [ |
| 235 | + {1: "bad-key"}, # type: ignore[dict-item] |
| 236 | + ] |
| 237 | + ) |
| 238 | + |
| 239 | + |
186 | 240 | def test_parse_session_recordings_response_data_wraps_unreadable_list_iteration(): |
187 | 241 | class _BrokenRecordingList(list): |
188 | 242 | def __iter__(self): |
|
0 commit comments