Skip to content

Commit ff83a57

Browse files
committed
fix api tests
1 parent 528a825 commit ff83a57

File tree

5 files changed

+8
-15
lines changed

5 files changed

+8
-15
lines changed

api/src/opentrons/calibration_storage/file_operators.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def save_to_file(
112112

113113
def serialize_pydantic_model(data: pydantic.BaseModel) -> bytes:
114114
"""Safely serialize data from a Pydantic model into a form suitable for storing on disk."""
115-
return data.json(by_alias=True).encode("utf-8")
115+
return data.model_dump_json(by_alias=True).encode("utf-8")
116116

117117

118118
_ModelT = typing.TypeVar("_ModelT", bound=pydantic.BaseModel)
@@ -133,7 +133,7 @@ def deserialize_pydantic_model(
133133
Returns `None` if the file is missing or corrupt.
134134
"""
135135
try:
136-
return model.parse_raw(serialized)
136+
return model.model_validate_json(serialized)
137137
except json.JSONDecodeError:
138138
_log.warning("Data is not valid JSON.", exc_info=True)
139139
return None

api/src/opentrons/protocol_engine/commands/custom.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
If you are implementing a custom command, you should probably
1111
put your own disambiguation identifier in the payload.
1212
"""
13-
from pydantic import ConfigDict, BaseModel
13+
from pydantic import ConfigDict, BaseModel, SerializeAsAny
1414
from typing import Optional, Type
1515
from typing_extensions import Literal
1616

@@ -47,7 +47,7 @@ class Custom(BaseCommand[CustomParams, CustomResult]):
4747
"""Custom command model."""
4848

4949
commandType: CustomCommandType = "custom"
50-
params: CustomParams
50+
params: SerializeAsAny[CustomParams]
5151
result: Optional[CustomResult] = None
5252

5353
_ImplementationCls: Type[CustomImplementation] = CustomImplementation

api/src/opentrons/protocol_runner/legacy_command_mapper.py

+3-9
Original file line numberDiff line numberDiff line change
@@ -408,9 +408,7 @@ def _build_pick_up_tip(
408408
wellName=well_name,
409409
),
410410
)
411-
create = pe_commands.PickUpTipCreate(
412-
key=running.key, params=running.params
413-
)
411+
create = pe_commands.PickUpTipCreate(key=running.key, params=running.params)
414412
return create, running
415413

416414
def _build_liquid_handling(
@@ -521,9 +519,7 @@ def _build_liquid_handling(
521519
legacyCommandText=command["payload"]["text"],
522520
),
523521
)
524-
create = pe_commands.CustomCreate(
525-
key=running.key, params=running.params
526-
)
522+
create = pe_commands.CustomCreate(key=running.key, params=running.params)
527523
return create, running
528524

529525
def _build_blow_out(
@@ -597,9 +593,7 @@ def _map_labware_load(
597593
slot = labware_load_info.deck_slot
598594
location: pe_types.LabwareLocation
599595
if labware_load_info.on_module:
600-
location = pe_types.ModuleLocation(
601-
moduleId=self._module_id_by_slot[slot]
602-
)
596+
location = pe_types.ModuleLocation(moduleId=self._module_id_by_slot[slot])
603597
else:
604598
location = pe_types.DeckSlotLocation(slotName=slot)
605599

api/tests/opentrons/calibration_storage/test_file_operators.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def test_deserialize_pydantic_model_valid() -> None:
8484
serialized = b'{"integer_field": 123, "! aliased field !": "abc"}'
8585
assert io.deserialize_pydantic_model(
8686
serialized, DummyModel
87-
) == DummyModel(integer_field=123, aliased_field="abc")
87+
) == DummyModel.model_construct(integer_field=123, aliased_field="abc")
8888

8989

9090
def test_deserialize_pydantic_model_invalid_as_json() -> None:

api/tests/opentrons/cli/test_cli.py

-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ def test_analyze(
6363
) -> None:
6464
"""Should return with no errors and a non-empty output."""
6565
result = _get_analysis_result([fixture_path])
66-
6766
assert result.exit_code == 0
6867

6968
assert result.json_output is not None

0 commit comments

Comments
 (0)