From 8f225c61f1058bc06c2cb606e9506f1053eebf89 Mon Sep 17 00:00:00 2001 From: laura_danielle Date: Tue, 20 Oct 2020 11:10:54 -0400 Subject: [PATCH] Robot server fix up all tests except tavern --- .../robot/calibration/check/user_flow.py | 11 +- .../robot_server/robot/calibration/models.py | 4 +- .../service/legacy/models/pipettes.py | 2 - .../robot_server/service/session/router.py | 3 - .../session/session_types/check_session.py | 7 +- .../test_calibration_check.tavern.yaml | 222 ++++++++++-------- .../calibration/check/test_state_machine.py | 38 +-- .../robot/calibration/check/test_user_flow.py | 150 ++++++++---- 8 files changed, 265 insertions(+), 172 deletions(-) diff --git a/robot-server/robot_server/robot/calibration/check/user_flow.py b/robot-server/robot_server/robot/calibration/check/user_flow.py index 6643c0f7f049..f4b26bee1430 100644 --- a/robot-server/robot_server/robot/calibration/check/user_flow.py +++ b/robot-server/robot_server/robot/calibration/check/user_flow.py @@ -85,7 +85,7 @@ def __init__( self._active_tiprack = self._load_active_tiprack() self._command_map: COMMAND_MAP = { - CalibrationCommand.load_labware: self.load_labware, + CalibrationCommand.load_labware: self.transition, CalibrationCommand.jog: self.jog, CalibrationCommand.pick_up_tip: self.pick_up_tip, CalibrationCommand.invalidate_tip: self.invalidate_tip, @@ -97,7 +97,7 @@ def __init__( DeckCalibrationCommand.move_to_point_three: self.move_to_point_three, # noqa: E501 CheckCalibrationCommand.switch_pipette: self.change_active_pipette, CheckCalibrationCommand.return_tip: self._return_tip, - CheckCalibrationCommand.transition: self.load_labware, + CheckCalibrationCommand.transition: self.transition, CalibrationCommand.exit: self.exit_session, } @@ -129,7 +129,7 @@ def active_tiprack(self) -> labware.Labware: def _hw_pipette(self) -> Pipette: return self._get_hw_pipettes()[0] - async def load_labware(self): + async def transition(self): pass async def change_active_pipette(self): @@ -314,9 +314,7 @@ def get_instruments(self) -> List[CheckAttachedPipette]: being used for a given session for the client. """ hw_pips = self._get_hw_pipettes() - MODULE_LOG.info(f"HW PIPS: {hw_pips}") info_pips = self._get_ordered_info_pipettes() - MODULE_LOG.info(f"INFO PIPS: {info_pips}") return [ CheckAttachedPipette( # type: ignore[call-arg] model=hw_pip.model, @@ -551,7 +549,7 @@ async def move_to_tip_rack(self): handler="move_to_tip_rack", condition="active tiprack") point = self.active_tiprack.wells()[0].top().point + \ - MOVE_TO_TIP_RACK_SAFETY_BUFFER + MOVE_TO_TIP_RACK_SAFETY_BUFFER to_loc = Location(point, None) await self._move(to_loc) await self.register_initial_point() @@ -605,7 +603,6 @@ async def _move(self, to_loc: Location): await uf.move(self, to_loc) async def exit_session(self): - MODULE_LOG.info("exit session was initiated") if self._hw_pipette.has_tip: await self.move_to_tip_rack() await self._return_tip() diff --git a/robot-server/robot_server/robot/calibration/models.py b/robot-server/robot_server/robot/calibration/models.py index adf839e184f5..9693f6cc0539 100644 --- a/robot-server/robot_server/robot/calibration/models.py +++ b/robot-server/robot_server/robot/calibration/models.py @@ -1,4 +1,4 @@ -from typing import Optional, List +from typing import Optional from pydantic import BaseModel, Field @@ -20,7 +20,7 @@ class SessionCreateParams(BaseModel): ) tipRackDefinition: Optional[dict] = Field( None, - description='The full tiprack definition(s)' + description='The full tiprack definition' 'to use for a calibration session.' ) shouldPerformTipLength: bool = Field( diff --git a/robot-server/robot_server/service/legacy/models/pipettes.py b/robot-server/robot_server/service/legacy/models/pipettes.py index 84a5c70826d2..d51e664ceabc 100644 --- a/robot-server/robot_server/service/legacy/models/pipettes.py +++ b/robot-server/robot_server/service/legacy/models/pipettes.py @@ -27,8 +27,6 @@ class AttachedPipette(BaseModel): id: typing.Optional[str] = \ Field(..., description="The serial number of the attached pipette") - rank: typing.Optional[str] = \ - Field(None, description="The order of a pipette, if relevant") class PipettesByMount(BaseModel): diff --git a/robot-server/robot_server/service/session/router.py b/robot-server/robot_server/service/session/router.py index c2e0700d61cd..6d4e11805eab 100644 --- a/robot-server/robot_server/service/session/router.py +++ b/robot-server/robot_server/service/session/router.py @@ -80,8 +80,6 @@ async def delete_session_handler( session_obj = get_session(manager=session_manager, session_id=sessionId, api_router=router) - log.info("delete was called! ") - log.info(f"session object {session_obj}") await session_manager.remove(session_obj.meta.identifier) return SessionResponse( @@ -157,7 +155,6 @@ async def session_command_execute_handler( command_request.data.attributes.data) command_result = await session_obj.command_executor.execute(command) - log.info(f"Command completed: {command}") log.debug(f"Command result: {command_result}") return CommandResponse( diff --git a/robot-server/robot_server/service/session/session_types/check_session.py b/robot-server/robot_server/service/session/session_types/check_session.py index 488332efd5f8..517f5aefab1b 100644 --- a/robot-server/robot_server/service/session/session_types/check_session.py +++ b/robot-server/robot_server/service/session/session_types/check_session.py @@ -1,4 +1,4 @@ -from typing import Awaitable, cast, TYPE_CHECKING, List, Optional +from typing import Awaitable, cast, TYPE_CHECKING, List from robot_server.robot.calibration.check.user_flow import\ CheckCalibrationUserFlow @@ -49,15 +49,16 @@ async def create(cls, configuration: SessionConfiguration, instance_meta: SessionMetaData) -> BaseSession: """Create an instance""" - # (lc, 10-19-2020) For now, only pass in empty tipracks. We cannot + # (lc, 10-19-2020) For now, only pass in an empty list. We cannot # have a session model with an optional tiprack for session # create params right now because of the pydantic union problem. - tip_racks: List[Optional['LabwareDefinition']] = [] + tip_racks: List = [] # if lights are on already it's because the user clicked the button, # so a) we don't need to turn them on now and b) we shouldn't turn them # off after session_controls_lights =\ not configuration.hardware.get_lights()['rails'] + await configuration.hardware.cache_instruments() try: calibration_check = CheckCalibrationUserFlow( configuration.hardware, diff --git a/robot-server/tests/integration/sessions/test_calibration_check.tavern.yaml b/robot-server/tests/integration/sessions/test_calibration_check.tavern.yaml index 94b336d60dcc..4ebec49b2630 100644 --- a/robot-server/tests/integration/sessions/test_calibration_check.tavern.yaml +++ b/robot-server/tests/integration/sessions/test_calibration_check.tavern.yaml @@ -37,9 +37,11 @@ stages: createParams: null details: &session_data_attribute_details currentStep: sessionStarted - instruments: !anydict + instruments: !anylist + activePipette: !anydict + activeTipRack: !anydict labware: !anylist - comparisonsByStep: {} + comparisonsByPipette: !anydict - name: Load labware request: &post_command @@ -75,7 +77,7 @@ stages: id: "{session_id}" type: SessionCommand attributes: - command: preparePipette + command: moveToTipRack data: {} response: status_code: 200 @@ -91,7 +93,7 @@ stages: <<: *session_data_attributes details: <<: *session_data_attribute_details - currentStep: preparingFirstPipette + currentStep: preparingPipette - name: Jog first pipette request: @@ -117,7 +119,7 @@ stages: <<: *session_data_attributes details: <<: *session_data_attribute_details - currentStep: preparingFirstPipette + currentStep: preparingPipette - name: Pick up tip request: @@ -142,7 +144,7 @@ stages: <<: *session_data_attributes details: <<: *session_data_attribute_details - currentStep: inspectingFirstTip + currentStep: inspectingTip - name: Confirm tip attached request: @@ -151,7 +153,7 @@ stages: data: type: SessionCommand attributes: - command: confirmTip + command: moveToDeck data: {} response: status_code: 200 @@ -167,7 +169,7 @@ stages: <<: *session_data_attributes details: <<: *session_data_attribute_details - currentStep: joggingFirstPipetteToHeight + currentStep: comparingHeight - name: Jog first pipette to height request: @@ -193,7 +195,7 @@ stages: <<: *session_data_attributes details: <<: *session_data_attribute_details - currentStep: joggingFirstPipetteToHeight + currentStep: comparingHeight - name: Compare first pipette height request: @@ -218,8 +220,8 @@ stages: <<: *session_data_attributes details: <<: *session_data_attribute_details - currentStep: comparingFirstPipetteHeight - comparisonsByStep: + currentStep: comparingHeight + comparisonsByPipette: comparingFirstPipetteHeight: !anydict - name: Go to next check @@ -229,7 +231,7 @@ stages: data: type: SessionCommand attributes: - command: goToNextCheck + command: moveToPointOne data: {} response: status_code: 200 @@ -245,8 +247,8 @@ stages: <<: *session_data_attributes details: <<: *session_data_attribute_details - currentStep: joggingFirstPipetteToPointOne - comparisonsByStep: + currentStep: comparingPointOne + comparisonsByPipette: comparingFirstPipetteHeight: !anydict - name: Compare first pipette point one @@ -272,8 +274,8 @@ stages: <<: *session_data_attributes details: <<: *session_data_attribute_details - currentStep: comparingFirstPipettePointOne - comparisonsByStep: + currentStep: comparingPointOne + comparisonsByPipette: comparingFirstPipetteHeight: !anydict comparingFirstPipettePointOne: !anydict @@ -284,7 +286,7 @@ stages: data: type: SessionCommand attributes: - command: goToNextCheck + command: moveToPointTwo data: {} response: status_code: 200 @@ -300,10 +302,10 @@ stages: <<: *session_data_attributes details: <<: *session_data_attribute_details - currentStep: joggingFirstPipetteToPointTwo - comparisonsByStep: - comparingFirstPipetteHeight: !anydict - comparingFirstPipettePointOne: !anydict + currentStep: comparingPointTwo + comparisonsByPipette: + first: !anydict + second: !anydict - name: Compare first pipette point two request: @@ -328,11 +330,10 @@ stages: <<: *session_data_attributes details: <<: *session_data_attribute_details - currentStep: comparingFirstPipettePointTwo - comparisonsByStep: - comparingFirstPipetteHeight: !anydict - comparingFirstPipettePointOne: !anydict - comparingFirstPipettePointTwo: !anydict + currentStep: comparingPointTwo + comparisonsByPipette: + first: !anydict + second: !anydict - name: Go to next check request: @@ -341,7 +342,7 @@ stages: data: type: SessionCommand attributes: - command: goToNextCheck + command: moveToPointThree data: {} response: status_code: 200 @@ -357,11 +358,10 @@ stages: <<: *session_data_attributes details: <<: *session_data_attribute_details - currentStep: joggingFirstPipetteToPointThree - comparisonsByStep: - comparingFirstPipetteHeight: !anydict - comparingFirstPipettePointOne: !anydict - comparingFirstPipettePointTwo: !anydict + currentStep: comparingPointThree + comparisonsByPipette: + first: !anydict + second: !anydict - name: Compare first pipette point three request: @@ -386,12 +386,10 @@ stages: <<: *session_data_attributes details: <<: *session_data_attribute_details - currentStep: comparingFirstPipettePointThree - comparisonsByStep: - comparingFirstPipetteHeight: !anydict - comparingFirstPipettePointOne: !anydict - comparingFirstPipettePointTwo: !anydict - comparingFirstPipettePointThree: !anydict + currentStep: comparingPointThree + comparisonsByPipette: + first: !anydict + second: !anydict - name: Go to next check request: @@ -400,7 +398,7 @@ stages: data: type: SessionCommand attributes: - command: goToNextCheck + command: moveToTiprack data: {} response: status_code: 200 @@ -416,14 +414,67 @@ stages: <<: *session_data_attributes details: <<: *session_data_attribute_details - currentStep: preparingSecondPipette - comparisonsByStep: - comparingFirstPipetteHeight: !anydict - comparingFirstPipettePointOne: !anydict - comparingFirstPipettePointTwo: !anydict - comparingFirstPipettePointThree: !anydict + currentStep: returningTip + comparisonsByPipette: + first: !anydict + second: !anydict + + - name: Switch To Second Pipette + request: + <<: *post_command + json: + data: + type: SessionCommand + attributes: + command: switchPipette + data: + vector: [0, 0, -10] + response: + status_code: 200 + - name: Check the effect of command + request: *get_session + response: + status_code: 200 + json: + links: !anydict + data: + <<: *session_data + attributes: + <<: *session_data_attributes + details: + <<: *session_data_attribute_details + currentStep: preparingPipette + comparisonsByPipette: + first: !anydict + second: !anydict - - name: Jog Second Pipette + - name: Prepare second pipette + request: + <<: *post_command + json: + data: + id: "{session_id}" + type: SessionCommand + attributes: + command: moveToTipRack + data: {} + response: + status_code: 200 + - name: Check the effect of command + request: *get_session + response: + status_code: 200 + json: + links: !anydict + data: + <<: *session_data + attributes: + <<: *session_data_attributes + details: + <<: *session_data_attribute_details + currentStep: preparingPipette + + - name: Jog second pipette request: <<: *post_command json: @@ -447,12 +498,7 @@ stages: <<: *session_data_attributes details: <<: *session_data_attribute_details - currentStep: preparingSecondPipette - comparisonsByStep: - comparingFirstPipetteHeight: !anydict - comparingFirstPipettePointOne: !anydict - comparingFirstPipettePointTwo: !anydict - comparingFirstPipettePointThree: !anydict + currentStep: preparingPipette - name: Pick up tip request: @@ -477,12 +523,10 @@ stages: <<: *session_data_attributes details: <<: *session_data_attribute_details - currentStep: inspectingSecondTip - comparisonsByStep: - comparingFirstPipetteHeight: !anydict - comparingFirstPipettePointOne: !anydict - comparingFirstPipettePointTwo: !anydict - comparingFirstPipettePointThree: !anydict + currentStep: inspectingTip + comparisonsByPipette: + first: !anydict + second: !anydict - name: Confirm tip request: @@ -491,7 +535,7 @@ stages: data: type: SessionCommand attributes: - command: confirmTip + command: moveToDeck data: {} response: status_code: 200 @@ -507,12 +551,10 @@ stages: <<: *session_data_attributes details: <<: *session_data_attribute_details - currentStep: joggingSecondPipetteToHeight - comparisonsByStep: - comparingFirstPipetteHeight: !anydict - comparingFirstPipettePointOne: !anydict - comparingFirstPipettePointTwo: !anydict - comparingFirstPipettePointThree: !anydict + currentStep: comparingHeight + comparisonsByPipette: + first: !anydict + second: !anydict - name: Compare second pipette to height request: @@ -537,13 +579,10 @@ stages: <<: *session_data_attributes details: <<: *session_data_attribute_details - currentStep: comparingSecondPipetteHeight - comparisonsByStep: - comparingFirstPipetteHeight: !anydict - comparingFirstPipettePointOne: !anydict - comparingFirstPipettePointTwo: !anydict - comparingFirstPipettePointThree: !anydict - comparingSecondPipetteHeight: !anydict + currentStep: comparingHeight + comparisonsByPipette: + first: !anydict + second: !anydict - name: Go to next check request: @@ -552,7 +591,7 @@ stages: data: type: SessionCommand attributes: - command: goToNextCheck + command: moveToPointOne data: {} response: status_code: 200 @@ -568,13 +607,10 @@ stages: <<: *session_data_attributes details: <<: *session_data_attribute_details - currentStep: joggingSecondPipetteToPointOne - comparisonsByStep: - comparingFirstPipetteHeight: !anydict - comparingFirstPipettePointOne: !anydict - comparingFirstPipettePointTwo: !anydict - comparingFirstPipettePointThree: !anydict - comparingSecondPipetteHeight: !anydict + currentStep: comparingPointOne + comparisonsByPipette: + first: !anydict + second: !anydict - name: Compare second pipette to point one request: @@ -599,14 +635,10 @@ stages: <<: *session_data_attributes details: <<: *session_data_attribute_details - currentStep: comparingSecondPipettePointOne - comparisonsByStep: - comparingFirstPipetteHeight: !anydict - comparingFirstPipettePointOne: !anydict - comparingFirstPipettePointTwo: !anydict - comparingFirstPipettePointThree: !anydict - comparingSecondPipetteHeight: !anydict - comparingSecondPipettePointOne: !anydict + currentStep: comparingPointOne + comparisonsByPipette: + first: !anydict + second: !anydict - name: Go to next check request: @@ -615,7 +647,7 @@ stages: data: type: SessionCommand attributes: - command: goToNextCheck + command: moveToTiprack data: {} response: status_code: 200 @@ -631,14 +663,10 @@ stages: <<: *session_data_attributes details: <<: *session_data_attribute_details - currentStep: checkComplete - comparisonsByStep: - comparingFirstPipetteHeight: !anydict - comparingFirstPipettePointOne: !anydict - comparingFirstPipettePointTwo: !anydict - comparingFirstPipettePointThree: !anydict - comparingSecondPipetteHeight: !anydict - comparingSecondPipettePointOne: !anydict + currentStep: returningTip + comparisonsByPipette: + first: !anydict + second: !anydict - name: Delete the session request: diff --git a/robot-server/tests/robot/calibration/check/test_state_machine.py b/robot-server/tests/robot/calibration/check/test_state_machine.py index b5df75ca2276..51a20bcc6246 100644 --- a/robot-server/tests/robot/calibration/check/test_state_machine.py +++ b/robot-server/tests/robot/calibration/check/test_state_machine.py @@ -4,37 +4,39 @@ from robot_server.service.session.models.command import ( CalibrationCommand as CalCommand, DeckCalibrationCommand as DeckCommand, - CalibrationCommand as CheckCommand) + CheckCalibrationCommand as CheckCommand) from robot_server.robot.calibration.check.state_machine import \ CalibrationCheckStateMachine valid_commands: List[Tuple[str, str, str]] = [ (CalCommand.load_labware, 'sessionStarted', 'labwareLoaded'), (CalCommand.move_to_tip_rack, 'labwareLoaded', 'preparingPipette'), - (CalCommand.move_to_tip_rack, 'preparingPipette', 'preparingPipette'), (CalCommand.jog, 'preparingPipette', 'preparingPipette'), (CalCommand.pick_up_tip, 'preparingPipette', 'inspectingTip'), (CalCommand.invalidate_tip, 'inspectingTip', 'preparingPipette'), - (CalCommand.move_to_deck, 'inspectingTip', 'joggingToDeck'), - (CalCommand.jog, 'joggingToDeck', 'joggingToDeck'), - (CalCommand.save_offset, 'joggingToDeck', 'joggingToDeck'), - (CalCommand.move_to_point_one, 'joggingToDeck', 'savingPointOne'), - (CalCommand.jog, 'savingPointOne', 'savingPointOne'), - (CalCommand.save_offset, 'savingPointOne', 'savingPointOne'), - (DeckCommand.move_to_point_two, 'savingPointOne', 'savingPointTwo'), - (CalCommand.jog, 'savingPointTwo', 'savingPointTwo'), - (CalCommand.save_offset, 'savingPointTwo', 'savingPointTwo'), - (DeckCommand.move_to_point_three, 'savingPointTwo', 'savingPointThree'), - (CalCommand.jog, 'savingPointThree', 'savingPointThree'), - (CalCommand.save_offset, 'savingPointThree', 'savingPointThree'), - (CalCommand.move_to_tip_rack, 'savingPointThree', 'calibrationComplete'), + (CalCommand.move_to_deck, 'inspectingTip', 'comparingHeight'), + (CalCommand.jog, 'comparingHeight', 'comparingHeight'), + (CheckCommand.compare_point, 'comparingHeight', 'comparingHeight'), + (CalCommand.move_to_point_one, 'comparingHeight', 'comparingPointOne'), + (CalCommand.jog, 'comparingPointOne', 'comparingPointOne'), + (CheckCommand.compare_point, 'comparingPointOne', 'comparingPointOne'), + (DeckCommand.move_to_point_two, 'comparingPointOne', 'comparingPointTwo'), + (CalCommand.jog, 'comparingPointTwo', 'comparingPointTwo'), + (CheckCommand.compare_point, 'comparingPointTwo', 'comparingPointTwo'), + (DeckCommand.move_to_point_three, + 'comparingPointTwo', 'comparingPointThree'), + (CalCommand.jog, 'comparingPointThree', 'comparingPointThree'), + (CheckCommand.compare_point, 'comparingPointThree', 'comparingPointThree'), + (CalCommand.move_to_tip_rack, 'comparingPointThree', 'returningTip'), + (CheckCommand.return_tip, 'returningTip', 'returningTip'), + (CheckCommand.transition, 'returningTip', 'resultsSummary'), (CalCommand.exit, 'calibrationComplete', 'sessionExited'), (CalCommand.exit, 'sessionStarted', 'sessionExited'), (CalCommand.exit, 'labwareLoaded', 'sessionExited'), (CalCommand.exit, 'preparingPipette', 'sessionExited'), - (CalCommand.exit, 'savingPointOne', 'sessionExited'), - (CalCommand.exit, 'savingPointTwo', 'sessionExited'), - (CalCommand.exit, 'savingPointThree', 'sessionExited'), + (CalCommand.exit, 'comparingPointOne', 'sessionExited'), + (CalCommand.exit, 'comparingPointTwo', 'sessionExited'), + (CalCommand.exit, 'comparingPointThree', 'sessionExited'), ] diff --git a/robot-server/tests/robot/calibration/check/test_user_flow.py b/robot-server/tests/robot/calibration/check/test_user_flow.py index d9066886d5b2..1ff05b4740b7 100644 --- a/robot-server/tests/robot/calibration/check/test_user_flow.py +++ b/robot-server/tests/robot/calibration/check/test_user_flow.py @@ -1,15 +1,19 @@ from typing import List, Tuple -from unittest.mock import patch, call, MagicMock +from unittest.mock import call, MagicMock import pytest -from opentrons import types -from opentrons.hardware_control import ThreadManager +from opentrons.hardware_control import pipette from opentrons.types import Mount, Point from opentrons.calibration_storage import types as cal_types from opentrons.config import robot_configs - -from robot_server.robot.calibration.check.user_flow import CheckCalibrationUserFlow -from robot_server.robot.calibration.check.constants import CalibrationCheckState +from opentrons.config.pipette_config import load + +from robot_server.robot.calibration.check.user_flow import\ + CheckCalibrationUserFlow +from robot_server.robot.calibration.check.constants import\ + CalibrationCheckState +from robot_server.robot.calibration.check.models import\ + ComparisonStatus from robot_server.service.errors import RobotServerError from robot_server.robot.calibration.constants import ( POINT_ONE_ID, POINT_TWO_ID, POINT_THREE_ID) @@ -59,8 +63,8 @@ async def gantry_pos_mock(*args, **kwargs): pipette_combos: List[Tuple[List[str], Mount]] = [ (['p20_multi_v2.1', 'p20_multi_v2.1'], Mount.RIGHT), (['p20_single_v2.1', 'p20_multi_v2.1'], Mount.LEFT), - (['p20_multi_v2.1', 'p300_single_v2.1'], Mount.LEFT), - (['p300_multi_v2.1', 'p1000_single_v2.1'], Mount.LEFT), + (['p20_multi_v2.1', 'p300_single_v2.1'], Mount.RIGHT), + (['p300_multi_v2.1', 'p1000_single_v2.1'], Mount.RIGHT), (['p1000_single_v2.1', ''], Mount.LEFT), (['', 'p300_multi_v2.1'], Mount.RIGHT) ] @@ -86,9 +90,37 @@ def test_user_flow_select_pipette(pipettes, target_mount, hardware): hardware._attached_instruments[target_mount] +@pytest.mark.parametrize('pipettes,target_mount', pipette_combos) +async def test_switching_to_second_pipette(pipettes, target_mount, hardware): + pip, pip2 = None, None + if pipettes[0]: + pip = pipette.Pipette(load(pipettes[0], 'testId'), + {'single': [0, 0, 0], 'multi': [0, 0, 0]}, + PIP_OFFSET, + 'testId') + if pipettes[1]: + pip2 = pipette.Pipette(load(pipettes[1], 'testId'), + {'single': [0, 0, 0], 'multi': [0, 0, 0]}, + PIP_OFFSET, + 'testId2') + hardware._attached_instruments = {Mount.LEFT: pip, Mount.RIGHT: pip2} + uf = CheckCalibrationUserFlow(hardware=hardware) + if pip and pip2: + assert uf.mount == target_mount + await uf.change_active_pipette() + assert uf.mount != target_mount + else: + with pytest.raises(RobotServerError): + await uf.change_active_pipette() + + @pytest.fixture def mock_user_flow(mock_hw): m = CheckCalibrationUserFlow(hardware=mock_hw) + initial_pt = Point(1, 1, 5) + final_pt = Point(1, 1, 0) + m._get_reference_points_by_state =\ + MagicMock(return_value=(initial_pt, final_pt)) yield m @@ -96,7 +128,7 @@ async def test_move_to_tip_rack(mock_user_flow): uf = mock_user_flow await uf.move_to_tip_rack() cur_pt = await uf._get_current_point(None) - assert cur_pt == uf._tip_rack.wells()[0].top().point + Point(0, 0, 10) + assert cur_pt == uf.active_tiprack.wells()[0].top().point + Point(0, 0, 10) async def test_pick_up_tip(mock_user_flow): @@ -104,31 +136,9 @@ async def test_pick_up_tip(mock_user_flow): assert uf._tip_origin_pt is None await uf.move_to_tip_rack() cur_pt = await uf._get_current_point(None) + await uf.jog(vector=(0, 0, 1)) await uf.pick_up_tip() - assert uf._tip_origin_pt == cur_pt - - -async def test_save_default_pick_up_current(mock_hw): - # make sure pick up current for multi-channels is - # modified during tip pick up - pip = pipette.Pipette(load("p20_multi_v2.1", 'testId'), - {'single': [0, 0, 0], 'multi': [0, 0, 0]}, - PIP_OFFSET, - 'testid') - mock_hw._attached_instruments[Mount.LEFT] = pip - uf = CheckCalibrationUserFlow(hardware=mock_hw) - - def mock_update_config_item(*args, **kwargs): - pass - - uf._hw_pipette.update_config_item = MagicMock( - side_effect=mock_update_config_item) - default_current = pip.config.pick_up_current - update_config_calls = [ - call('pick_up_current', 0.1), - call('pick_up_current', default_current)] - await uf.pick_up_tip() - uf._hw_pipette.update_config_item.assert_has_calls(update_config_calls) + assert uf._tip_origin_pt == cur_pt + Point(0, 0, 1) async def test_return_tip(mock_user_flow): @@ -160,9 +170,9 @@ async def test_jog(mock_user_flow): @pytest.mark.parametrize( "state,point_id", [ - (CalibrationCheckState.comparingPointOne, POINT_ONE_ID), - (CalibrationCheckState.comparingPointTwo, POINT_TWO_ID), - (CalibrationCheckState.comparingPointThree, POINT_THREE_ID)]) + (CalibrationCheckState.comparingHeight, POINT_ONE_ID), + (CalibrationCheckState.comparingPointOne, POINT_TWO_ID), + (CalibrationCheckState.comparingPointTwo, POINT_THREE_ID)]) async def test_get_move_to_cal_point_location(mock_user_flow, state, point_id): uf = mock_user_flow @@ -175,15 +185,75 @@ async def test_get_move_to_cal_point_location(mock_user_flow, assert uf._get_move_to_point_loc_by_state().point == exp -async def test_save_z_height(mock_user_flow): +async def test_compare_z_height(mock_user_flow): uf = mock_user_flow uf._current_state = CalibrationCheckState.comparingHeight - assert uf._z_height_reference is None + await uf._hardware.move_to( + mount=uf._mount, + abs_position=Point(x=10, y=10, z=10), + critical_point=uf._hw_pipette.critical_point + ) + await uf.update_comparison_map() + # The initial and final mocked points have a 5 mm + # difference and so it should exceed the threshold + expected_status = ComparisonStatus( + differenceVector=(0.0, 0.0, -5.0), + thresholdVector=(0.0, 0.0, 0.8), + exceedsThreshold=True, + transformType='BAD_DECK_TRANSFORM') + assert uf.comparison_map.first.comparingHeight == expected_status + assert uf.comparison_map.second.comparingHeight is None + + +async def test_compare_points(mock_user_flow): + uf = mock_user_flow + uf._current_state = CalibrationCheckState.comparingPointOne + expected_status = ComparisonStatus( + differenceVector=(0.0, 0.0, -5.0), + thresholdVector=(1.8, 1.8, 0.0), + exceedsThreshold=False, + transformType='UNKNOWN') await uf._hardware.move_to( mount=uf._mount, abs_position=Point(x=10, y=10, z=10), critical_point=uf._hw_pipette.critical_point ) - await uf.save_offset() - assert uf._z_height_reference == 10 + await uf.update_comparison_map() + + assert uf.comparison_map.first.comparingPointOne == expected_status + assert uf.comparison_map.second.comparingPointOne is None + + uf._current_state = CalibrationCheckState.comparingPointTwo + await uf._hardware.move_to( + mount=uf._mount, + abs_position=Point(x=10, y=10, z=10), + critical_point=uf._hw_pipette.critical_point + ) + await uf.update_comparison_map() + assert uf.comparison_map.first.comparingPointTwo == expected_status + assert uf.comparison_map.second.comparingPointTwo is None + + uf._current_state = CalibrationCheckState.comparingPointThree + await uf._hardware.move_to( + mount=uf._mount, + abs_position=Point(x=10, y=10, z=10), + critical_point=uf._hw_pipette.critical_point + ) + await uf.update_comparison_map() + + assert uf.comparison_map.first.comparingPointThree == expected_status + assert uf.comparison_map.second.comparingPointThree is None + + await uf.change_active_pipette() + + uf._current_state = CalibrationCheckState.comparingPointOne + await uf._hardware.move_to( + mount=uf._mount, + abs_position=Point(x=10, y=10, z=10), + critical_point=uf._hw_pipette.critical_point + ) + await uf.update_comparison_map() + + assert uf.comparison_map.first.comparingPointOne == expected_status + assert uf.comparison_map.second.comparingPointOne == expected_status