Skip to content

Commit

Permalink
fix(api): Fix RuntimeError when calling InstrumentContext.type on a 9…
Browse files Browse the repository at this point in the history
…6-channel (#14186)
  • Loading branch information
SyntaxColoring authored Dec 13, 2023
1 parent 165a607 commit b1d774d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
18 changes: 11 additions & 7 deletions api/src/opentrons/protocol_api/instrument_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -1492,14 +1492,15 @@ def flow_rate(self) -> "FlowRates":
@property # type: ignore
@requires_version(2, 0)
def type(self) -> str:
"""One of ``'single'`` or ``'multi'``."""
model = self.name
if "single" in model:
"""``'single'`` if this is a 1-channel pipette, or ``'multi'`` otherwise.
See also :py:obj:`.channels`, which can distinguish between 8-channel and 96-channel
pipettes.
"""
if self.channels == 1:
return "single"
elif "multi" in model:
return "multi"
else:
raise RuntimeError("Bad pipette name: {}".format(model))
return "multi"

@property # type: ignore
@requires_version(2, 0)
Expand Down Expand Up @@ -1630,7 +1631,10 @@ def hw_pipette(self) -> PipetteDict:
def channels(self) -> int:
"""The number of channels on the pipette.
Possible values are 1, 8, or 96."""
Possible values are 1, 8, or 96.
See also :py:obj:`.type`.
"""
return self._core.get_channels()

@property # type: ignore
Expand Down
32 changes: 32 additions & 0 deletions api/tests/opentrons/protocol_api/test_instrument_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,38 @@ def test_api_version(api_version: APIVersion, subject: InstrumentContext) -> Non
assert subject.api_version == api_version


@pytest.mark.parametrize("channels_from_core", [1, 8, 96])
def test_channels(
decoy: Decoy,
subject: InstrumentContext,
mock_instrument_core: InstrumentCore,
channels_from_core: int,
) -> None:
"""It should return the number of channels, as returned by the core."""
decoy.when(mock_instrument_core.get_channels()).then_return(channels_from_core)
assert subject.channels == channels_from_core


@pytest.mark.parametrize(
("channels_from_core", "expected_type"),
[
(1, "single"),
(8, "multi"),
(96, "multi"),
],
)
def test_type(
decoy: Decoy,
subject: InstrumentContext,
mock_instrument_core: InstrumentCore,
channels_from_core: int,
expected_type: str,
) -> None:
"""It should map the number of channels from the core into the string "single" or "multi"."""
decoy.when(mock_instrument_core.get_channels()).then_return(channels_from_core)
assert subject.type == expected_type


def test_trash_container(
decoy: Decoy,
mock_trash: Labware,
Expand Down

0 comments on commit b1d774d

Please sign in to comment.