Skip to content

Commit 9fc7a3e

Browse files
Expand passthrough coverage for mapping inspection failures
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent bd0e445 commit 9fc7a3e

1 file changed

Lines changed: 109 additions & 0 deletions

File tree

tests/test_tools_response_handling.py

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,32 @@ def __getitem__(self, key: str) -> object:
416416
assert exc_info.value.original_error is not None
417417

418418

419+
def test_scrape_tool_preserves_hyperbrowser_mapping_field_inspection_failures():
420+
class _BrokenContainsMapping(Mapping[str, object]):
421+
def __iter__(self):
422+
yield "markdown"
423+
424+
def __len__(self) -> int:
425+
return 1
426+
427+
def __contains__(self, key: object) -> bool:
428+
_ = key
429+
raise HyperbrowserError("custom markdown inspect failure")
430+
431+
def __getitem__(self, key: str) -> object:
432+
_ = key
433+
return "ignored"
434+
435+
client = _SyncScrapeClient(_Response(data=_BrokenContainsMapping()))
436+
437+
with pytest.raises(
438+
HyperbrowserError, match="custom markdown inspect failure"
439+
) as exc_info:
440+
WebsiteScrapeTool.runnable(client, {"url": "https://example.com"})
441+
442+
assert exc_info.value.original_error is None
443+
444+
419445
def test_screenshot_tool_rejects_non_string_screenshot_field():
420446
client = _SyncScrapeClient(_Response(data=SimpleNamespace(screenshot=123)))
421447

@@ -583,6 +609,30 @@ def __getitem__(self, key: str) -> object:
583609
assert exc_info.value.original_error is not None
584610

585611

612+
def test_crawl_tool_preserves_hyperbrowser_mapping_page_inspection_failures():
613+
class _BrokenContainsPage(Mapping[str, object]):
614+
def __iter__(self):
615+
yield "markdown"
616+
617+
def __len__(self) -> int:
618+
return 1
619+
620+
def __contains__(self, key: object) -> bool:
621+
_ = key
622+
raise HyperbrowserError("custom page inspect failure")
623+
624+
def __getitem__(self, key: str) -> object:
625+
_ = key
626+
return "ignored"
627+
628+
client = _SyncCrawlClient(_Response(data=[_BrokenContainsPage()]))
629+
630+
with pytest.raises(HyperbrowserError, match="custom page inspect failure") as exc_info:
631+
WebsiteCrawlTool.runnable(client, {"url": "https://example.com"})
632+
633+
assert exc_info.value.original_error is None
634+
635+
586636
def test_crawl_tool_rejects_non_string_page_urls():
587637
client = _SyncCrawlClient(
588638
_Response(data=[SimpleNamespace(url=42, markdown="body")])
@@ -880,6 +930,36 @@ async def run() -> None:
880930
asyncio.run(run())
881931

882932

933+
def test_async_scrape_tool_preserves_hyperbrowser_mapping_field_inspection_failures():
934+
class _BrokenContainsMapping(Mapping[str, object]):
935+
def __iter__(self):
936+
yield "markdown"
937+
938+
def __len__(self) -> int:
939+
return 1
940+
941+
def __contains__(self, key: object) -> bool:
942+
_ = key
943+
raise HyperbrowserError("custom markdown inspect failure")
944+
945+
def __getitem__(self, key: str) -> object:
946+
_ = key
947+
return "ignored"
948+
949+
async def run() -> None:
950+
client = _AsyncScrapeClient(_Response(data=_BrokenContainsMapping()))
951+
with pytest.raises(
952+
HyperbrowserError, match="custom markdown inspect failure"
953+
) as exc_info:
954+
await WebsiteScrapeTool.async_runnable(
955+
client,
956+
{"url": "https://example.com"},
957+
)
958+
assert exc_info.value.original_error is None
959+
960+
asyncio.run(run())
961+
962+
883963
def test_async_scrape_tool_decodes_utf8_bytes_markdown_field():
884964
async def run() -> None:
885965
client = _AsyncScrapeClient(_Response(data=SimpleNamespace(markdown=b"async")))
@@ -965,6 +1045,35 @@ async def run() -> None:
9651045
asyncio.run(run())
9661046

9671047

1048+
def test_async_crawl_tool_preserves_hyperbrowser_mapping_page_inspection_failures():
1049+
class _BrokenContainsPage(Mapping[str, object]):
1050+
def __iter__(self):
1051+
yield "markdown"
1052+
1053+
def __len__(self) -> int:
1054+
return 1
1055+
1056+
def __contains__(self, key: object) -> bool:
1057+
_ = key
1058+
raise HyperbrowserError("custom page inspect failure")
1059+
1060+
def __getitem__(self, key: str) -> object:
1061+
_ = key
1062+
return "ignored"
1063+
1064+
async def run() -> None:
1065+
client = _AsyncCrawlClient(_Response(data=[_BrokenContainsPage()]))
1066+
with pytest.raises(
1067+
HyperbrowserError, match="custom page inspect failure"
1068+
) as exc_info:
1069+
await WebsiteCrawlTool.async_runnable(
1070+
client, {"url": "https://example.com"}
1071+
)
1072+
assert exc_info.value.original_error is None
1073+
1074+
asyncio.run(run())
1075+
1076+
9681077
def test_async_browser_use_tool_supports_mapping_response_data():
9691078
async def run() -> None:
9701079
client = _AsyncBrowserUseClient(

0 commit comments

Comments
 (0)