Files
2026-04-20 13:40:53 +08:00

37 lines
1.6 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import pytest
from jiangchang_desktop_sdk import JiangchangDesktopClient, JiangchangMessage, AskOptions, LaunchOptions, AssertOptions
from jiangchang_desktop_sdk.exceptions import JiangchangDesktopError, AppNotFoundError, ConnectionError, TimeoutError, AssertError
def test_client_init():
"""实例化 JiangchangDesktopClient验证 _connected = False"""
client = JiangchangDesktopClient()
assert client._connected is False
assert client._browser is None
assert client._page is None
def test_types_dataclasses():
"""验证 JiangchangMessage, AskOptions 等 dataclass 可以正常实例化"""
msg = JiangchangMessage(id="1", role="user", content="hello", timestamp=123.456)
assert msg.id == "1"
assert msg.role == "user"
ask_opts = AskOptions(timeout=1000)
assert ask_opts.timeout == 1000
launch_opts = LaunchOptions(headless=True)
assert launch_opts.headless is True
assert_opts = AssertOptions(match_mode="exact")
assert assert_opts.match_mode == "exact"
def test_exceptions_are_exceptions():
"""验证所有异常类都是 Exception 的子类"""
assert issubclass(JiangchangDesktopError, Exception)
assert issubclass(AppNotFoundError, JiangchangDesktopError)
assert issubclass(ConnectionError, JiangchangDesktopError)
assert issubclass(ConnectionError, ConnectionError)
assert issubclass(TimeoutError, JiangchangDesktopError)
# Note: in Python 3.10+, TimeoutError is a built-in.
# Our definition: class TimeoutError(JiangchangDesktopError, TimeoutError):
assert issubclass(AssertError, JiangchangDesktopError)