Skip to content

Commit

Permalink
raise if no gripper attached
Browse files Browse the repository at this point in the history
  • Loading branch information
TamarZanzouri committed Oct 2, 2024
1 parent 6f6b27d commit 5d5cc13
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Ungrip labware payload, result, and implementaiton."""

from __future__ import annotations
from opentrons.protocol_engine.errors.exceptions import GripperNotAttachedError
from pydantic import BaseModel
from typing import Optional, Type
from typing_extensions import Literal
Expand Down Expand Up @@ -42,7 +43,10 @@ async def execute(
self, params: UnsafeUngripLabwareParams
) -> SuccessData[UnsafeUngripLabwareResult, None]:
"""Ungrip Labware."""
print("ungripping")
ot3_hardware_api = ensure_ot3_hardware(self._hardware_api)
if not ot3_hardware_api.has_gripper():
raise GripperNotAttachedError("No gripper found for ungrip.")
await ot3_hardware_api.ungrip()
return SuccessData(public=UnsafeUngripLabwareResult(), private=None)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,37 @@
UnsafeUngripLabwareImplementation,
)
from opentrons.protocol_engine.commands.command import SuccessData
from opentrons.protocol_engine.errors.exceptions import GripperNotAttachedError
from opentrons.protocol_engine.execution import GantryMover
from opentrons.protocol_engine.types import MotorAxis
from opentrons.hardware_control import OT3HardwareControlAPI
from opentrons.hardware_control.types import Axis
import pytest


async def test_engage_axes_implementation(
decoy: Decoy, ot3_hardware_api: OT3HardwareControlAPI, gantry_mover: GantryMover
async def test_ungrip_labware_implementation(
decoy: Decoy, ot3_hardware_api: OT3HardwareControlAPI
) -> None:
"""Test EngageAxes command execution."""
"""Test UngripLabware command execution."""
subject = UnsafeUngripLabwareImplementation(hardware_api=ot3_hardware_api)

decoy.when(ot3_hardware_api.has_gripper()).then_return(True)

result = await subject.execute(params=UnsafeUngripLabwareParams())

assert result == SuccessData(public=UnsafeUngripLabwareResult(), private=None)

decoy.verify(
await ot3_hardware_api.ungrip(),
)


async def test_ungrip_labware_implementation_raises_no_gripper_attached(
decoy: Decoy, ot3_hardware_api: OT3HardwareControlAPI
) -> None:
"""Test UngripLabware command execution."""
subject = UnsafeUngripLabwareImplementation(hardware_api=ot3_hardware_api)

decoy.when(ot3_hardware_api.has_gripper()).then_return(False)
with pytest.raises(GripperNotAttachedError):
await subject.execute(params=UnsafeUngripLabwareParams())

0 comments on commit 5d5cc13

Please sign in to comment.