Skip to content

Commit

Permalink
WIP read missing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TamarZanzouri committed Dec 19, 2024
1 parent efd2eba commit 238f675
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async def test_absorbance_reader_implementation(

params = InitializeParams(
moduleId="unverified-module-id",
measureMode=input_measure_mode,
measureMode=input_measure_mode, # type: ignore[arg-type]
sampleWavelengths=input_sample_wave_length,
)

Expand Down Expand Up @@ -75,7 +75,7 @@ async def test_absorbance_reader_implementation(
module_id="unverified-module-id",
module_type="absorbanceReaderType",
initialize_absorbance_reader_update=update_types.AbsorbanceReaderInitializeUpdate(
measure_mode=input_measure_mode,
measure_mode=input_measure_mode, # type: ignore[arg-type]
sample_wave_lengths=input_sample_wave_length,
reference_wave_length=None,
),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
"""Test absorbance reader initilize command."""
import pytest
from decoy import Decoy
from typing import List

from opentrons.drivers.types import ABSMeasurementMode
from opentrons.hardware_control.modules import AbsorbanceReader

from opentrons.protocol_engine.execution import EquipmentHandler
from opentrons.protocol_engine.resources import FileProvider
from opentrons.protocol_engine.state import update_types
from opentrons.protocol_engine.state.state import StateView
from opentrons.protocol_engine.state.module_substates import (
AbsorbanceReaderSubState,
AbsorbanceReaderId,
)
from opentrons.protocol_engine.commands.command import SuccessData
from opentrons.protocol_engine.commands.absorbance_reader import (
ReadAbsorbanceResult,
ReadAbsorbanceParams,
)
from opentrons.protocol_engine.commands.absorbance_reader.read import (
ReadAbsorbanceImpl,
)


async def test_absorbance_reader_implementation(
decoy: Decoy,
state_view: StateView,
equipment: EquipmentHandler,
file_provider: FileProvider,
) -> None:
"""It should validate, find hardware module if not virtualized, and disengage."""
subject = ReadAbsorbanceImpl(
state_view=state_view, equipment=equipment, file_provider=file_provider
)

params = ReadAbsorbanceParams(
moduleId="unverified-module-id",
)

mabsorbance_module_substate = decoy.mock(cls=AbsorbanceReaderSubState)
absorbance_module_hw = decoy.mock(cls=AbsorbanceReader)
verified_module_id = AbsorbanceReaderId("module-id")

decoy.when(
state_view.modules.get_absorbance_reader_substate("unverified-module-id")
).then_return(mabsorbance_module_substate)

decoy.when(mabsorbance_module_substate.module_id).then_return(verified_module_id)

decoy.when(equipment.get_module_hardware_api(verified_module_id)).then_return(
absorbance_module_hw
)

result = await subject.execute(params=params)

decoy.verify(
await absorbance_module_hw.start_measure(),
times=1,
)
assert result == SuccessData(
public=ReadAbsorbanceResult(),
state_update=update_types.StateUpdate(
module_state_update=update_types.ModuleStateUpdate(
module_id="unverified-module-id",
module_type="absorbanceReaderType",
absorbance_reader_data=update_types.AbsorbanceReaderDataUpdate(),
)
),
)
7 changes: 7 additions & 0 deletions api/tests/opentrons/protocol_engine/commands/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
TipHandler,
GantryMover,
)
from opentrons.protocol_engine.resources import FileProvider
from opentrons.protocol_engine.resources.model_utils import ModelUtils
from opentrons.protocol_engine.state.state import StateView

Expand Down Expand Up @@ -83,3 +84,9 @@ def status_bar(decoy: Decoy) -> StatusBarHandler:
def gantry_mover(decoy: Decoy) -> GantryMover:
"""Get a mocked out GantryMover."""
return decoy.mock(cls=GantryMover)


@pytest.fixture
def file_provider(decoy: Decoy) -> FileProvider:
"""Get a mocked out StateView."""
return decoy.mock(cls=FileProvider)

0 comments on commit 238f675

Please sign in to comment.