Skip to content

Commit 26ea3b7

Browse files
author
SentienceDEV
committed
fix tests
1 parent 3141f86 commit 26ea3b7

File tree

2 files changed

+36
-8
lines changed

2 files changed

+36
-8
lines changed

tests/unit/test_extract.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ def model_name(self) -> str:
2424
return "stub"
2525

2626

27-
class BrowserStub:
28-
page = True
29-
27+
class PageStub:
3028
def __init__(self, content: str):
3129
self._content = content
3230

@@ -40,6 +38,30 @@ def evaluate(self, _script: str, _opts: dict):
4038
}
4139

4240

41+
class AsyncPageStub:
42+
def __init__(self, content: str):
43+
self._content = content
44+
45+
async def evaluate(self, _script: str, _opts: dict):
46+
return {
47+
"status": "success",
48+
"url": "https://example.com",
49+
"format": "markdown",
50+
"content": self._content,
51+
"length": len(self._content),
52+
}
53+
54+
55+
class BrowserStub:
56+
def __init__(self, content: str):
57+
self.page = PageStub(content)
58+
59+
60+
class AsyncBrowserStub:
61+
def __init__(self, content: str):
62+
self.page = AsyncPageStub(content)
63+
64+
4365
class ItemSchema(BaseModel):
4466
name: str
4567
price: str
@@ -64,7 +86,7 @@ def test_extract_schema_invalid_json() -> None:
6486

6587
@pytest.mark.asyncio
6688
async def test_extract_async_schema_success() -> None:
67-
browser = BrowserStub("Product: Widget")
89+
browser = AsyncBrowserStub("Product: Widget")
6890
llm = LLMStub('{"name":"Widget","price":"$10"}')
6991
from sentience.read import extract_async
7092

tests/unit/test_tool_registry.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@
33
import pytest
44
from pydantic import BaseModel, ValidationError
55

6-
from sentience.tools import ToolContext, ToolRegistry, ToolSpec, register_default_tools
6+
from sentience.tools import (
7+
ToolContext,
8+
ToolRegistry,
9+
ToolSpec,
10+
UnsupportedCapabilityError,
11+
register_default_tools,
12+
)
713

814

915
class EchoInput(BaseModel):
@@ -143,7 +149,7 @@ def can(self, _name: str) -> bool:
143149
return False
144150

145151
ctx = ToolContext(RuntimeStub())
146-
with pytest.raises(ValueError, match="unsupported_capability"):
152+
with pytest.raises(UnsupportedCapabilityError, match="unsupported_capability"):
147153
ctx.require("tabs")
148154

149155

@@ -213,10 +219,10 @@ async def snapshot(self, **_kwargs):
213219
ctx = ToolContext(RuntimeStub())
214220
register_default_tools(registry, ctx)
215221

216-
with pytest.raises(ValueError, match="unsupported_capability"):
222+
with pytest.raises(UnsupportedCapabilityError, match="unsupported_capability"):
217223
await registry.execute("press", {"key": "Enter"}, ctx=ctx)
218224

219-
with pytest.raises(ValueError, match="unsupported_capability"):
225+
with pytest.raises(UnsupportedCapabilityError, match="unsupported_capability"):
220226
await registry.execute(
221227
"scroll_to_element",
222228
{"element_id": 1, "behavior": "instant", "block": "center"},

0 commit comments

Comments
 (0)