-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_factory.py
More file actions
74 lines (58 loc) · 2.17 KB
/
test_factory.py
File metadata and controls
74 lines (58 loc) · 2.17 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
from typing import Any, AsyncGenerator
import pytest
from uipath.runtime import (
UiPathExecuteOptions,
UiPathRuntimeEvent,
UiPathRuntimeProtocol,
UiPathRuntimeResult,
UiPathRuntimeSchema,
UiPathStreamOptions,
)
from uipath.runtime.factory import UiPathRuntimeCreatorProtocol
class MockRuntime:
"""Mock runtime that implements UiPathRuntimeProtocol."""
def __init__(self, settings: dict[str, Any] | None = None) -> None:
self.settings = settings
async def execute(
self,
input: dict[str, Any] | None = None,
options: UiPathExecuteOptions | None = None,
) -> UiPathRuntimeResult:
return UiPathRuntimeResult(output={})
async def stream(
self,
input: dict[str, Any] | None = None,
options: UiPathStreamOptions | None = None,
) -> AsyncGenerator[UiPathRuntimeEvent, None]:
yield UiPathRuntimeResult(output={})
async def get_schema(self) -> UiPathRuntimeSchema:
return UiPathRuntimeSchema(
filePath="agent.json",
type="agent",
uniqueId="unique-id",
input={},
output={},
)
async def dispose(self) -> None:
pass
class CreatorWithKwargs:
"""Implementation with kwargs."""
async def new_runtime(
self, entrypoint: str, runtime_id: str, **kwargs
) -> UiPathRuntimeProtocol:
return MockRuntime(kwargs.get("settings"))
@pytest.mark.asyncio
async def test_protocol_works_with_kwargs_not_specified():
"""Test protocol works with implementation that has kwargs."""
creator: UiPathRuntimeCreatorProtocol = CreatorWithKwargs()
runtime = await creator.new_runtime("main.py", "runtime-123")
assert isinstance(runtime, MockRuntime)
@pytest.mark.asyncio
async def test_protocol_works_with_kwargs_specified():
"""Test protocol works with implementation that has kwargs."""
creator: UiPathRuntimeCreatorProtocol = CreatorWithKwargs()
runtime = await creator.new_runtime(
"main.py", "runtime-123", settings={"timeout": 30, "model": "gpt-4"}
)
assert isinstance(runtime, MockRuntime)
assert runtime.settings == {"timeout": 30, "model": "gpt-4"}