Skip to content

Commit

Permalink
test(reana-dev): add tests for run-example --check-only (reanahub#817)
Browse files Browse the repository at this point in the history
Add tests for gherkin-parser implementation of run-example.
  • Loading branch information
ajclyall committed Aug 6, 2024
1 parent 7de9f8e commit 30392de
Showing 1 changed file with 94 additions and 0 deletions.
94 changes: 94 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
import os
import pytest
import click
from click.testing import CliRunner
from unittest.mock import patch
from reana.reana_dev.cli import reana_dev


def test_shorten_component_name():
Expand All @@ -27,6 +30,97 @@ def test_shorten_component_name():
assert name_short == shorten_component_name(name_long)


@patch(
"reana.reana_dev.run.run_command",
side_effect=lambda command, component, return_output=False: (
"""
Using test file tests/serial/log-messages.feature
Summary of tests/serial/log-messages.feature:
Tested Writing failed in the scenario name should make no difference: failed: passed
"""
if "reana-client test" in command
else "finished" if "reana-client status" in command else ""
),
)
@patch(
"reana.reana_dev.run.get_example_reana_yaml_file_path",
return_value="reana-cwl.yaml",
)
def test_run_example_check_only_passes(
mock_run_command, mock_get_example_reana_yaml_file_path
):
runner = CliRunner()
with runner.isolation():
result = runner.invoke(
reana_dev,
[
"run-example",
"-c",
"r-d-r-roofit",
"-w",
"cwl",
"--check-only",
],
)
assert "1 passed" in result.output
assert "0 failed" in result.output
assert result.exit_code == 0


def run_command_possibilities(command, component, return_output=False):
if "reana-client test" in command and "cwl" in command:
return """
Using test file tests/serial/log-messages.feature
Summary of tests/serial/log-messages.feature:
Tested Writing passed in the scenario name should make no difference: passed: failed
Tested If one scenario fails, the whole test should fail: passed
"""
elif "reana-client test" in command:
return """
Using test file tests/serial/log-messages.feature
Summary of tests/serial/log-messages.feature:
Tested Writing passed in the scenario name should make no difference: passed
Tested If one scenario fails, the whole test should fail: passed
"""
elif "reana-client status" in command:
return "finished"
return ""


@patch(
"reana.reana_dev.run.run_command",
side_effect=run_command_possibilities,
)
@patch(
"reana.reana_dev.run.get_example_reana_yaml_file_path",
return_value="reana-cwl.yaml",
side_effect=lambda component, workflow_engine, compute_backend: (
"reana-cwl.yaml" if workflow_engine == "cwl" else "reana-yadage.yaml"
),
)
def test_run_example_check_only_one_fail_one_pass(
mock_run_command, mock_get_example_reana_yaml_file_path
):
runner = CliRunner()
with runner.isolation():
result = runner.invoke(
reana_dev,
[
"run-example",
"-c",
"r-d-r-roofit",
"-w",
"cwl",
"-w",
"yadage",
"--check-only",
],
)
assert "2 submitted" in result.output
assert "1 passed" in result.output
assert "1 failed: root6-roofit-cwl-kubernetes" in result.output


def test_is_component_python_package():
"""Tests for is_component_python_package()."""
from reana.reana_dev.python import is_component_python_package
Expand Down

0 comments on commit 30392de

Please sign in to comment.