Skip to content

Commit

Permalink
execute_json fixes. 275 remaining
Browse files Browse the repository at this point in the history
  • Loading branch information
aaron-kulkarni committed Jul 31, 2024
1 parent ecc6433 commit 5d6a2bc
Show file tree
Hide file tree
Showing 5 changed files with 275 additions and 138 deletions.
25 changes: 15 additions & 10 deletions api/src/opentrons/protocols/execution/execute_json_v4.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
ModuleContext,
ThermocyclerContext,
)
from opentrons_shared_data.protocol.types import (
MagneticModuleCommand,
TemperatureModuleCommand,
ThermocyclerCommand,
)
from .execute_json_v3 import _delay, _move_to_slot
from opentrons.protocols.execution.types import LoadedLabware, Instruments
from opentrons_shared_data.protocol.constants import (
Expand Down Expand Up @@ -277,21 +282,21 @@ def dispatch_json(
params, # type: ignore
modules,
command_type, # type: ignore
magnetic_module_command_map,
magnetic_module_command_map, # type: ignore[arg-type]
)
elif command_type in temperature_module_command_map:
handleTemperatureCommand(
params, # type: ignore
params, # type: ignore[arg-type]
modules,
command_type, # type: ignore
temperature_module_command_map,
temperature_module_command_map, # type: ignore[arg-type]
)
elif command_type in thermocycler_module_command_map:
handleThermocyclerCommand(
params, # type: ignore
modules, # type: ignore
command_type, # type: ignore
thermocycler_module_command_map,
thermocycler_module_command_map, # type: ignore[arg-type]
)
elif command_item["command"] == JsonRobotCommand.delay.value:
_delay(context, params) # type: ignore
Expand All @@ -305,12 +310,12 @@ def handleTemperatureCommand(
params: Union["TemperatureParams", "ModuleIDParams"],
modules: Dict[str, ModuleContext],
command_type: "TemperatureModuleCommandId",
temperature_module_command_map,
temperature_module_command_map: TemperatureModuleCommand,
) -> None:
module_id = params["module"]
module = modules[module_id]
if isinstance(module, TemperatureModuleContext):
temperature_module_command_map[command_type](module, params)
temperature_module_command_map[command_type](module, params) # type: ignore[typeddict-item]
else:
raise RuntimeError(
"Temperature Module does not match " + "TemperatureModuleContext interface"
Expand All @@ -326,12 +331,12 @@ def handleThermocyclerCommand(
],
modules: Dict[str, ThermocyclerContext],
command_type: "ThermocyclerCommandId",
thermocycler_module_command_map,
thermocycler_module_command_map: ThermocyclerCommand,
) -> None:
module_id = params["module"]
module = modules[module_id]
if isinstance(module, ThermocyclerContext):
thermocycler_module_command_map[command_type](module, params)
thermocycler_module_command_map[command_type](module, params) # type: ignore[typeddict-item]
else:
raise RuntimeError(
"Thermocycler Module does not match ThermocyclerContext interface"
Expand All @@ -342,12 +347,12 @@ def handleMagnetCommand(
params: Union["ModuleIDParams", "MagneticModuleEngageParams"],
modules: Dict[str, ModuleContext],
command_type: "MagneticModuleCommandId",
magnetic_module_command_map,
magnetic_module_command_map: MagneticModuleCommand,
) -> None:
module_id = params["module"]
module = modules[module_id]
if isinstance(module, MagneticModuleContext):
magnetic_module_command_map[command_type](module, params)
magnetic_module_command_map[command_type](module, params) # type: ignore[typeddict-item]
else:
raise RuntimeError(
"Magnetic Module does not match MagneticModuleContext interface"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import asyncio
import sys
from typing import AsyncGenerator
from typing import AsyncGenerator, List

import anyio
import pytest

from opentrons.hardware_control import ExecutionManager
from opentrons.hardware_control.emulation.settings import Settings
from opentrons.hardware_control.modules import Thermocycler
from opentrons.hardware_control.modules.types import TemperatureStatus
from opentrons.hardware_control.modules.types import TemperatureStatus, ThermocyclerStep

from .build_module import build_module

Expand Down Expand Up @@ -95,7 +95,7 @@ async def test_cycle_temperatures(thermocycler: Thermocycler) -> None:
assert thermocycler.total_cycle_count is None
assert thermocycler.total_step_count is None

steps = [
steps: list[ThermocyclerStep] = [
{
"temperature": 70.0,
},
Expand Down Expand Up @@ -164,7 +164,7 @@ async def test_cycle_cannot_be_interrupted_by_pause(
# This list must be long enough that we can reliably target a pause somewhere
# in the middle of it, but not so long that makes the test take a disruptively
# long time.
steps = [
steps: list[ThermocyclerStep] = [
{"temperature": temp_1, "hold_time_seconds": poll_interval_seconds * 2},
{"temperature": temp_2, "hold_time_seconds": poll_interval_seconds * 2},
{"temperature": temp_1, "hold_time_seconds": poll_interval_seconds * 2},
Expand Down Expand Up @@ -227,7 +227,7 @@ async def test_cycle_can_be_blocked_by_preexisting_pause(
# as an approximation of asserting that it blocks forever.
with pytest.raises(TimeoutError):
with anyio.fail_after(0.5):
steps = [{"temperature": temp_2}]
steps: List[ThermocyclerStep] = [{"temperature": temp_2}]
await thermocycler.cycle_temperatures(steps=steps, repetitions=1)

# Assert that the cycle didn't have any effect.
Expand All @@ -240,7 +240,7 @@ async def test_cycle_can_be_cancelled(
execution_manager: ExecutionManager,
) -> None:
"""A cycle should be cancellable (even though it isn't pausable)."""
steps = [
steps: List[ThermocyclerStep] = [
{"temperature": 20.0, "hold_time_minutes": 99999},
]

Expand Down
Loading

0 comments on commit 5d6a2bc

Please sign in to comment.