-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathconftest.py
More file actions
172 lines (141 loc) · 5.12 KB
/
Copy pathconftest.py
File metadata and controls
172 lines (141 loc) · 5.12 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
"""Shared pytest fixtures for e2e tests."""
import pathlib
from typing import Generator
import pytest
from typing_extensions import override
from askui import AgentSettings, ComputerAgent
from askui.locators.locators import Locator
from askui.locators.serializers import AskUiLocatorSerializer
from askui.model_providers.detection_provider import DetectionProvider
from askui.models.askui.ai_element_utils import AiElementCollection
from askui.models.askui.inference_api import (
AskUiInferenceApi,
AskUiInferenceApiSettings,
)
from askui.models.askui.locate_api import AskUiInferenceLocateApi
from askui.models.askui.locate_models import (
AskUiAiElementLocateModel,
AskUiComboLocateModel,
AskUiLocateModel,
AskUiOcrLocateModel,
AskUiPtaLocateModel,
)
from askui.models.models import LocateModel
from askui.models.shared.settings import LocateSettings
from askui.models.types.geometry import PointList
from askui.reporting import Reporter, SimpleHtmlReporter
from askui.tools.toolbox import AgentToolbox
from askui.utils.image_utils import ImageSource
class _LocateModelDetectionProvider(DetectionProvider):
"""Adapter wrapping a `LocateModel` as a `DetectionProvider` for e2e tests."""
def __init__(self, locate_model: LocateModel) -> None:
self._locate_model = locate_model
@override
def detect(
self,
locator: str | Locator,
image: ImageSource,
locate_settings: LocateSettings,
) -> PointList:
result: PointList = self._locate_model.locate(
locator=locator,
image=image,
locate_settings=locate_settings,
)
return result
def _make_locate_api(path_fixtures: pathlib.Path) -> AskUiInferenceLocateApi:
locator_serializer = AskUiLocatorSerializer(
ai_element_collection=AiElementCollection(
additional_ai_element_locations=[path_fixtures / "images"]
),
reporter=SimpleHtmlReporter(),
)
return AskUiInferenceLocateApi(
locator_serializer=locator_serializer,
inference_api=AskUiInferenceApi(settings=AskUiInferenceApiSettings()),
)
@pytest.fixture
def simple_html_reporter() -> Reporter:
return SimpleHtmlReporter()
@pytest.fixture
def askui_locate_model(path_fixtures: pathlib.Path) -> LocateModel:
return AskUiLocateModel(locate_api=_make_locate_api(path_fixtures))
@pytest.fixture
def pta_locate_model(path_fixtures: pathlib.Path) -> LocateModel:
return AskUiPtaLocateModel(locate_api=_make_locate_api(path_fixtures))
@pytest.fixture
def ocr_locate_model(path_fixtures: pathlib.Path) -> LocateModel:
return AskUiOcrLocateModel(locate_api=_make_locate_api(path_fixtures))
@pytest.fixture
def ai_element_locate_model(path_fixtures: pathlib.Path) -> LocateModel:
return AskUiAiElementLocateModel(locate_api=_make_locate_api(path_fixtures))
@pytest.fixture
def combo_locate_model(path_fixtures: pathlib.Path) -> LocateModel:
return AskUiComboLocateModel(locate_api=_make_locate_api(path_fixtures))
@pytest.fixture
def agent_with_pta_model(
pta_locate_model: LocateModel,
agent_toolbox_mock: AgentToolbox,
simple_html_reporter: Reporter,
) -> Generator[ComputerAgent, None, None]:
with ComputerAgent(
settings=AgentSettings(
detection_provider=_LocateModelDetectionProvider(pta_locate_model)
),
reporters=[simple_html_reporter],
tools=agent_toolbox_mock,
) as agent:
yield agent
@pytest.fixture
def agent_with_ocr_model(
ocr_locate_model: LocateModel,
agent_toolbox_mock: AgentToolbox,
simple_html_reporter: Reporter,
) -> Generator[ComputerAgent, None, None]:
with ComputerAgent(
settings=AgentSettings(
detection_provider=_LocateModelDetectionProvider(ocr_locate_model)
),
reporters=[simple_html_reporter],
tools=agent_toolbox_mock,
) as agent:
yield agent
@pytest.fixture
def agent_with_ai_element_model(
ai_element_locate_model: LocateModel,
agent_toolbox_mock: AgentToolbox,
simple_html_reporter: Reporter,
) -> Generator[ComputerAgent, None, None]:
with ComputerAgent(
settings=AgentSettings(
detection_provider=_LocateModelDetectionProvider(ai_element_locate_model)
),
reporters=[simple_html_reporter],
tools=agent_toolbox_mock,
) as agent:
yield agent
@pytest.fixture
def agent_with_combo_model(
combo_locate_model: LocateModel,
agent_toolbox_mock: AgentToolbox,
simple_html_reporter: Reporter,
) -> Generator[ComputerAgent, None, None]:
with ComputerAgent(
settings=AgentSettings(
detection_provider=_LocateModelDetectionProvider(combo_locate_model)
),
reporters=[simple_html_reporter],
tools=agent_toolbox_mock,
) as agent:
yield agent
@pytest.fixture
def vision_agent(
agent_toolbox_mock: AgentToolbox,
simple_html_reporter: Reporter,
) -> Generator[ComputerAgent, None, None]:
"""Fixture providing a ComputerAgent instance."""
with ComputerAgent(
reporters=[simple_html_reporter],
tools=agent_toolbox_mock,
) as agent:
yield agent