Skip to content

Commit 4475f7e

Browse files
committed
cleaning up some unit tests
1 parent 8ed42e9 commit 4475f7e

12 files changed

+14
-3768
lines changed

tests/performance/test_performance.py

Lines changed: 1 addition & 495 deletions
Large diffs are not rendered by default.

tests/unit/agent/test_agent_system.py

Lines changed: 0 additions & 785 deletions
This file was deleted.

tests/unit/core/test_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from stagehand.config import StagehandConfig, default_config
88

9-
9+
# TODO: need to update after config-constructor refactor
1010
class TestStagehandConfig:
1111
"""Test StagehandConfig creation and validation"""
1212

tests/unit/core/test_page.py

Lines changed: 1 addition & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -256,30 +256,6 @@ async def test_act_with_options_browserbase(self, mock_stagehand_page):
256256
}
257257
)
258258
assert isinstance(result, ActResult)
259-
260-
@pytest.mark.asyncio
261-
async def test_act_ignores_kwargs_with_observe_result(self, mock_stagehand_page):
262-
"""Test that kwargs are ignored when using ObserveResult"""
263-
mock_stagehand_page._stagehand.env = "LOCAL"
264-
265-
observe_result = ObserveResult(
266-
selector="#test",
267-
description="test",
268-
method="click"
269-
)
270-
271-
mock_act_handler = MagicMock()
272-
mock_act_handler.act = AsyncMock(return_value=ActResult(
273-
success=True,
274-
message="Done",
275-
action="click"
276-
))
277-
mock_stagehand_page._act_handler = mock_act_handler
278-
279-
# Should warn about ignored kwargs
280-
await mock_stagehand_page.act(observe_result, model_name="ignored")
281-
282-
mock_stagehand_page._stagehand.logger.warning.assert_called()
283259

284260

285261
class TestObserveFunctionality:
@@ -311,26 +287,6 @@ async def test_observe_with_string_instruction_local(self, mock_stagehand_page):
311287
assert result[0].selector == "#submit-btn"
312288
mock_observe_handler.observe.assert_called_once()
313289

314-
@pytest.mark.asyncio
315-
async def test_observe_with_options_object(self, mock_stagehand_page):
316-
"""Test observe() with ObserveOptions object"""
317-
mock_stagehand_page._stagehand.env = "LOCAL"
318-
319-
options = ObserveOptions(
320-
instruction="find buttons",
321-
only_visible=True,
322-
return_action=True
323-
)
324-
325-
mock_observe_handler = MagicMock()
326-
mock_observe_handler.observe = AsyncMock(return_value=[])
327-
mock_stagehand_page._observe_handler = mock_observe_handler
328-
329-
result = await mock_stagehand_page.observe(options)
330-
331-
assert isinstance(result, list)
332-
mock_observe_handler.observe.assert_called_with(options, from_act=False)
333-
334290
@pytest.mark.asyncio
335291
async def test_observe_browserbase_mode(self, mock_stagehand_page):
336292
"""Test observe() in BROWSERBASE mode"""
@@ -352,23 +308,6 @@ async def test_observe_browserbase_mode(self, mock_stagehand_page):
352308
assert len(result) == 1
353309
assert isinstance(result[0], ObserveResult)
354310
assert result[0].selector == "#test-btn"
355-
356-
@pytest.mark.asyncio
357-
async def test_observe_with_none_options(self, mock_stagehand_page):
358-
"""Test observe() with None options"""
359-
mock_stagehand_page._stagehand.env = "LOCAL"
360-
361-
mock_observe_handler = MagicMock()
362-
mock_observe_handler.observe = AsyncMock(return_value=[])
363-
mock_stagehand_page._observe_handler = mock_observe_handler
364-
365-
# This test should pass a default instruction instead of None
366-
result = await mock_stagehand_page.observe("default instruction")
367-
368-
assert isinstance(result, list)
369-
# Should create ObserveOptions with the instruction
370-
call_args = mock_observe_handler.observe.call_args[0][0]
371-
assert isinstance(call_args, ObserveOptions)
372311

373312

374313
class TestExtractFunctionality:
@@ -421,34 +360,7 @@ class ProductSchema(BaseModel):
421360
assert isinstance(call_args[0][0], ExtractOptions) # First argument should be ExtractOptions
422361
assert call_args[0][1] == ProductSchema # Second argument should be the Pydantic model
423362

