Skip to content

Commit

Permalink
add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
amit lissack committed Apr 14, 2021
1 parent fb7d65b commit 06d8835
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions api/tests/opentrons/protocol_api/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,53 @@ def fake_plan_move(from_loc, to_loc, deck,
assert test_args[0].labware.as_well() == lw.wells()[0]


async def test_location_cache_two_pipettes(ctx, get_labware_def, hardware):
"""It should be invalidated when next movement is a different pipette
than the cached location."""
ctx.home()
left = ctx.load_instrument('p10_single', Mount.LEFT)
right = ctx.load_instrument('p10_single', Mount.RIGHT)

left_loc = Location(point=Point(1, 2, 3), labware="1")
right_loc = Location(point=Point(3, 4, 5), labware="2")

with mock.patch.object(papi_geometry.planning, "plan_moves") as m:
# The first moves. The location cache is empty.
left.move_to(left_loc)
assert m.call_args[0][0].labware.is_empty
assert m.call_args[0][1] == left_loc
# The second move the location cache is not used because we're moving
# a different pipette.
right.move_to(right_loc)
assert m.call_args[0][0].labware.is_empty
assert m.call_args[0][1] == right_loc


async def test_location_cache_two_pipettes_fails_pre_2_10(
ctx,
get_labware_def, hardware
):
"""It should reuse location cache even if cached location was set by
move of a different pipette."""
ctx.home()
left = ctx.load_instrument('p10_single', Mount.LEFT)
right = ctx.load_instrument('p10_single', Mount.RIGHT)
left._implementation._api_version = APIVersion(2, 9)
right._implementation._api_version = APIVersion(2, 9)

left_loc = Location(point=Point(1, 2, 3), labware="1")
right_loc = Location(point=Point(3, 4, 5), labware="2")

with mock.patch.object(papi_geometry.planning, "plan_moves") as m:
# The first moves. The location cache is empty.
left.move_to(left_loc)
assert m.call_args[0][0].labware.is_empty
assert m.call_args[0][1] == left_loc
right.move_to(right_loc)
assert m.call_args[0][0].labware == left_loc.labware
assert m.call_args[0][1] == right_loc


async def test_move_uses_arc(ctx, monkeypatch, get_labware_def, hardware):
ctx.connect(hardware)
ctx.home()
Expand Down

0 comments on commit 06d8835

Please sign in to comment.