Skip to content

Commit

Permalink
change test to not use private methods. cursor rename
Browse files Browse the repository at this point in the history
  • Loading branch information
TamarZanzouri committed Aug 15, 2024
1 parent b6962ee commit c1d580c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
13 changes: 6 additions & 7 deletions api/src/opentrons/protocol_engine/state/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,17 +599,16 @@ def get_slice(
running_command = self._state.command_history.get_running_command()
queued_command_ids = self._state.command_history.get_queue_ids()
total_length = len(command_ids)
cursor_index = cursor

# TODO(mm, 2024-05-17): This looks like it's attempting to do the same thing
# as self.get_current(), but in a different way. Can we unify them?
if cursor_index is None:
if cursor is None:
if running_command is not None:
cursor_index = running_command.index
cursor = running_command.index
elif len(queued_command_ids) > 0:
# Get the most recently executed command,
# which we can find just before the first queued command.
cursor_index = (
cursor = (
self._state.command_history.get(queued_command_ids.head()).index - 1
)
elif (
Expand All @@ -621,12 +620,12 @@ def get_slice(
# reach as failed. This makes command status alone insufficient to
# find the most recent command that actually executed, so we need to
# store that separately.
cursor_index = self._state.failed_command.index
cursor = self._state.failed_command.index
else:
cursor_index = total_length - length
cursor = total_length - length

# start is inclusive, stop is exclusive
actual_cursor = max(0, min(cursor_index, total_length - 1))
actual_cursor = max(0, min(cursor, total_length - 1))
stop = min(total_length, actual_cursor + length)

commands = self._state.command_history.get_slice(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,14 @@ def test_get_all_commands(command_history: CommandHistory) -> None:
def test_get_filtered_commands(command_history: CommandHistory) -> None:
"""It should return a list of all commands without fixit commands."""
assert list(command_history.get_filtered_command_ids()) == []
command_entry_1 = create_queued_command_entry()
command_entry_2 = create_queued_command_entry(index=1)
fixit_command_entry_1 = create_queued_command_entry(intent=CommandIntent.FIXIT)
command_history._add("0", command_entry_1)
command_history._add("1", command_entry_2)
command_history._add("fixit-1", fixit_command_entry_1)
command_entry_1 = create_queued_command(command_id="0")
command_entry_2 = create_queued_command(command_id="1")
fixit_command_entry_1 = create_queued_command(
intent=CommandIntent.FIXIT, command_id="fixit-1"
)
command_history.append_queued_command(command_entry_1)
command_history.append_queued_command(command_entry_2)
command_history.append_queued_command(fixit_command_entry_1)
assert list(command_history.get_filtered_command_ids()) == ["0", "1"]


Expand Down

0 comments on commit c1d580c

Please sign in to comment.