Skip to content

Commit 20f52f0

Browse files
Resolved the maintainability issues
1 parent 9bd6f91 commit 20f52f0

3 files changed

Lines changed: 20 additions & 17 deletions

File tree

src/tests/backend/common/database/test_database_base.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -493,14 +493,18 @@ async def delete_team_agent(self, team_id, agent_name): pass
493493
async def get_team_agent(self, team_id, agent_name): return None
494494

495495
database = MockDatabase()
496-
497-
with pytest.raises(ValueError):
496+
497+
exception_raised = False
498+
try:
498499
async with database:
499500
assert database.initialized is True
500501
# Raise an exception to test cleanup
501502
raise ValueError("Test exception")
503+
except ValueError:
504+
exception_raised = True
502505

503506
# Even with exception, close should have been called
507+
assert exception_raised is True
504508
assert database.closed is True
505509

506510

src/tests/backend/v4/config/test_settings.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55

66
import asyncio
77
import json
8-
import os
9-
import sys
10-
import unittest
11-
from unittest import IsolatedAsyncioTestCase
8+
from unittest import TestCase, IsolatedAsyncioTestCase, main
129
from unittest.mock import AsyncMock, Mock, patch
1310

1411
# Environment variables are set by conftest.py
@@ -23,7 +20,7 @@
2320
)
2421

2522

26-
class TestAzureConfig(unittest.TestCase):
23+
class TestAzureConfig(TestCase):
2724
"""Test cases for AzureConfig class."""
2825

2926
@patch('backend.v4.config.settings.config')
@@ -76,7 +73,7 @@ def test_ad_token_provider(self, mock_config):
7673
mock_credential.get_token.assert_called_once_with(mock_config.AZURE_COGNITIVE_SERVICES)
7774

7875

79-
class TestAzureConfigAsync(unittest.IsolatedAsyncioTestCase):
76+
class TestAzureConfigAsync(IsolatedAsyncioTestCase):
8077
"""Async test cases for AzureConfig class."""
8178

8279
@patch('backend.v4.config.settings.AzureOpenAIChatClient')
@@ -106,7 +103,7 @@ async def test_create_chat_completion_service_reasoning_model(self, mock_client_
106103
mock_client_class.assert_called_once()
107104

108105

109-
class TestMCPConfig(unittest.TestCase):
106+
class TestMCPConfig(TestCase):
110107
"""Test cases for MCPConfig class."""
111108

112109
def test_mcp_config_creation(self):
@@ -151,7 +148,7 @@ def test_get_headers_with_none_token(self):
151148
self.assertEqual(headers, {})
152149

153150

154-
class TestTeamConfig(unittest.TestCase):
151+
class TestTeamConfig(TestCase):
155152
"""Test cases for TeamConfig class."""
156153

157154
def test_team_config_creation(self):
@@ -198,7 +195,7 @@ def test_overwrite_existing_team(self):
198195
self.assertEqual(config.get_current_team(user_id), team_config2)
199196

200197

201-
class TestOrchestrationConfig(unittest.IsolatedAsyncioTestCase):
198+
class TestOrchestrationConfig(IsolatedAsyncioTestCase):
202199
"""Test cases for OrchestrationConfig class."""
203200

204201
def test_orchestration_config_creation(self):
@@ -347,9 +344,10 @@ async def cancel_task():
347344
cancel_task_handle = asyncio.create_task(cancel_task())
348345

349346
with self.assertRaises(asyncio.CancelledError):
350-
await task
347+
_ = await task
351348

352349
await cancel_task_handle
350+
self.assertTrue(cancel_task_handle.done())
353351

354352
async def test_wait_for_clarification_cancelled(self):
355353
"""Test waiting for clarification when cancelled."""
@@ -367,9 +365,10 @@ async def cancel_task():
367365
cancel_task_handle = asyncio.create_task(cancel_task())
368366

369367
with self.assertRaises(asyncio.CancelledError):
370-
await task
368+
_ = await task
371369

372370
await cancel_task_handle
371+
self.assertTrue(cancel_task_handle.done())
373372

374373
def test_cleanup_approval(self):
375374
"""Test cleanup approval."""
@@ -404,7 +403,7 @@ def test_cleanup_clarification(self):
404403
self.assertNotIn(request_id, config._clarification_events)
405404

406405

407-
class TestConnectionConfig(unittest.IsolatedAsyncioTestCase):
406+
class TestConnectionConfig(IsolatedAsyncioTestCase):
408407
"""Test cases for ConnectionConfig class."""
409408

410409
def test_connection_config_creation(self):
@@ -745,7 +744,7 @@ def test_send_status_update_sync_no_connection(self):
745744
mock_logger.warning.assert_called()
746745

747746

748-
class TestGlobalInstances(unittest.TestCase):
747+
class TestGlobalInstances(TestCase):
749748
"""Test cases for global configuration instances."""
750749

751750
def test_global_instances_exist(self):
@@ -873,4 +872,4 @@ async def approve_task():
873872

874873

875874
if __name__ == '__main__':
876-
unittest.main()
875+
main()

src/tests/backend/v4/orchestration/helper/test_plan_to_mplan_converter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
# Environment variables and paths are set by conftest.py
3030
# Import the models (conftest.py handles path setup)
31-
from backend.v4.models.models import MPlan, MStep, PlanStatus
31+
from backend.v4.models.models import MPlan, PlanStatus
3232

3333
# Import the converter
3434
from backend.v4.orchestration.helper.plan_to_mplan_converter import PlanToMPlanConverter

0 commit comments

Comments
 (0)