Skip to content

Commit

Permalink
moved build method inside orchestrator
Browse files Browse the repository at this point in the history
  • Loading branch information
TamarZanzouri committed May 7, 2024
1 parent 12f6fd1 commit b57b38c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 54 deletions.
43 changes: 15 additions & 28 deletions api/src/opentrons/protocol_runner/run_orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,11 @@ class RunOrchestrator:

def __init__(
self,
setup_runner: protocol_runner.AnyRunner,
fixit_runner: protocol_runner.AnyRunner,
json_or_python_runner: Optional[protocol_runner.AnyRunner] = None,
protocol_engine: ProtocolEngine,
hardware_api: HardwareControlAPI,
) -> None:
# todo(tamar, 5-7-24): assert that the type matches expected type
self._setup_runner = setup_runner
self._fixit_runner = fixit_runner
self._json_or_python_runner = json_or_python_runner
self._protocol_engine = protocol_engine
self._hardware_api = hardware_api

def add_command(
self, request: CommandCreate, failed_command_id: Optional[str] = None
Expand Down Expand Up @@ -69,40 +66,30 @@ def add_command(
):
self._json_or_python_runner.set_command_queued(request)


@dataclass
class RunOrchestratorProvider:
@staticmethod
def build_orchestrator(
self,
protocol_config: Optional[Union[JsonProtocolConfig, PythonProtocolConfig]],
protocol_engine: ProtocolEngine,
hardware_api: HardwareControlAPI,
post_run_hardware_state: PostRunHardwareState = PostRunHardwareState.HOME_AND_STAY_ENGAGED,
drop_tips_after_run: bool = True,
):
setup_runner = protocol_runner.create_protocol_runner(
protocol_engine=protocol_engine,
hardware_api=hardware_api,
self._setup_runner = protocol_runner.create_protocol_runner(
protocol_engine=self._protocol_engine,
hardware_api=self._hardware_api,
post_run_hardware_state=post_run_hardware_state,
drop_tips_after_run=drop_tips_after_run,
)
fixit_runner = protocol_runner.create_protocol_runner(
protocol_engine=protocol_engine,
hardware_api=hardware_api,
self._fixit_runner = protocol_runner.create_protocol_runner(
protocol_engine=self._protocol_engine,
hardware_api=self._hardware_api,
post_run_hardware_state=post_run_hardware_state,
drop_tips_after_run=drop_tips_after_run,
)
json_or_python_runner = None

if protocol_config:
json_or_python_runner = protocol_runner.create_protocol_runner(
self._json_or_python_runner = protocol_runner.create_protocol_runner(
protocol_config=protocol_config,
protocol_engine=protocol_engine,
hardware_api=hardware_api,
protocol_engine=self._protocol_engine,
hardware_api=self._hardware_api,
post_run_hardware_state=post_run_hardware_state,
drop_tips_after_run=drop_tips_after_run,
)
return RunOrchestrator(
setup_runner=setup_runner,
fixit_runner=fixit_runner,
json_or_python_runner=json_or_python_runner,
)
5 changes: 1 addition & 4 deletions api/tests/opentrons/protocol_runner/test_run_orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ def mock_protocol_json_runner(decoy: Decoy) -> JsonRunner:
)
from opentrons.hardware_control import API as HardwareAPI
from opentrons.protocol_reader import JsonProtocolConfig, PythonProtocolConfig
from opentrons.protocol_runner.run_orchestrator import (
RunOrchestrator,
RunOrchestratorProvider,
)
from opentrons.protocol_runner.run_orchestrator import RunOrchestrator
from opentrons.protocol_runner.protocol_runner import (
JsonRunner,
PythonAndLegacyRunner,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
)
from opentrons.hardware_control import API as HardwareAPI
from opentrons.protocol_reader import JsonProtocolConfig, PythonProtocolConfig
from opentrons.protocol_runner.run_orchestrator import (
RunOrchestrator,
RunOrchestratorProvider,
)
from opentrons.protocol_runner.run_orchestrator import RunOrchestrator
from opentrons import protocol_runner
from opentrons.protocol_runner.protocol_runner import (
JsonRunner,
Expand Down Expand Up @@ -46,7 +43,13 @@ def mock_protocol_json_runner(decoy: Decoy) -> JsonRunner:


@pytest.fixture
def mock_live_runner(decoy: Decoy) -> LiveRunner:
def mock_setup_runner(decoy: Decoy) -> LiveRunner:
"""Get a mocked out LiveRunner dependency."""
return decoy.mock(cls=LiveRunner)


@pytest.fixture
def mock_fixit_runner(decoy: Decoy) -> LiveRunner:
"""Get a mocked out LiveRunner dependency."""
return decoy.mock(cls=LiveRunner)

Expand All @@ -64,8 +67,13 @@ def mock_hardware_api(decoy: Decoy) -> HardwareAPI:


@pytest.fixture
def subject() -> RunOrchestratorProvider:
return RunOrchestratorProvider()
def subject(
mock_protocol_engine: ProtocolEngine, mock_hardware_api: HardwareAPI
) -> RunOrchestrator:
return RunOrchestrator(
protocol_engine=mock_protocol_engine,
hardware_api=mock_hardware_api,
)


@pytest.mark.parametrize(
Expand All @@ -84,26 +92,31 @@ def subject() -> RunOrchestratorProvider:
)
def test_build_run_orchestrator_provider(
decoy: Decoy,
subject: RunOrchestratorProvider,
subject: RunOrchestrator,
mock_protocol_engine: ProtocolEngine,
mock_hardware_api: HardwareAPI,
input_protocol_config: Optional[Union[PythonProtocolConfig, JsonProtocolConfig]],
mock_live_runner: LiveRunner,
mock_setup_runner: LiveRunner,
mock_fixit_runner: LiveRunner,
mock_protocol_runner: Optional[Union[PythonAndLegacyRunner, JsonRunner]],
) -> None:
result = subject.build_orchestrator(
protocol_config=input_protocol_config,
protocol_engine=mock_protocol_engine,
hardware_api=mock_hardware_api,
)

decoy.when(
protocol_runner.create_protocol_runner(
protocol_engine=mock_protocol_engine, hardware_api=mock_hardware_api
)
).then_return(mock_live_runner)
assert result == RunOrchestrator(
setup_runner=mock_live_runner,
fixit_runner=mock_live_runner,
json_or_python_runner=mock_protocol_runner,
)
# decoy.when(
# protocol_runner.create_protocol_runner(
# protocol_engine=mock_protocol_engine, hardware_api=mock_hardware_api
# )
# ).then_return(mock_setup_runner)
#
# decoy.when(
# protocol_runner.create_protocol_runner(
# protocol_engine=mock_protocol_engine, hardware_api=mock_hardware_api
# )
# ).then_return(mock_fixit_runner)
#
# assert result == RunOrchestrator(
# setup_runner=mock_setup_runner,
# fixit_runner=mock_fixit_runner,
# json_or_python_runner=mock_protocol_runner,
# )

0 comments on commit b57b38c

Please sign in to comment.