diff --git a/src/blueapi/utils/ophyd_async_connect.py b/src/blueapi/utils/ophyd_async_connect.py index ee463403e..31423a739 100644 --- a/src/blueapi/utils/ophyd_async_connect.py +++ b/src/blueapi/utils/ophyd_async_connect.py @@ -30,7 +30,7 @@ async def _wait_for_tasks(tasks: Dict[asyncio.Task, str], timeout: float): t.cancel() with suppress(Exception): await t - msg += format_error_message(tasks, t) + msg += _format_awaited_task_error_message(tasks, t) logging.error(msg) raised = [t for t in done if t.exception()] if raised: @@ -41,7 +41,9 @@ async def _wait_for_tasks(tasks: Dict[asyncio.Task, str], timeout: float): raise NotConnected("Not all Devices connected") -def format_error_message(tasks: Dict[asyncio.Task, str], t: asyncio.Task) -> str: +def _format_awaited_task_error_message( + tasks: Dict[asyncio.Task, str], t: asyncio.Task +) -> str: e = t.exception() part_one = f"\n {tasks[t]}: {type(e).__name__}" lines = str(e).splitlines() diff --git a/tests/utils/test_ophyd_async_connect.py b/tests/utils/test_ophyd_async_connect.py index f9cdf7006..f3dcba767 100644 --- a/tests/utils/test_ophyd_async_connect.py +++ b/tests/utils/test_ophyd_async_connect.py @@ -1,7 +1,7 @@ import asyncio import unittest -from blueapi.utils.ophyd_async_connect import format_error_message +from blueapi.utils.ophyd_async_connect import _format_awaited_task_error_message from blueapi.worker.task import Task _SIMPLE_TASK = Task(name="sleep", params={"time": 0.0}) @@ -34,7 +34,9 @@ def test_format_error_message_single_line(self): task = self.loop.run_until_complete(self._create_task_with_exception(exception)) tasks = {task: "Task1"} expected_output = "\n Task1: ValueError: A single-line error" - self.assertEqual(format_error_message(tasks, task), expected_output) + self.assertEqual( + _format_awaited_task_error_message(tasks, task), expected_output + ) def test_format_error_message_multi_line(self): # Test formatting with an exception that has a multi-line message @@ -42,7 +44,9 @@ def test_format_error_message_multi_line(self): task = self.loop.run_until_complete(self._create_task_with_exception(exception)) tasks = {task: "Task2"} expected_output = "\n Task2: ValueError\n A multi-line\n error message" - self.assertEqual(format_error_message(tasks, task), expected_output) + self.assertEqual( + _format_awaited_task_error_message(tasks, task), expected_output + ) def test_format_error_message_simple_task_failure(self): # Test formatting with the _SIMPLE_TASK key and a failing asyncio task @@ -52,7 +56,9 @@ def test_format_error_message_simple_task_failure(self): ) tasks = {failing_task: _SIMPLE_TASK.name} expected_output = "\n sleep: RuntimeError: Simple task error" - self.assertEqual(format_error_message(tasks, failing_task), expected_output) + self.assertEqual( + _format_awaited_task_error_message(tasks, failing_task), expected_output + ) def test_format_error_message_long_task_failure(self): # Test formatting with the _LONG_TASK key and a failing asyncio task @@ -62,7 +68,9 @@ def test_format_error_message_long_task_failure(self): ) tasks = {failing_task: _LONG_TASK.name} expected_output = "\n sleep: RuntimeError: Long task error" - self.assertEqual(format_error_message(tasks, failing_task), expected_output) + self.assertEqual( + _format_awaited_task_error_message(tasks, failing_task), expected_output + ) if __name__ == "__main__":