Skip to content

Commit 3707ec4

Browse files
committed
better error messages and tests for new ones
1 parent 7cb6bcc commit 3707ec4

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

api/src/opentrons/protocol_api/labware.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,7 +1166,11 @@ def load_liquid(
11661166
well_names.append(well.well_name)
11671167
else:
11681168
raise TypeError(
1169-
"The elements of wells should be Well instances or well names."
1169+
f"Unexpected type for element {repr(well)}. The elements of wells should be Well instances or well names."
1170+
)
1171+
if not isinstance(volume, (float, int)):
1172+
raise TypeError(
1173+
f"Unexpected type for volume {repr(volume)}. Volume should be a number in microliters."
11701174
)
11711175
self._core.load_liquid({well_name: volume for well_name in well_names}, liquid)
11721176

@@ -1211,7 +1215,11 @@ def load_liquid_by_well(
12111215
verified_volumes[well.well_name] = volume
12121216
else:
12131217
raise TypeError(
1214-
"The elements of wells should be Well instances or well names."
1218+
f"Unexpected type for well name {repr(well)}. The keys of volumes should be Well instances or well names."
1219+
)
1220+
if not isinstance(volume, (float, int)):
1221+
raise TypeError(
1222+
f"Unexpected type for volume {repr(volume)}. The values of volumes should be numbers in microliters."
12151223
)
12161224
self._core.load_liquid(verified_volumes, liquid)
12171225

@@ -1235,18 +1243,18 @@ def load_empty(self, wells: Sequence[Union[Well, str]]) -> None:
12351243
if isinstance(well, str):
12361244
if well not in self:
12371245
raise KeyError(
1238-
"The elements of wells should name wells in this labware."
1246+
f"{well} is not a well in {self.name}. The elements of wells should name wells in this labware."
12391247
)
12401248
well_names.append(well)
12411249
elif isinstance(well, Well):
12421250
if well.parent is not self:
12431251
raise KeyError(
1244-
"The elements of wells should be wells of this labware."
1252+
f"{well.well_name} is not a well in {self.name}. The elements of wells should be wells of this labware."
12451253
)
12461254
well_names.append(well.well_name)
12471255
else:
12481256
raise TypeError(
1249-
"The elements of wells should be Well instances or well names."
1257+
f"Unexpected type for well name {repr(well)}. The elements of wells should be Well instances or well names."
12501258
)
12511259
self._core.load_empty(well_names)
12521260

api/tests/opentrons/protocol_api/test_labware.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,8 @@ def test_load_liquid_rejects_invalid_inputs(
467467
with pytest.raises(TypeError):
468468
subject.load_liquid([2], 10, mock_liquid) # type: ignore[list-item]
469469

470+
with pytest.raises(TypeError):
471+
subject.load_liquid(["A1"], "A1", mock_liquid) # type: ignore[arg-type]
470472
mock_liquid = decoy.mock(cls=Liquid)
471473

472474
subject.load_liquid(["A1", subject["B1"]], 10, mock_liquid)
@@ -587,6 +589,9 @@ def test_load_liquid_by_well_rejects_invalid_inputs(
587589
with pytest.raises(TypeError):
588590
subject.load_liquid_by_well({2: 10}, mock_liquid) # type: ignore[dict-item]
589591

592+
with pytest.raises(TypeError):
593+
subject.load_liquid_by_well({"A1": "A3"}, mock_liquid) # type: ignore[dict-item]
594+
590595

591596
@pytest.mark.parametrize("api_version", versions_at_or_above(APIVersion(2, 22)))
592597
def test_load_empty_handles_valid_inputs(

0 commit comments

Comments
 (0)