diff --git a/src/ska_tango_base/base/base_device.py b/src/ska_tango_base/base/base_device.py index 5946ff6f5ee97bd693cdf8f283e3a765f8c659e8..2c7f624a03cef40d71e83e50d08e15cebb1ee203 100644 --- a/src/ska_tango_base/base/base_device.py +++ b/src/ska_tango_base/base/base_device.py @@ -433,7 +433,6 @@ class SKABaseDevice(Device): device.set_change_event("status", True, True) device.set_archive_event("status", True, True) - # Long running command attributes device.set_change_event("longRunningCommandsInQueue", True, True) device.set_archive_event("longRunningCommandsInQueue", True, True) device.set_change_event("longRunningCommandIDsInQueue", True, True) @@ -1162,9 +1161,7 @@ class SKABaseDevice(Device): :return: ID, ResultCode, result. """ - if not self.component_manager.task_result: - return [] - return list(self.component_manager.task_result) + return self.component_manager.task_result # -------- # Commands diff --git a/src/ska_tango_base/base/component_manager.py b/src/ska_tango_base/base/component_manager.py index c19618b46b73f0e2967a88a326d6389465242a91..18a87e6fee7694bbb320da92ce3102d2e123f874 100644 --- a/src/ska_tango_base/base/component_manager.py +++ b/src/ska_tango_base/base/component_manager.py @@ -164,8 +164,6 @@ class BaseComponentManager: :return: ID, ResultCode, result. """ - if not self.queue_manager.task_result: - return [] return list(self.queue_manager.task_result) def off(self): diff --git a/src/ska_tango_base/base/task_queue_manager.py b/src/ska_tango_base/base/task_queue_manager.py index 0445009787af8ae6b21b71c0eeaa65529aeaa44b..6ea0d5fbf1ed059fa4ca20bc0305fcca64b09393 100644 --- a/src/ska_tango_base/base/task_queue_manager.py +++ b/src/ska_tango_base/base/task_queue_manager.py @@ -116,7 +116,7 @@ from uuid import uuid4 from queue import Empty, Queue from datetime import datetime from threading import Event -from typing import Any, Callable, Dict, Optional, Tuple +from typing import Any, Callable, Dict, Optional, Tuple, Union import tango @@ -442,7 +442,7 @@ class QueueManager: self._property_update_lock = threading.Lock() self._logger = logger if logger else logging.getLogger(__name__) - self._task_result: Optional[Tuple[str, str, str]] = None + self._task_result: Union[Tuple[str, str, str], Tuple[()]] = () self._tasks_in_queue: Dict[str, str] = {} # unique_id, task_name self._task_status: Dict[str, str] = {} # unique_id, status self._threads = [] @@ -476,7 +476,7 @@ class QueueManager: return self._work_queue.full() @property - def task_result(self) -> Tuple[str, str, str]: + def task_result(self) -> Union[Tuple[str, str, str], Tuple[()]]: """Return the last task result. :return: Last task result diff --git a/src/ska_tango_base/utils.py b/src/ska_tango_base/utils.py index 986fbf189a813502717c413caa04731d692e22f1..3a296c2a478aad7b37dbb139271f3a88200e2642 100644 --- a/src/ska_tango_base/utils.py +++ b/src/ska_tango_base/utils.py @@ -564,8 +564,7 @@ class StoredCommand: class LongRunningDeviceInterface: - """This class is a convenience class to be used by clients of devices - that implement long running commands. + """This class is a convenience class for long running command devices. The intent of this class is that clients should not have to keep track of command IDs or the various attributes @@ -577,10 +576,10 @@ class LongRunningDeviceInterface: Using this class, a client would need to: - Supply the Tango devices to connect to that implements long - running commands + running commands - The Long running commands to run (including parameter) - Optional callback that should be executed when the command - completes + completes The callback will be executed once the command completes across all devices. Thus there's no need to watch attribute changes or keep @@ -614,7 +613,7 @@ class LongRunningDeviceInterface: ) def push_event(self, ev: EventData): - """Handles the attribute change events. + """Handle the attribute change events. For every event that comes in: diff --git a/tests/conftest.py b/tests/conftest.py index 7652044902f3500724e02991a535361979aca9f5..4a3c4078a832a0bb67b5280d25c80d389895967d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -225,6 +225,7 @@ def logger(): @pytest.fixture(scope="module") def devices_to_test(request): + """Fixture for devices to test.""" yield getattr(request.module, "devices_to_test") @@ -233,7 +234,8 @@ def multi_device_tango_context( mocker, devices_to_test # pylint: disable=redefined-outer-name ): """ - Creates and returns a TANGO MultiDeviceTestContext object, with + Create and return a TANGO MultiDeviceTestContext object. + tango.DeviceProxy patched to work around a name-resolving issue. """ @@ -251,9 +253,7 @@ def multi_device_tango_context( mocker.patch( "tango.DeviceProxy", wraps=lambda fqdn, *args, **kwargs: _DeviceProxy( - "tango://{0}:{1}/{2}#dbase=no".format(HOST, PORT, fqdn), - *args, - **kwargs + "tango://{0}:{1}/{2}#dbase=no".format(HOST, PORT, fqdn), *args, **kwargs ), ) with MultiDeviceTestContext( diff --git a/tests/long_running_tasks/reference_base_device.py b/tests/long_running_tasks/reference_base_device.py index a9dde348c1ab5e144022c7545c467ae437b1e3f2..4d90ed45b765fd94ea0f93e704a2d3c1df9ab2f5 100644 --- a/tests/long_running_tasks/reference_base_device.py +++ b/tests/long_running_tasks/reference_base_device.py @@ -61,7 +61,9 @@ class LongRunningCommandBaseTestDevice(SKABaseDevice): self.register_command_object( "TestProgressWithArgs", - self.TestProgressWithArgsCommand(self.component_manager, logger=self.logger), + self.TestProgressWithArgsCommand( + self.component_manager, logger=self.logger + ), ) class ShortCommand(ResponseCommand): @@ -194,8 +196,7 @@ class LongRunningCommandBaseTestDevice(SKABaseDevice): def do(self): """Execute something on the long running device.""" interface = self.target.lrc_device_interface - interface.execute_long_running_command( - "TestProgress", 0.5, None) + interface.execute_long_running_command("TestProgress", 0.5, None) self.logger.info("In TestProgressNoArgsCommand") return (ResultCode.OK, "Done TestProgressNoArgsCommand") @@ -216,8 +217,7 @@ class LongRunningCommandBaseTestDevice(SKABaseDevice): def do(self, argin): """Execute something on the long running device.""" interface = self.target.lrc_device_interface - interface.execute_long_running_command( - "TestProgress", argin, None) + interface.execute_long_running_command("TestProgress", argin, None) self.logger.info("In TestProgressWithArgs") return (ResultCode.OK, "Done TestProgressWithArgsCommand")