mirror of
https://github.com/zap-proto/spec.git
synced 2026-10-30 15:04:03 +00:00
Add test_client/test_gateway/test_server and extend test_config to exercise the async stub modules (connect/list/call, add/remove/list servers, run() startup) and Config.load + non-Darwin default_path. Lifts total coverage 85% -> 91%, giving the 80% gate real headroom across the 3.10/3.11/3.12 matrix. Ignore .coverage/coverage.xml so build artifacts stay out of the tree. 129 passed; client/config/gateway/server at 100%, identity 92%, crypto 82%.
70 lines
2.4 KiB
Python
70 lines
2.4 KiB
Python
"""Tests for zap_schema.client module."""
|
|
|
|
import pytest
|
|
|
|
from zap_schema.client import Client, Resource, ResourceContent, Tool
|
|
from zap_schema.error import ZapError
|
|
|
|
|
|
class TestDataclasses:
|
|
def test_tool(self):
|
|
t = Tool(name="search", description="d", schema={"type": "object"})
|
|
assert t.name == "search"
|
|
assert t.schema["type"] == "object"
|
|
|
|
def test_resource(self):
|
|
r = Resource(uri="zap://r", name="r", description="d", mime_type="text/plain")
|
|
assert r.uri == "zap://r"
|
|
|
|
def test_resource_content(self):
|
|
c = ResourceContent(uri="zap://r", mime_type="text/plain", content="hi")
|
|
assert c.content == "hi"
|
|
|
|
|
|
class TestClientConnected:
|
|
async def test_connect_sets_state(self):
|
|
client = await Client.connect("zap://localhost:9999")
|
|
assert client.url == "zap://localhost:9999"
|
|
assert client._connected is True
|
|
|
|
async def test_list_tools_empty(self):
|
|
client = await Client.connect("zap://x")
|
|
assert await client.list_tools() == []
|
|
|
|
async def test_call_tool_returns_none(self):
|
|
client = await Client.connect("zap://x")
|
|
assert await client.call_tool("search", {"q": "hi"}) is None
|
|
|
|
async def test_list_resources_empty(self):
|
|
client = await Client.connect("zap://x")
|
|
assert await client.list_resources() == []
|
|
|
|
async def test_read_resource(self):
|
|
client = await Client.connect("zap://x")
|
|
content = await client.read_resource("zap://res")
|
|
assert isinstance(content, ResourceContent)
|
|
assert content.uri == "zap://res"
|
|
|
|
async def test_close_clears_state(self):
|
|
client = await Client.connect("zap://x")
|
|
await client.close()
|
|
assert client._connected is False
|
|
|
|
|
|
class TestClientNotConnected:
|
|
async def test_list_tools_raises(self):
|
|
with pytest.raises(ZapError, match="Not connected"):
|
|
await Client("zap://x").list_tools()
|
|
|
|
async def test_call_tool_raises(self):
|
|
with pytest.raises(ZapError, match="Not connected"):
|
|
await Client("zap://x").call_tool("t", {})
|
|
|
|
async def test_list_resources_raises(self):
|
|
with pytest.raises(ZapError, match="Not connected"):
|
|
await Client("zap://x").list_resources()
|
|
|
|
async def test_read_resource_raises(self):
|
|
with pytest.raises(ZapError, match="Not connected"):
|
|
await Client("zap://x").read_resource("zap://r")
|