Skip to content

Commit

Permalink
added tests to get_error_slice
Browse files Browse the repository at this point in the history
  • Loading branch information
TamarZanzouri committed Aug 2, 2024
1 parent 0ed2a97 commit 299779c
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 3 deletions.
6 changes: 3 additions & 3 deletions api/src/opentrons/protocol_runner/run_orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
58 changes: 58 additions & 0 deletions api/tests/opentrons/protocol_engine/state/test_command_view_old.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
CommandState,
CommandView,
CommandSlice,
CommandErrorSlice,
CommandPointer,
RunResult,
QueueStatus,
Expand Down Expand Up @@ -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,
)

0 comments on commit 299779c

Please sign in to comment.