From 052b1cba13846a76fa0395185842000e1d17c964 Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Wed, 13 Sep 2023 19:34:24 +0200 Subject: [PATCH] Support for testing workflows with conditional steps --- planemo/galaxy/activity.py | 8 +++++--- tests/data/wf18_simple_conditional-test.yml | 7 +++++++ tests/data/wf18_simple_conditional.yml | 13 +++++++++++++ tests/test_cmd_test.py | 10 ++++++++++ 4 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 tests/data/wf18_simple_conditional-test.yml create mode 100644 tests/data/wf18_simple_conditional.yml diff --git a/planemo/galaxy/activity.py b/planemo/galaxy/activity.py index 290b8d339..1ee3b77cc 100644 --- a/planemo/galaxy/activity.py +++ b/planemo/galaxy/activity.py @@ -223,7 +223,7 @@ def _execute( # noqa C901 if not kwds.get("no_wait"): final_state = _wait_for_invocation_jobs(ctx, user_gi, invocation_id, polling_backoff) - if final_state != "ok": + if final_state not in ("ok", "skipped"): msg = "Failed to run workflow final history state is [%s]." % final_state error_message = msg if not error_message else f"{error_message}. {msg}" ctx.vlog(msg) @@ -698,7 +698,7 @@ def _invocation(self): @property def was_successful(self): - return self.history_state in ["ok", None] and self.invocation_state == "scheduled" + return self.history_state in ["ok", "skipped", None] and self.invocation_state == "scheduled" def _tool_id(tool_path): @@ -740,7 +740,7 @@ def _retry_on_timeouts(ctx, gi, f): except RequestException: end_time = time.time() if end_time - start_time > 45 and (try_num + 1) < try_count: - ctx.vlog("Galaxy seems to have timedout, retrying to fetch status.") + ctx.vlog("Galaxy seems to have timed out, retrying to fetch status.") continue else: raise @@ -815,6 +815,8 @@ def get_state(): return terminal_state if current_non_terminal_states: return None + if len(current_states) > 1: + current_states = current_states - {"skipped"} assert len(current_states) == 1, f"unexpected state(s) found: {current_states}" return current_states.pop() diff --git a/tests/data/wf18_simple_conditional-test.yml b/tests/data/wf18_simple_conditional-test.yml new file mode 100644 index 000000000..b44241468 --- /dev/null +++ b/tests/data/wf18_simple_conditional-test.yml @@ -0,0 +1,7 @@ +- doc: Simple conditional concat workflow test + job: + some_file: + class: File + path: hello.txt + should_run: false + outputs: {} diff --git a/tests/data/wf18_simple_conditional.yml b/tests/data/wf18_simple_conditional.yml new file mode 100644 index 000000000..c91052c6f --- /dev/null +++ b/tests/data/wf18_simple_conditional.yml @@ -0,0 +1,13 @@ +class: GalaxyWorkflow +inputs: + should_run: + type: boolean + some_file: + type: data +steps: + cat1: + tool_id: cat1 + in: + input1: some_file + should_run: should_run + when: $(inputs.should_run) diff --git a/tests/test_cmd_test.py b/tests/test_cmd_test.py index 9a70f796b..cc256c852 100644 --- a/tests/test_cmd_test.py +++ b/tests/test_cmd_test.py @@ -358,3 +358,13 @@ def test_workflow_test_output_sanitization(self): test_command = self.append_profile_argument_if_needed(test_command) test_command.append(test_artifact) self._check_exit_code(test_command, exit_code=0) + + @skip_if_environ("PLANEMO_SKIP_GALAXY_TESTS") + def test_workflow_test_skipped_invocation(self): + cat = os.path.join(PROJECT_TEMPLATES_DIR, "demo", "cat.xml") + with self._isolate(): + test_artifact = os.path.join(TEST_DATA_DIR, "wf18_simple_conditional.yml") + test_command = self._test_command("--extra_tools", cat) + test_command = self.append_profile_argument_if_needed(test_command) + test_command.append(test_artifact) + self._check_exit_code(test_command, exit_code=0)