加入匠厂桌面测试

This commit is contained in:
2026-04-20 13:40:53 +08:00
parent 71a9ab1700
commit 2174b2b573
6 changed files with 713 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
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)