forked from AbanteAI/archive-old-cli-mentat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvision_test.py
51 lines (37 loc) · 1.57 KB
/
vision_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from unittest.mock import MagicMock, patch
import pytest
from mentat.vision.vision_manager import ScreenshotException, VisionManager
@pytest.fixture
def mock_webdriver():
with patch("selenium.webdriver.Safari") as mock:
yield mock
@pytest.fixture
def mock_platform():
with patch("platform.system") as mock:
yield mock
def test_vision_manager_screenshot(mock_platform, mock_webdriver, temp_testbed):
mock_driver_instance = MagicMock()
mock_webdriver.return_value = mock_driver_instance
mock_platform.return_value = "Darwin"
mock_driver_instance.get_screenshot_as_png.return_value = b"fake_screenshot_data"
vision_manager = VisionManager()
vision_manager._open_browser()
# Test taking a screenshot of an opened page
vision_manager.screenshot()
mock_driver_instance.get_screenshot_as_png.assert_called_once()
# Test taking a screenshot of a specific URL
test_url = "http://example.com"
vision_manager.screenshot(test_url)
mock_driver_instance.get.assert_called_with(test_url)
assert mock_driver_instance.get_screenshot_as_png.call_count == 2
# Test taking a screenshot of a local file
test_file_path = "scripts/calculator.py"
vision_manager.screenshot(test_file_path)
mock_driver_instance.get.assert_called_with(
f"file://{temp_testbed / test_file_path}"
)
assert mock_driver_instance.get_screenshot_as_png.call_count == 3
# Test exception when no browser is open
vision_manager.driver = None
with pytest.raises(ScreenshotException):
vision_manager.screenshot()