(send: Send, client: Anthropic | AsyncAnthropic, monkeypatch: pytest.MonkeyPatch)
| 724 | |
| 725 | |
| 726 | async def test_deep_nesting(send: Send, client: Anthropic | AsyncAnthropic, monkeypatch: pytest.MonkeyPatch) -> None: |
| 727 | monkeypatch.setattr(MARKERS_ATTR, MARKERS) |
| 728 | |
| 729 | # untyped JSON fields (`input_schema`, ...) can nest past the recursion limit |
| 730 | def nested(depth: int) -> object: |
| 731 | data: object = {"type": "base64", "dropped": omit, "data": SAMPLE_FILE_PATH} |
| 732 | for i in range(depth): |
| 733 | data = {"k": data} if i % 2 else (data,) |
| 734 | return data |
| 735 | |
| 736 | depth = 5 * sys.getrecursionlimit() |
| 737 | if isinstance(client, Anthropic): |
| 738 | prepared = prepare_request_data(nested(depth), location="body") |
| 739 | else: |
| 740 | prepared = await async_prepare_request_data(nested(depth), location="body") |
| 741 | for i in reversed(range(depth)): |
| 742 | prepared = prepared["k"] if i % 2 else prepared[0] |
| 743 | assert prepared == {"type": "base64", "data": SAMPLE_FILE_BASE64} |
| 744 | |
| 745 | # sent end to end from less deep only because `json` itself recurses once per level before Python 3.12 |
| 746 | depth = sys.getrecursionlimit() - 100 |
| 747 | await send({"metadata": nested(depth)}) |
| 748 | |
| 749 | assert send.request.content.endswith( |
| 750 | b'{"type":"base64","data":"SGVsbG8sIHdvcmxkIQo="}' + b"]}" * (depth // 2) + b"}" |
| 751 | ) |
| 752 | |
| 753 | |
| 754 | async def test_circular_reference(send: Send) -> None: |
nothing calls this directly
no test coverage detected