diff --git a/protzilla/steps.py b/protzilla/steps.py index ad898d9e..3326acdb 100644 --- a/protzilla/steps.py +++ b/protzilla/steps.py @@ -260,6 +260,10 @@ def extend(self, messages): def clear(self): self.messages = [] + @property + def empty(self) -> bool: + return len(self.messages) == 0 + class Plots: def __init__(self, plots: list | None = None): @@ -621,10 +625,22 @@ def goto_step(self, step_index: int, section: str) -> None: step = self.all_steps_in_section(section)[step_index] new_step_index = self.all_steps.index(step) + + if new_step_index == self.current_step_index: + return + assert new_step_index < len(self.all_steps) + if new_step_index < self.current_step_index: self.current_step_index = new_step_index + elif ( + not step.output.is_empty + or not self.all_steps[new_step_index - 1].output.is_empty + ): + self.current_step_index = new_step_index else: - raise ValueError("Cannot go to a step that is after the current step") + raise ValueError( + f"Cannot go to a step that has no output yet: {step.display_name}. Please calculate the steps beforehand first." + ) def name_current_step_instance(self, new_instance_identifier: str) -> None: """ diff --git a/tests/protzilla/test_run.py b/tests/protzilla/test_run.py index fd6276cc..7536c9e9 100644 --- a/tests/protzilla/test_run.py +++ b/tests/protzilla/test_run.py @@ -1,5 +1,3 @@ -import logging - from protzilla.methods.data_preprocessing import ImputationByMinPerProtein from protzilla.methods.importing import MaxQuantImport @@ -91,12 +89,7 @@ def test_step_goto(self, caplog, run_imported): step = ImputationByMinPerProtein() run_imported.step_add(step) run_imported.step_goto(0, "data_preprocessing") - assert any( - message["level"] == logging.ERROR and "ValueError" in message["msg"] - for message in run_imported.current_messages - ), "No error messages found in run.current_messages" - assert run_imported.current_step != step - run_imported.step_next() + assert run_imported.current_messages.empty assert run_imported.current_step == step run_imported.step_goto(0, "importing") assert run_imported.current_step == run_imported.steps.all_steps[0]