From 299779c134859669e6629d2559774f8c3e9df9b9 Mon Sep 17 00:00:00 2001 From: tamarzanzouri Date: Fri, 2 Aug 2024 16:23:21 -0400 Subject: [PATCH] added tests to get_error_slice --- .../protocol_runner/run_orchestrator.py | 6 +- .../state/test_command_view_old.py | 58 +++++++++++++++++++ 2 files changed, 61 insertions(+), 3 deletions(-) diff --git a/api/src/opentrons/protocol_runner/run_orchestrator.py b/api/src/opentrons/protocol_runner/run_orchestrator.py index e7c0f4ed9c6..65da1d612b0 100644 --- a/api/src/opentrons/protocol_runner/run_orchestrator.py +++ b/api/src/opentrons/protocol_runner/run_orchestrator.py @@ -275,13 +275,13 @@ def get_command_error_slice( cursor: Optional[int], length: int, ) -> CommandErrorSlice: - """Get a slice of run commands. + """Get a slice of run commands errors. Args: - cursor: Requested index of first command in the returned slice. + cursor: Requested index of first error in the returned slice. length: Length of slice to return. """ - return self._protocol_engine.state_view.commands.get_slice( + return self._protocol_engine.state_view.commands.get_errors_slice( cursor=cursor, length=length ) diff --git a/api/tests/opentrons/protocol_engine/state/test_command_view_old.py b/api/tests/opentrons/protocol_engine/state/test_command_view_old.py index 2b86fe9259f..d751e562c00 100644 --- a/api/tests/opentrons/protocol_engine/state/test_command_view_old.py +++ b/api/tests/opentrons/protocol_engine/state/test_command_view_old.py @@ -25,6 +25,7 @@ CommandState, CommandView, CommandSlice, + CommandErrorSlice, CommandPointer, RunResult, QueueStatus, @@ -1026,3 +1027,60 @@ def test_get_slice_default_cursor_queued() -> None: cursor=2, total_length=5, ) + + +def test_get_errors_slice_empty() -> None: + """It should return a slice from the tail if no current command.""" + subject = get_command_view(failed_command_errors=[]) + result = subject.get_errors_slice(cursor=None, length=2) + + assert result == CommandErrorSlice(commands_errors=[], cursor=0, total_length=0) + + +def test_get_errors_slice() -> None: + """It should return a slice of all command errors.""" + error_1 = ErrorOccurrence.construct(id="error-id-1") # type: ignore[call-arg] + error_2 = ErrorOccurrence.construct(id="error-id-2") # type: ignore[call-arg] + error_3 = ErrorOccurrence.construct(id="error-id-3") # type: ignore[call-arg] + error_4 = ErrorOccurrence.construct(id="error-id-4") # type: ignore[call-arg] + + subject = get_command_view( + failed_command_errors=[error_1, error_2, error_3, error_4] + ) + + result = subject.get_errors_slice(cursor=1, length=3) + + assert result == CommandErrorSlice( + commands_errors=[error_2, error_3, error_4], + cursor=1, + total_length=4, + ) + + result = subject.get_errors_slice(cursor=-3, length=10) + + assert result == CommandErrorSlice( + commands_errors=[error_1, error_2, error_3, error_4], + cursor=0, + total_length=4, + ) + + +def test_get_slice_default_cursor_last_error() -> None: + """It should select a cursor automatically to the last error inserted.""" + error_1 = ErrorOccurrence.construct(id="error-id-1") # type: ignore[call-arg] + error_2 = ErrorOccurrence.construct(id="error-id-2") # type: ignore[call-arg] + error_3 = ErrorOccurrence.construct(id="error-id-3") # type: ignore[call-arg] + error_4 = ErrorOccurrence.construct(id="error-id-4") # type: ignore[call-arg] + error_5 = ErrorOccurrence.construct(id="error-id-5") # type: ignore[call-arg] + + subject = get_command_view( + failed_command_errors=[error_1, error_2, error_3, error_4, error_5] + ) + + result = subject.get_errors_slice(cursor=None, length=2) + + assert result == CommandErrorSlice( + commands_errors=[error_5], + cursor=4, + total_length=5, + )