Files
ai-agent-book/chapter5/video-edit/test_extract_json_adjacent.py
T
liqiang b119135836
Build latest book artifacts / build (push) Canceled after 0s
dependency resolution / resolve (3.11) (push) Canceled after 0s
dependency resolution / resolve (3.13) (push) Canceled after 0s
deploy-pages / build (push) Canceled after 0s
deploy-pages / deploy (push) Canceled after 0s
i18n consistency check / check (push) Canceled after 0s
provider adoption tests / test (chapter2/context-compression) (push) Canceled after 0s
provider adoption tests / test (chapter2/prompt-injection) (push) Canceled after 0s
provider adoption tests / test (chapter2/system-hint) (push) Canceled after 0s
provider adoption tests / test (chapter3/log-sanitization) (push) Canceled after 0s
web-search-agent tests / test (push) Canceled after 0s
web-search-agent tests / agentbook (push) Canceled after 0s
ai-agent-book 精选快照(<2MB 代码与文档,来自 github.com/bojieli/ai-agent-book)
2026-08-20 13:12:50 +00:00

23 lines
619 B
Python

"""_extract_json must accept the first object when another object follows."""
import pytest
from agents import _extract_json
def test_adjacent_json_objects_returns_first():
assert _extract_json('{"a":1}{"b":2}') == {"a": 1}
def test_prose_with_two_objects_returns_first():
assert _extract_json('note {"a":1} mid {"b":2}') == {"a": 1}
def test_single_object_unchanged():
assert _extract_json('prefix {"ok": true, "n": 3} suffix') == {"ok": True, "n": 3}
def test_no_object_raises():
with pytest.raises(ValueError, match="未能从回复中解析 JSON"):
_extract_json("no braces here")