|
| 1 | +# Copyright 2026 Dimensional Inc. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +"""Shared control-task stubs for tests. |
| 16 | +
|
| 17 | +Not named ``test_*``/``*_test`` so pytest does not collect it; both |
| 18 | +``test_control.py`` and ``test_coordinator_routing.py`` import ``RecordingTask`` |
| 19 | +from here rather than reaching into each other's test modules. |
| 20 | +""" |
| 21 | + |
| 22 | +from __future__ import annotations |
| 23 | + |
| 24 | +from typing import Any |
| 25 | + |
| 26 | +from dimos.control.task import ( |
| 27 | + BaseControlTask, |
| 28 | + CoordinatorState, |
| 29 | + JointCommandOutput, |
| 30 | + ResourceClaim, |
| 31 | +) |
| 32 | + |
| 33 | + |
| 34 | +class RecordingTask(BaseControlTask): |
| 35 | + """Stub task that records every stream handler invocation.""" |
| 36 | + |
| 37 | + def __init__(self, name: str, joints: frozenset[str] = frozenset()) -> None: |
| 38 | + self._name = name |
| 39 | + self._joints = frozenset(joints) |
| 40 | + self.cartesian_calls: list[tuple[Any, float]] = [] |
| 41 | + self.ee_twist_calls: list[tuple[Any, float]] = [] |
| 42 | + self.buttons_calls: list[Any] = [] |
| 43 | + |
| 44 | + def claim(self) -> ResourceClaim: |
| 45 | + return ResourceClaim(joints=self._joints) |
| 46 | + |
| 47 | + def is_active(self) -> bool: |
| 48 | + return False |
| 49 | + |
| 50 | + def compute(self, state: CoordinatorState) -> JointCommandOutput | None: |
| 51 | + return None |
| 52 | + |
| 53 | + def on_preempted(self, by_task: str, joints: frozenset[str]) -> None: |
| 54 | + pass |
| 55 | + |
| 56 | + def on_cartesian_command(self, pose: Any, t_now: float) -> bool: |
| 57 | + self.cartesian_calls.append((pose, t_now)) |
| 58 | + return True |
| 59 | + |
| 60 | + def on_ee_twist_command(self, twist: Any, t_now: float) -> bool: |
| 61 | + self.ee_twist_calls.append((twist, t_now)) |
| 62 | + return True |
| 63 | + |
| 64 | + def on_buttons(self, msg: Any) -> bool: |
| 65 | + self.buttons_calls.append(msg) |
| 66 | + return True |
| 67 | + |
| 68 | + def on_teleop_buttons(self, msg: Any, t_now: float) -> bool: |
| 69 | + # Mirrors TeleopIKTask: the uniform handler delegates to on_buttons. |
| 70 | + return self.on_buttons(msg) |
0 commit comments