Skip to content

Commit

Permalink
add tests for the new state updates
Browse files Browse the repository at this point in the history
  • Loading branch information
sfoster1 committed Feb 25, 2025
1 parent 8a452d8 commit 64444f0
Showing 1 changed file with 175 additions and 1 deletion.
176 changes: 175 additions & 1 deletion api/tests/opentrons/protocol_engine/state/test_labware_store_old.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@

from opentrons.calibration_storage.helpers import uri_from_details
from opentrons_shared_data.deck.types import DeckDefinitionV5
from opentrons_shared_data.labware.labware_definition import LabwareDefinition
from opentrons_shared_data.labware.labware_definition import (
LabwareDefinition,
LabwareDefinition2,
Parameters2,
)
from opentrons.types import DeckSlotName

from opentrons.protocol_engine.types import (
Expand Down Expand Up @@ -361,3 +365,173 @@ def test_handles_move_labware_off_deck(
)
assert subject.state.labware_by_id["my-labware-id"].location == OFF_DECK_LOCATION
assert subject.state.labware_by_id["my-labware-id"].offsetId is None


def test_handle_batch_labware_loaded_update(
subject: LabwareStore,
well_plate_def: LabwareDefinition,
) -> None:
"""It should consume batch_loaded_labware updates."""
request = LabwareOffsetCreateInternal(
definitionUri="offset-definition-uri",
legacyLocation=LegacyLabwareOffsetLocation(slotName=DeckSlotName.SLOT_1),
locationSequence=[
OnAddressableAreaOffsetLocationSequenceComponent(addressableAreaName="1")
],
vector=LabwareOffsetVector(x=1, y=2, z=3),
)
subject.handle_action(
AddLabwareOffsetAction(
labware_offset_id="some-offset-id",
created_at=datetime(year=2021, month=1, day=2),
request=request,
)
)
comment_command = create_comment_command()
subject.handle_action(
SucceedCommandAction(
command=comment_command,
state_update=update_types.StateUpdate(
batch_loaded_labware=update_types.BatchLoadedLabwareUpdate(
new_locations_by_id={
"some-labware-id": DeckSlotLocation(
slotName=DeckSlotName.SLOT_1
),
"some-other-labware-id": OFF_DECK_LOCATION,
},
offset_ids_by_id={
"some-labware-id": "some-offset-id",
"some-other-labware-id": None,
},
display_names_by_id={
"some-labware-id": "some-display-name",
"some-other-labware-id": None,
},
definitions_by_id={
"some-labware-id": LabwareDefinition2.model_construct( # type: ignore[call-arg]
schemaVersion=2,
namespace="namespace-1",
version=1,
parameters=Parameters2.model_construct( # type: ignore[call-arg]
loadName="load-name-1"
),
),
"some-other-labware-id": LabwareDefinition2.model_construct( # type: ignore[call-arg]
schemaVersion=2,
namespace="namespace-2",
version=2,
parameters=Parameters2.model_construct( # type: ignore[call-arg]
loadName="load-name-2"
),
),
},
)
),
)
)
some_labware = subject.state.labware_by_id["some-labware-id"]
some_other_labware = subject.state.labware_by_id["some-other-labware-id"]
assert some_labware.id == "some-labware-id"
assert some_labware.location == DeckSlotLocation(slotName=DeckSlotName.SLOT_1)
assert some_labware.loadName == "load-name-1"
assert some_labware.definitionUri == "namespace-1/load-name-1/1"
assert some_labware.offsetId == "some-offset-id"
assert some_labware.displayName == "some-display-name"

assert some_other_labware.id == "some-other-labware-id"
assert some_other_labware.location == OFF_DECK_LOCATION
assert some_other_labware.loadName == "load-name-2"
assert some_other_labware.definitionUri == "namespace-2/load-name-2/2"
assert some_other_labware.offsetId is None
assert some_other_labware.displayName is None


def test_handle_batch_labware_location_update(
subject: LabwareStore,
well_plate_def: LabwareDefinition,
) -> None:
"""It should consume batch_labware_location updates."""
request = LabwareOffsetCreateInternal(
definitionUri="offset-definition-uri",
legacyLocation=LegacyLabwareOffsetLocation(slotName=DeckSlotName.SLOT_1),
locationSequence=[
OnAddressableAreaOffsetLocationSequenceComponent(addressableAreaName="1")
],
vector=LabwareOffsetVector(x=1, y=2, z=3),
)
subject.handle_action(
AddLabwareOffsetAction(
labware_offset_id="some-offset-id",
created_at=datetime(year=2021, month=1, day=2),
request=request,
)
)
comment_command = create_comment_command()
subject.handle_action(
SucceedCommandAction(
command=comment_command,
state_update=update_types.StateUpdate(
batch_loaded_labware=update_types.BatchLoadedLabwareUpdate(
new_locations_by_id={
"some-labware-id": DeckSlotLocation(
slotName=DeckSlotName.SLOT_1
),
"some-other-labware-id": OFF_DECK_LOCATION,
},
offset_ids_by_id={
"some-labware-id": "some-offset-id",
"some-other-labware-id": None,
},
display_names_by_id={
"some-labware-id": "some-display-name",
"some-other-labware-id": None,
},
definitions_by_id={
"some-labware-id": LabwareDefinition2.model_construct( # type: ignore[call-arg]
schemaVersion=2,
namespace="namespace-1",
version=1,
parameters=Parameters2.model_construct( # type: ignore[call-arg]
loadName="load-name-1"
),
),
"some-other-labware-id": LabwareDefinition2.model_construct( # type: ignore[call-arg]
schemaVersion=2,
namespace="namespace-2",
version=2,
parameters=Parameters2.model_construct( # type: ignore[call-arg]
loadName="load-name-2"
),
),
},
)
),
)
)
comment_command2 = create_comment_command()
subject.handle_action(
SucceedCommandAction(
command=comment_command2,
state_update=update_types.StateUpdate(
batch_labware_location=update_types.BatchLabwareLocationUpdate(
new_locations_by_id={
"some-labware-id": OFF_DECK_LOCATION,
"some-other-labware-id": DeckSlotLocation(
slotName=DeckSlotName.SLOT_1
),
},
new_offset_ids_by_id={
"some-labware-id": None,
"some-other-labware-id": "some-offset-id",
},
)
),
)
)
some_labware = subject.state.labware_by_id["some-labware-id"]
some_other_labware = subject.state.labware_by_id["some-other-labware-id"]
assert some_labware.location == OFF_DECK_LOCATION
assert some_labware.offsetId is None

assert some_other_labware.location == DeckSlotLocation(slotName=DeckSlotName.SLOT_1)
assert some_other_labware.offsetId == "some-offset-id"

0 comments on commit 64444f0

Please sign in to comment.