424-
@pytest.mark.asyncio
425-
async def test_extract_with_dict_schema(self, mock_stagehand_page):
426-
"""Test extract() with dictionary schema"""
427-
mock_stagehand_page._stagehand.env = "LOCAL"
428-
429-
schema = {
430-
"type": "object",
431-
"properties": {
432-
"title": {"type": "string"},
433-
"content": {"type": "string"}
434-
}
435-
}
436-
437-
options = ExtractOptions(
438-
instruction="extract content",
439-
schema_definition=schema
440-
)
441-
442-
mock_extract_handler = MagicMock()
443-
mock_extract_result = MagicMock()
444-
mock_extract_result.data = {"title": "Test", "content": "Test content"}
445-
mock_extract_handler.extract = AsyncMock(return_value=mock_extract_result)
446-
mock_stagehand_page._extract_handler = mock_extract_handler
447-
448-
result = await mock_stagehand_page.extract(options)
449-
450-
assert result == {"title": "Test", "content": "Test content"}
451-
363+
452364
@pytest.mark.asyncio
453365
async def test_extract_with_none_options(self, mock_stagehand_page):
454366
"""Test extract() with None options (extract entire page)"""
@@ -490,16 +402,6 @@ async def test_extract_browserbase_mode(self, mock_stagehand_page):
490402
class TestScreenshotFunctionality:
491403
"""Test screenshot functionality"""
492404

493-
@pytest.mark.asyncio
494-
async def test_screenshot_local_mode_not_implemented(self, mock_stagehand_page):
495-
"""Test that screenshot in LOCAL mode shows warning"""
496-
mock_stagehand_page._stagehand.env = "LOCAL"
497-
498-
result = await mock_stagehand_page.screenshot()
499-
500-
assert result is None
501-
mock_stagehand_page._stagehand.logger.warning.assert_called()
502-
503405
@pytest.mark.asyncio
504406
async def test_screenshot_browserbase_mode(self, mock_stagehand_page):
505407
"""Test screenshot in BROWSERBASE mode"""
@@ -636,58 +538,3 @@ async def test_wait_for_settled_dom_error_handling(self, mock_stagehand_page):
636538
# If we get here, it means the method handled the exception gracefully
637539
except Exception:
638540
pytest.fail("_wait_for_settled_dom should handle exceptions gracefully")
639-
640-
641-
class TestPageIntegration:
642-
"""Test page integration workflows"""
643-
644-
@pytest.mark.asyncio
645-
async def test_observe_then_act_workflow(self, mock_stagehand_page):
646-
"""Test workflow of observing then acting on results"""
647-
mock_stagehand_page._stagehand.env = "LOCAL"
648-
649-
# Mock observe handler
650-
mock_observe_handler = MagicMock()
651-
observe_result = ObserveResult(
652-
selector="#button",
653-
description="Test button",
654-
method="click",
655-
arguments=[]
656-
)
657-
mock_observe_handler.observe = AsyncMock(return_value=[observe_result])
658-
mock_stagehand_page._observe_handler = mock_observe_handler
659-
660-
# Mock act handler
661-
mock_act_handler = MagicMock()
662-
mock_act_handler.act = AsyncMock(return_value=ActResult(
663-
success=True,
664-
message="Button clicked",
665-
action="click"
666-
))
667-
mock_stagehand_page._act_handler = mock_act_handler
668-
669-
# Test workflow
670-
observe_results = await mock_stagehand_page.observe("find a button")
671-
assert len(observe_results) == 1
672-
673-
act_result = await mock_stagehand_page.act(observe_results[0])
674-
assert act_result.success is True
675-
676-
@pytest.mark.asyncio
677-
async def test_navigation_then_extraction_workflow(self, mock_stagehand_page, sample_html_content):
678-
"""Test workflow of navigation then data extraction"""
679-
mock_stagehand_page._stagehand.env = "LOCAL"
680-
681-
# Mock extract handler
682-
mock_extract_handler = MagicMock()
683-
mock_extract_result = MagicMock()
684-
mock_extract_result.data = {"title": "Sample Post Title"}
685-
mock_extract_handler.extract = AsyncMock(return_value=mock_extract_result)
686-
mock_stagehand_page._extract_handler = mock_extract_handler
687-
688-
# Test navigation
689-
await mock_stagehand_page.goto("https://example.com")
690-
691-
# Test extraction
692-
result = await mock_stagehand_page.extract("extract the title")
693-
assert result == {"title": "Sample Post Title"}

0 commit comments

Comments
 (0)