Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "uipath"
version = "2.2.33"
version = "2.2.34"
description = "Python SDK and CLI for UiPath Platform, enabling programmatic interaction with automation services, process management, and deployment tools."
readme = { file = "README.md", content-type = "text/markdown" }
requires-python = ">=3.11"
Expand Down
6 changes: 6 additions & 0 deletions src/uipath/_cli/_evals/_models/_evaluation_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ class InputMockingStrategy(BaseModel):
class MockingArgument(BaseModel):
args: list[Any] = Field(default_factory=lambda: [], alias="args")
kwargs: dict[str, Any] = Field(default_factory=lambda: {}, alias="kwargs")
match_any_additional_args: bool = Field(
default=False, alias="matchAnyAdditionalArgs"
)
match_any_additional_kwargs: bool = Field(
default=False, alias="matchAnyAdditionalKwargs"
)


class MockingAnswerType(str, Enum):
Expand Down
7 changes: 7 additions & 0 deletions src/uipath/_cli/_evals/mocks/mockito_mocker.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from typing import Any, Callable

from mockito import ( # type: ignore[import-untyped] # explicit ignore
ARGS,
KWARGS,
invocation,
mocking,
)
Expand Down Expand Up @@ -78,6 +80,11 @@ def __init__(self, evaluation_item: EvaluationItem):
args = resolved_args if resolved_args is not None else []
kwargs = resolved_kwargs if resolved_kwargs is not None else {}

if behavior.arguments.match_any_additional_kwargs:
kwargs = kwargs | KWARGS
if behavior.arguments.match_any_additional_args:
args = args + ARGS

stubbed = invocation.StubbedInvocation(mock_obj, behavior.function)(
*args,
**kwargs,
Expand Down
85 changes: 85 additions & 0 deletions tests/cli/eval/mocks/test_mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,91 @@ async def foofoo(*args, **kwargs):
assert await foo(x=2) == "bar1"


def test_mockito_mockable_anyargs_sync():
# Arrange
@mockable()
def foo(*args, **kwargs):
raise NotImplementedError()

evaluation_item: dict[str, Any] = {
"id": "evaluation-id",
"name": "Mock foo",
"inputs": {},
"evaluationCriterias": {
"ExactMatchEvaluator": None,
},
"mockingStrategy": {
"type": "mockito",
"behaviors": [
{
"function": "foo",
"arguments": {
"args": [],
"kwargs": {},
"matchAnyAdditionalArgs": True,
"matchAnyAdditionalKwargs": True,
},
"then": [
{"type": "return", "value": "bar1"},
],
}
],
},
}
evaluation = EvaluationItem(**evaluation_item)
assert isinstance(evaluation.mocking_strategy, MockitoMockingStrategy)

# Act & Assert
set_execution_context(evaluation, _mock_span_collector, "test-execution-id")
assert foo(x=1) == "bar1"
assert foo(x="x") == "bar1"
assert foo() == "bar1"
assert foo(1) == "bar1"


@pytest.mark.asyncio
async def test_mockito_mockable_anyargs_async():
# Arrange
@mockable()
async def foo(*args, **kwargs):
raise NotImplementedError()

evaluation_item: dict[str, Any] = {
"id": "evaluation-id",
"name": "Mock foo",
"inputs": {},
"evaluationCriterias": {
"ExactMatchEvaluator": None,
},
"mockingStrategy": {
"type": "mockito",
"behaviors": [
{
"function": "foo",
"arguments": {
"args": [],
"kwargs": {},
"matchAnyAdditionalArgs": True,
"matchAnyAdditionalKwargs": True,
},
"then": [
{"type": "return", "value": "bar1"},
],
}
],
},
}
evaluation = EvaluationItem(**evaluation_item)
assert isinstance(evaluation.mocking_strategy, MockitoMockingStrategy)

# Act & Assert
set_execution_context(evaluation, _mock_span_collector, "test-execution-id")
assert await foo(x=1) == "bar1"
assert await foo(x="x") == "bar1"
assert await foo() == "bar1"
assert await foo(1) == "bar1"


@pytest.mark.httpx_mock(assert_all_responses_were_requested=False)
def test_llm_mockable_sync(httpx_mock: HTTPXMock, monkeypatch: MonkeyPatch):
monkeypatch.setenv("UIPATH_URL", "https://example.com")
Expand Down
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.