Skip to content

Commit

Permalink
fix api tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ahiuchingau committed Apr 11, 2024
1 parent 528a825 commit ff83a57
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 15 deletions.
4 changes: 2 additions & 2 deletions api/src/opentrons/calibration_storage/file_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def save_to_file(

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


_ModelT = typing.TypeVar("_ModelT", bound=pydantic.BaseModel)
Expand All @@ -133,7 +133,7 @@ def deserialize_pydantic_model(
Returns `None` if the file is missing or corrupt.
"""
try:
return model.parse_raw(serialized)
return model.model_validate_json(serialized)
except json.JSONDecodeError:
_log.warning("Data is not valid JSON.", exc_info=True)
return None
Expand Down
4 changes: 2 additions & 2 deletions api/src/opentrons/protocol_engine/commands/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
If you are implementing a custom command, you should probably
put your own disambiguation identifier in the payload.
"""
from pydantic import ConfigDict, BaseModel
from pydantic import ConfigDict, BaseModel, SerializeAsAny
from typing import Optional, Type
from typing_extensions import Literal

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

commandType: CustomCommandType = "custom"
params: CustomParams
params: SerializeAsAny[CustomParams]
result: Optional[CustomResult] = None

_ImplementationCls: Type[CustomImplementation] = CustomImplementation
Expand Down
12 changes: 3 additions & 9 deletions api/src/opentrons/protocol_runner/legacy_command_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,9 +408,7 @@ def _build_pick_up_tip(
wellName=well_name,
),
)
create = pe_commands.PickUpTipCreate(
key=running.key, params=running.params
)
create = pe_commands.PickUpTipCreate(key=running.key, params=running.params)
return create, running

def _build_liquid_handling(
Expand Down Expand Up @@ -521,9 +519,7 @@ def _build_liquid_handling(
legacyCommandText=command["payload"]["text"],
),
)
create = pe_commands.CustomCreate(
key=running.key, params=running.params
)
create = pe_commands.CustomCreate(key=running.key, params=running.params)
return create, running

def _build_blow_out(
Expand Down Expand Up @@ -597,9 +593,7 @@ def _map_labware_load(
slot = labware_load_info.deck_slot
location: pe_types.LabwareLocation
if labware_load_info.on_module:
location = pe_types.ModuleLocation(
moduleId=self._module_id_by_slot[slot]
)
location = pe_types.ModuleLocation(moduleId=self._module_id_by_slot[slot])
else:
location = pe_types.DeckSlotLocation(slotName=slot)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def test_deserialize_pydantic_model_valid() -> None:
serialized = b'{"integer_field": 123, "! aliased field !": "abc"}'
assert io.deserialize_pydantic_model(
serialized, DummyModel
) == DummyModel(integer_field=123, aliased_field="abc")
) == DummyModel.model_construct(integer_field=123, aliased_field="abc")


def test_deserialize_pydantic_model_invalid_as_json() -> None:
Expand Down
1 change: 0 additions & 1 deletion api/tests/opentrons/cli/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ def test_analyze(
) -> None:
"""Should return with no errors and a non-empty output."""
result = _get_analysis_result([fixture_path])

assert result.exit_code == 0

assert result.json_output is not None
Expand Down

0 comments on commit ff83a57

Please sign in to comment.