|
9 | 9 |
|
10 | 10 | from opentrons.motion_planning import adjacent_slots_getters as mock_adjacent_slots
|
11 | 11 | from opentrons.protocols.api_support.types import APIVersion
|
12 |
| -from opentrons.protocol_api.core.common import ProtocolCore, LabwareCore |
| 12 | +from opentrons.protocols.api_support.util import APIVersionError |
| 13 | +from opentrons.protocol_api.core.common import ProtocolCore, LabwareCore, ModuleCore |
13 | 14 | from opentrons.protocol_api.core.core_map import LoadedCoreMap
|
14 |
| -from opentrons.protocol_api import Deck, Labware, validation as mock_validation |
| 15 | +from opentrons.protocol_api import ( |
| 16 | + Deck, |
| 17 | + Labware, |
| 18 | + OFF_DECK, |
| 19 | + validation as mock_validation, |
| 20 | +) |
15 | 21 | from opentrons.protocol_api.deck import CalibrationPosition
|
16 | 22 | from opentrons.types import DeckSlotName, Point
|
17 | 23 |
|
@@ -135,6 +141,89 @@ def test_get_slot_item(
|
135 | 141 | assert subject[42] is mock_labware
|
136 | 142 |
|
137 | 143 |
|
| 144 | +def test_delitem_aliases_to_move_labware( |
| 145 | + decoy: Decoy, |
| 146 | + mock_protocol_core: ProtocolCore, |
| 147 | + api_version: APIVersion, |
| 148 | + subject: Deck, |
| 149 | +) -> None: |
| 150 | + """It should be equivalent to a manual labware move to off-deck, without pausing.""" |
| 151 | + mock_labware_core = decoy.mock(cls=LabwareCore) |
| 152 | + |
| 153 | + decoy.when(mock_protocol_core.robot_type).then_return("OT-3 Standard") |
| 154 | + decoy.when( |
| 155 | + mock_validation.ensure_and_convert_deck_slot(42, api_version, "OT-3 Standard") |
| 156 | + ).then_return(DeckSlotName.SLOT_2) |
| 157 | + decoy.when(mock_protocol_core.get_slot_item(DeckSlotName.SLOT_2)).then_return( |
| 158 | + mock_labware_core |
| 159 | + ) |
| 160 | + |
| 161 | + del subject[42] |
| 162 | + |
| 163 | + decoy.verify( |
| 164 | + mock_protocol_core.move_labware( |
| 165 | + mock_labware_core, |
| 166 | + OFF_DECK, |
| 167 | + use_gripper=False, |
| 168 | + pause_for_manual_move=False, |
| 169 | + pick_up_offset=None, |
| 170 | + drop_offset=None, |
| 171 | + ) |
| 172 | + ) |
| 173 | + |
| 174 | + |
| 175 | +@pytest.mark.parametrize("api_version", [APIVersion(2, 14)]) |
| 176 | +def test_delitem_raises_on_api_2_14( |
| 177 | + subject: Deck, |
| 178 | +) -> None: |
| 179 | + """It should raise on apiLevel 2.14.""" |
| 180 | + with pytest.raises(APIVersionError): |
| 181 | + del subject[1] |
| 182 | + |
| 183 | + |
| 184 | +def test_delitem_noops_if_slot_is_empty( |
| 185 | + decoy: Decoy, |
| 186 | + mock_protocol_core: ProtocolCore, |
| 187 | + api_version: APIVersion, |
| 188 | + subject: Deck, |
| 189 | +) -> None: |
| 190 | + """It should do nothing, and not raise anything, if you try to delete from an empty slot.""" |
| 191 | + decoy.when(mock_protocol_core.robot_type).then_return("OT-3 Standard") |
| 192 | + decoy.when( |
| 193 | + mock_validation.ensure_and_convert_deck_slot(1, api_version, "OT-3 Standard") |
| 194 | + ).then_return(DeckSlotName.SLOT_1) |
| 195 | + decoy.when(mock_protocol_core.get_slot_item(DeckSlotName.SLOT_1)).then_return(None) |
| 196 | + |
| 197 | + del subject[1] |
| 198 | + |
| 199 | + |
| 200 | +def test_delitem_raises_if_slot_has_module( |
| 201 | + decoy: Decoy, |
| 202 | + mock_protocol_core: ProtocolCore, |
| 203 | + api_version: APIVersion, |
| 204 | + subject: Deck, |
| 205 | +) -> None: |
| 206 | + """It should raise a descriptive error if you try to delete a module.""" |
| 207 | + decoy.when(mock_protocol_core.robot_type).then_return("OT-3 Standard") |
| 208 | + mock_module_core = decoy.mock(cls=ModuleCore) |
| 209 | + decoy.when(mock_module_core.get_display_name()).then_return("<module display name>") |
| 210 | + decoy.when( |
| 211 | + mock_validation.ensure_and_convert_deck_slot(2, api_version, "OT-3 Standard") |
| 212 | + ).then_return(DeckSlotName.SLOT_2) |
| 213 | + decoy.when(mock_protocol_core.get_slot_item(DeckSlotName.SLOT_2)).then_return( |
| 214 | + mock_module_core |
| 215 | + ) |
| 216 | + |
| 217 | + with pytest.raises( |
| 218 | + TypeError, |
| 219 | + match=( |
| 220 | + "Slot 2 contains a module, <module display name>." |
| 221 | + " You can only delete labware, not modules." |
| 222 | + ), |
| 223 | + ): |
| 224 | + del subject[2] |
| 225 | + |
| 226 | + |
138 | 227 | @pytest.mark.parametrize(
|
139 | 228 | "deck_definition",
|
140 | 229 | [
|
|
0 commit comments