Skip to content
Merged
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 packages/uipath/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "uipath"
version = "2.10.52"
version = "2.10.53"
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
7 changes: 6 additions & 1 deletion packages/uipath/src/uipath/eval/mocks/_llm_mocker.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,16 @@ def __init__(self, context: MockingContext):

@traced(name="__mocker__", recording=False)
async def response(
self, func: Callable[[T], R], params: dict[str, Any], *args: T, **kwargs
self,
func: Callable[[T], R],
params: dict[str, Any],
invocation: tuple[tuple[Any, ...], dict[str, Any]],
) -> R:
"""Respond with mocked response generated by an LLM."""
assert isinstance(self.context.strategy, LLMMockingStrategy)

args, kwargs = invocation

function_name = params.get("name") or func.__name__
if function_name in [x.name for x in self.context.strategy.tools_to_simulate]:
uipath = UiPath()
Expand Down
6 changes: 4 additions & 2 deletions packages/uipath/src/uipath/eval/mocks/_mock_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,13 @@ def is_tool_simulated(tool_name: str) -> bool:


async def get_mocked_response(
func: Callable[[Any], Any], params: dict[str, Any], *args, **kwargs
func: Callable[[Any], Any],
params: dict[str, Any],
invocation: tuple[tuple[Any, ...], dict[str, Any]],
) -> Any:
"""Get a mocked response."""
mocker = mocker_context.get()
if mocker is None:
raise UiPathNoMockFoundError()
else:
return await mocker.response(func, params, *args, **kwargs)
return await mocker.response(func, params, invocation)
3 changes: 1 addition & 2 deletions packages/uipath/src/uipath/eval/mocks/_mocker.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ async def response(
self,
func: Callable[[T], R],
params: dict[str, Any],
*args: T,
**kwargs,
invocation: tuple[tuple[Any, ...], dict[str, Any]],
) -> R:
"""Respond with mocked response."""
raise NotImplementedError()
Expand Down
7 changes: 6 additions & 1 deletion packages/uipath/src/uipath/eval/mocks/_mockito_mocker.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,17 @@ def __init__(self, context: MockingContext):
stubbed = stubbed.thenRaise(_resolve_value(answer_dict["value"]))

async def response(
self, func: Callable[[T], R], params: dict[str, Any], *args: T, **kwargs
self,
func: Callable[[T], R],
params: dict[str, Any],
invocation: tuple[tuple[Any, ...], dict[str, Any]],
) -> R:
"""Return mocked response or raise appropriate errors."""
if not isinstance(self.context.strategy, MockitoMockingStrategy):
raise UiPathMockResponseGenerationError("Mocking strategy misconfigured.")

args, kwargs = invocation

# No behavior configured → call real function
is_mocked = any(
behavior.function == params["name"]
Expand Down
2 changes: 1 addition & 1 deletion packages/uipath/src/uipath/eval/mocks/mockable.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def mocked_response_decorator(func, params: dict[str, Any]):
"""Mocked response decorator."""

async def mock_response_generator(*args, **kwargs):
mocked_response = await get_mocked_response(func, params, *args, **kwargs)
mocked_response = await get_mocked_response(func, params, (args, kwargs))

# Mocking successful.
context = UiPathSpanUtils.get_parent_context()
Expand Down
107 changes: 107 additions & 0 deletions packages/uipath/tests/cli/eval/mocks/test_mockable_arg_collision.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
"""Regression tests: @mockable must not collide with user args named `func`/`params`."""

from typing import Any
from unittest.mock import MagicMock, patch

import pytest

from uipath.eval.mocks import mockable
from uipath.eval.mocks._mock_runtime import (
clear_execution_context,
set_execution_context,
)
from uipath.eval.mocks._types import MockingContext
from uipath.eval.models.evaluation_set import EvaluationItem

_mock_span_collector = MagicMock()


def _build_evaluation(
function_name: str, kwargs: dict[str, Any], value: Any
) -> EvaluationItem:
evaluation_item: dict[str, Any] = {
"id": "evaluation-id",
"name": "Test evaluation",
"inputs": {},
"evaluationCriterias": {"ExactMatchEvaluator": None},
"mockingStrategy": {
"type": "mockito",
"behaviors": [
{
"function": function_name,
"arguments": {"args": [], "kwargs": kwargs},
"then": [{"type": "return", "value": value}],
}
],
},
}
return EvaluationItem(**evaluation_item)


class TestMockableArgCollision:
"""Ensure `@mockable` works when the wrapped function has args named `func` or `params`."""

def test_sync_function_with_func_and_params_args(self):
"""A sync mockable function that takes `func` and `params` kwargs should not raise."""

@mockable()
def test_function(func: str, params: dict[str, Any]) -> str:
raise NotImplementedError()

evaluation = _build_evaluation(
"test_function",
kwargs={"func": "some_func", "params": {"k": "v"}},
value="mocked_result",
)

set_execution_context(
MockingContext(
strategy=evaluation.mocking_strategy,
name=evaluation.name,
inputs=evaluation.inputs,
),
_mock_span_collector,
"test-execution-id",
)

try:
with patch("uipath.eval.mocks.mockable.UiPathSpanUtils"):
with patch("uipath.eval.mocks.mockable.trace"):
result = test_function(func="some_func", params={"k": "v"})

assert result == "mocked_result"
finally:
clear_execution_context()

@pytest.mark.asyncio
async def test_async_function_with_func_and_params_args(self):
"""An async mockable function that takes `func` and `params` kwargs should not raise."""

@mockable()
async def test_function(func: str, params: dict[str, Any]) -> str:
raise NotImplementedError()

evaluation = _build_evaluation(
"test_function",
kwargs={"func": "some_func", "params": {"k": "v"}},
value="mocked_result",
)

set_execution_context(
MockingContext(
strategy=evaluation.mocking_strategy,
name=evaluation.name,
inputs=evaluation.inputs,
),
_mock_span_collector,
"test-execution-id",
)

try:
with patch("uipath.eval.mocks.mockable.UiPathSpanUtils"):
with patch("uipath.eval.mocks.mockable.trace"):
result = await test_function(func="some_func", params={"k": "v"})

assert result == "mocked_result"
finally:
clear_execution_context()
2 changes: 1 addition & 1 deletion packages/uipath/uv.lock

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

Loading