Hy3 / tests /test_display.py
ericsqin's picture
add hy3
ad51766
Raw
History Blame Contribute Delete
1.59 kB
"""Unit tests for display helpers."""
import json
from display import (
build_display_content,
format_tool_call_prompt,
format_tool_calls_for_display,
)
def test_build_display_content_empty():
assert build_display_content("", "") == ""
def test_build_display_content_only_content():
assert build_display_content("", "hello") == "hello"
def test_build_display_content_streaming_reasoning_open():
"""While content is empty the thinking block should be open."""
out = build_display_content("step 1...", "")
assert "<details" in out
assert " open>" in out
assert "Thinking..." in out
assert "step 1..." in out
def test_build_display_content_completed_reasoning_collapsed():
out = build_display_content("step 1...", "final answer")
assert "Thinking complete" in out
assert " open>" not in out
assert "final answer" in out
def test_format_single_tool_call_dict():
tc = {
"id": "call_1",
"type": "function",
"function": {"name": "ping", "arguments": json.dumps({"x": 1})},
}
out = format_tool_calls_for_display([tc])
assert "ping" in out
assert '"x": 1' in out
def test_format_single_tool_call_invalid_args_kept_raw():
tc = {"function": {"name": "ping", "arguments": "{not json"}}
out = format_tool_calls_for_display([tc])
assert "{not json" in out
def test_format_tool_call_prompt_header():
tc = {"function": {"name": "ping", "arguments": "{}"}}
out = format_tool_call_prompt(tc, 2, 5)
assert "Function call (2/5)" in out
assert "ping" in out