π OpenHands: AI-Driven Development
PLTF-1269: add docstrings to mock classes in maintenance runner tests (#13931)
aivong-openhandse23af62a576d
diff --git a/enterprise/tests/unit/test_maintenance_task_runner_standalone.py b/enterprise/tests/unit/test_maintenance_task_runner_standalone.pyindex 6de9a2dcf1..de43ae39e4 100644--- a/enterprise/tests/unit/test_maintenance_task_runner_standalone.py+++ b/enterprise/tests/unit/test_maintenance_task_runner_standalone.py@@ -24,6 +24,8 @@ class TestMaintenanceTaskRunnerStandalone:# Mock the runner class structureclass MockMaintenanceTaskRunner:+ """Minimal mock of MaintenanceTaskRunner to verify initialization state."""+def __init__(self):self._running = Falseself._task = None@@ -38,6 +40,8 @@ class TestMaintenanceTaskRunnerStandalone:# Mock the runner behaviorclass MockMaintenanceTaskRunner:+ """Mock runner for verifying start/stop lifecycle behaviour."""+def __init__(self):self._running: bool = Falseself._task = None@@ -45,6 +49,7 @@ class TestMaintenanceTaskRunnerStandalone:self.stop_called = Falseasync def start(self):+ """Start the runner."""if self._running:returnself._running = True@@ -52,6 +57,7 @@ class TestMaintenanceTaskRunnerStandalone:self.start_called = Trueasync def stop(self):+ """Stop the runner."""if not self._running:returnself._running = False@@ -90,12 +96,15 @@ class TestMaintenanceTaskRunnerStandalone:# Mock the run loop logicclass MockMaintenanceTaskRunner:+ """Mock runner for verifying run loop iteration behaviour."""+def __init__(self):self._running = Falseself.process_calls = 0self.sleep_calls = 0async def _run_loop(self):+ """Execute the main processing loop."""loop_count = 0while self._running and loop_count < 3: # Limit for testingtry:@@ -113,6 +122,7 @@ class TestMaintenanceTaskRunnerStandalone:loop_count += 1async def _process_pending_tasks(self):+ """Process pending tasks."""# Mock processingpass@@ -131,6 +141,8 @@ class TestMaintenanceTaskRunnerStandalone:"""Test error handling in the run loop."""class MockMaintenanceTaskRunner:+ """Mock runner for verifying error handling in the run loop."""+def __init__(self):self._running = Falseself.error_count = 0@@ -138,6 +150,7 @@ class TestMaintenanceTaskRunnerStandalone:self.attempt_count = 0async def _run_loop(self):+ """Execute the main processing loop."""loop_count = 0while self._running and loop_count < 2: # Limit for testingtry:@@ -155,6 +168,7 @@ class TestMaintenanceTaskRunnerStandalone:loop_count += 1async def _process_pending_tasks(self):+ """Process pending tasks."""self.attempt_count += 1# Only fail on the first attemptif self.attempt_count == 1:@@ -231,6 +245,8 @@ class TestMaintenanceTaskRunnerStandalone:# Mock task processing logicclass MockTask:+ """Mock task for successful processing scenarios."""+def __init__(self, task_id, processor_type):self.id = task_idself.processor_type = processor_type@@ -239,17 +255,21 @@ class TestMaintenanceTaskRunnerStandalone:self.updated_at = Nonedef get_processor(self):+ """Return a mock processor."""# Mock processorprocessor = AsyncMock()processor.return_value = {'result': 'success', 'processed_items': 5}return processorclass MockMaintenanceTaskRunner:+ """Mock runner for verifying task status transitions on success."""+def __init__(self):self.status_updates = []self.commits = []async def _process_task(self, task):+ """Process a single task."""# Simulate updating status to WORKINGtask.status = 'WORKING'task.updated_at = datetime.now()@@ -297,6 +317,8 @@ class TestMaintenanceTaskRunnerStandalone:"""Test task processing with failure."""class MockTask:+ """Mock task for failure processing scenarios."""+def __init__(self, task_id, processor_type):self.id = task_idself.processor_type = processor_type@@ -305,17 +327,21 @@ class TestMaintenanceTaskRunnerStandalone:self.updated_at = Nonedef get_processor(self):+ """Return a mock processor."""# Mock processor that failsprocessor = AsyncMock()processor.side_effect = ValueError('Processing failed')return processorclass MockMaintenanceTaskRunner:+ """Mock runner for verifying task status transitions on failure."""+def __init__(self):self.status_updates = []self.error_logged = Noneasync def _process_task(self, task):+ """Process a single task."""# Simulate updating status to WORKINGtask.status = 'WORKING'task.updated_at = datetime.now()@@ -368,6 +394,8 @@ class TestMaintenanceTaskRunnerStandalone:# Mock the session handling logicclass MockSession:+ """Mock database session for verifying session usage patterns."""+def __init__(self):self.queries = []self.merges = []@@ -541,6 +569,8 @@ class TestMaintenanceTaskRunnerStandalone:"""Test handling of multiple tasks in sequence."""class MockTask:+ """Mock task with configurable success or failure behaviour."""+def __init__(self, task_id, should_fail=False):self.id = task_idself.processor_type = f'processor_{task_id}'@@ -548,6 +578,7 @@ class TestMaintenanceTaskRunnerStandalone:self.should_fail = should_faildef get_processor(self):+ """Return a mock processor."""processor = AsyncMock()if self.should_fail:processor.side_effect = Exception(f'Task {self.id} failed')@@ -556,12 +587,15 @@ class TestMaintenanceTaskRunnerStandalone:return processorclass MockMaintenanceTaskRunner:+ """Mock runner for verifying sequential processing of multiple tasks."""+def __init__(self):self.processed_tasks = []self.successful_tasks = []self.failed_tasks = []async def _process_pending_tasks(self):+ """Process all pending tasks."""# Simulate finding multiple taskstasks = [MockTask(1, should_fail=False),@@ -573,6 +607,7 @@ class TestMaintenanceTaskRunnerStandalone:await self._process_task(task)async def _process_task(self, task):+ """Process a single task."""self.processed_tasks.append(task.id)try:@@ -610,6 +645,8 @@ class TestMaintenanceTaskRunnerStandalone:# Mock the global instance patternclass MockMaintenanceTaskRunner:+ """Mock runner for verifying the global singleton instance pattern."""+def __init__(self):self.instance_id = id(self)@@ -628,11 +665,14 @@ class TestMaintenanceTaskRunnerStandalone:"""Test proper handling of task cancellation."""class MockMaintenanceTaskRunner:+ """Mock runner for verifying cancellation handling in the run loop."""+def __init__(self):self._running = Falseself.cancellation_handled = Falseasync def _run_loop(self):+ """Execute the main processing loop."""try:while self._running:await asyncio.sleep(0.01)