Skip to content

Commit

Permalink
added missing tests for initialize - need to fix lint and add raising…
Browse files Browse the repository at this point in the history
… errors
  • Loading branch information
TamarZanzouri committed Dec 18, 2024
1 parent 92fa9b4 commit efd2eba
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ async def execute(self, params: InitializeParams) -> SuccessData[InitializeResul
)

state_update.initialize_absorbance_reader(
params.moduleId,
params.moduleId, # should this be the verified id?
params.measureMode,
params.sampleWavelengths,
params.referenceWavelength,
Expand Down
13 changes: 7 additions & 6 deletions api/src/opentrons/protocol_engine/state/update_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,12 +630,13 @@ def initialize_absorbance_reader(
reference_wave_length: typing.Optional[int],
) -> Self:
self.module_state_update = ModuleStateUpdate(
module_id=module_id, module_type="absorbanceReaderType"
)
self.initialize_absorbance_reader_update = AbsorbanceReaderInitializeUpdate(
measure_mode=measure_mode,
sample_wave_lengths=sample_wave_lengths,
reference_wave_length=reference_wave_length,
module_id=module_id,
module_type="absorbanceReaderType",
initialize_absorbance_reader_update=AbsorbanceReaderInitializeUpdate(
measure_mode=measure_mode,
sample_wave_lengths=sample_wave_lengths,
reference_wave_length=reference_wave_length,
),
)
return self

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
"""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.state import update_types
from opentrons.protocol_engine.state.state import StateView
from opentrons.protocol_engine.state.module_substates import (
AbsorbanceReaderSubState,
Expand All @@ -19,16 +23,23 @@
)


@pytest.mark.parametrize(
"input_sample_wave_length, input_measure_mode", [([1, 2], "multi"), ([1], "single")]
)
async def test_absorbance_reader_implementation(
decoy: Decoy,
state_view: StateView,
equipment: EquipmentHandler,
input_sample_wave_length: List[int],
input_measure_mode: str,
) -> None:
"""It should validate, find hardware module if not virtualized, and disengage."""
subject = InitializeImpl(state_view=state_view, equipment=equipment)

params = InitializeParams(
moduleId="unverified-module-id", measureMode="single", sampleWavelengths=[1, 2]
moduleId="unverified-module-id",
measureMode=input_measure_mode,
sampleWavelengths=input_sample_wave_length,
)

mabsorbance_module_substate = decoy.mock(cls=AbsorbanceReaderSubState)
Expand All @@ -45,7 +56,29 @@ async def test_absorbance_reader_implementation(
absorbance_module_hw
)

decoy.when((absorbance_module_hw.supported_wavelengths)).then_return([1, 2])

result = await subject.execute(params=params)

decoy.verify(await absorbance_module_hw.set_sample_wavelength(), times=1)
assert result == SuccessData(public=InitializeResult())
decoy.verify(
await absorbance_module_hw.set_sample_wavelength(
ABSMeasurementMode(params.measureMode),
params.sampleWavelengths,
reference_wavelength=params.referenceWavelength,
),
times=1,
)
assert result == SuccessData(
public=InitializeResult(),
state_update=update_types.StateUpdate(
module_state_update=update_types.ModuleStateUpdate(
module_id="unverified-module-id",
module_type="absorbanceReaderType",
initialize_absorbance_reader_update=update_types.AbsorbanceReaderInitializeUpdate(
measure_mode=input_measure_mode,
sample_wave_lengths=input_sample_wave_length,
reference_wave_length=None,
),
)
),
)

0 comments on commit efd2eba

Please sign in to comment.