mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
Python: Achieve 85%+ unit test coverage for azurefunctions package (#3866)
* Initial plan * Initial analysis: azurefunctions package at 80% coverage, need 85% Co-authored-by: larohra <41490930+larohra@users.noreply.github.com> * Add comprehensive unit tests to achieve 86% coverage for azurefunctions package Co-authored-by: larohra <41490930+larohra@users.noreply.github.com> * Add comprehensive coverage report documentation for azurefunctions package Co-authored-by: larohra <41490930+larohra@users.noreply.github.com> * Fix linting errors: combine nested with statements in test_entities.py Co-authored-by: larohra <41490930+larohra@users.noreply.github.com> * Remove COVERAGE_REPORT.md and coverage.json files as requested Co-authored-by: larohra <41490930+larohra@users.noreply.github.com> * Address PR review feedback: fix unused variables, remove line numbers from docstrings, improve test clarity Co-authored-by: larohra <41490930+larohra@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: larohra <41490930+larohra@users.noreply.github.com> Co-authored-by: Laveesh Rohra <larohra@microsoft.com> Co-authored-by: Tao Chen <taochen@microsoft.com>
This commit is contained in:
co-authored by
larohra
copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Laveesh Rohra
Tao Chen
parent
e563849be3
commit
cd1e3110aa
@@ -129,6 +129,25 @@ def executor_with_context(mock_context_with_uuid: tuple[Mock, str]) -> tuple[Any
|
||||
class TestAgentResponseHelpers:
|
||||
"""Tests for response handling through public AgentTask API."""
|
||||
|
||||
def test_try_set_value_exception_handling(self) -> None:
|
||||
"""Test try_set_value handles exceptions raised when converting a successful task result to AgentResponse."""
|
||||
entity_task = _create_entity_task()
|
||||
task = AgentTask(entity_task, None, "correlation-id")
|
||||
|
||||
# Simulate successful entity task with invalid result that causes exception
|
||||
entity_task.state = TaskState.SUCCEEDED
|
||||
entity_task.result = {"invalid": "format"} # Missing required fields for AgentResponse
|
||||
|
||||
# Clear pending_tasks to simulate that parent has processed the child
|
||||
task.pending_tasks.clear()
|
||||
|
||||
# Call try_set_value - should catch exception and set error
|
||||
task.try_set_value(entity_task)
|
||||
|
||||
# Verify task failed due to conversion exception
|
||||
assert task.state == TaskState.FAILED
|
||||
assert isinstance(task.result, Exception)
|
||||
|
||||
def test_try_set_value_success(self) -> None:
|
||||
"""Test try_set_value correctly processes successful task completion."""
|
||||
entity_task = _create_entity_task()
|
||||
@@ -279,6 +298,27 @@ class TestAzureFunctionsFireAndForget:
|
||||
assert isinstance(result, AgentTask)
|
||||
|
||||
|
||||
class TestAzureFunctionsAgentExecutor:
|
||||
"""Tests for AzureFunctionsAgentExecutor."""
|
||||
|
||||
def test_generate_unique_id(self, mock_context_with_uuid: tuple[Mock, str]) -> None:
|
||||
"""Test generate_unique_id method returns UUID from orchestration context."""
|
||||
from agent_framework_azurefunctions._orchestration import AzureFunctionsAgentExecutor
|
||||
|
||||
context, _ = mock_context_with_uuid
|
||||
executor = AzureFunctionsAgentExecutor(context)
|
||||
|
||||
# Call generate_unique_id
|
||||
unique_id = executor.generate_unique_id()
|
||||
|
||||
# Verify it returns the UUID from context (as string with dashes)
|
||||
# The UUID is returned in standard format with dashes
|
||||
context.new_uuid.assert_called_once()
|
||||
# Just verify it's a string representation of UUID
|
||||
assert isinstance(unique_id, str)
|
||||
assert len(unique_id) > 0
|
||||
|
||||
|
||||
class TestOrchestrationIntegration:
|
||||
"""Integration tests for orchestration scenarios."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user