Skip to content

Commit

Permalink
refactor(test): address PR comments (#724)
Browse files Browse the repository at this point in the history
Various changes addressing review comments.
  • Loading branch information
ajclyall committed Aug 22, 2024
1 parent 1c92a87 commit b231b90
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
11 changes: 4 additions & 7 deletions reana_client/cli/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,11 @@ def upload_files( # noqa: C901
msg_type="error",
)
sys.exit(1)

filenames = []
if reana_spec.get("tests"):
for f in reana_spec["tests"].get("files") or []:
filenames.append(os.path.join(os.getcwd(), f))
if reana_spec.get("inputs"):
filenames = []

# collect all files in input.files
for f in reana_spec["inputs"].get("files") or []:
# check for directories in files
Expand All @@ -340,10 +341,6 @@ def upload_files( # noqa: C901
)
sys.exit(1)
filenames.append(os.path.join(os.getcwd(), f))
if reana_spec.get("tests"):
for f in reana_spec["tests"].get("files") or []:
filenames.append(os.path.join(os.getcwd(), f))

# collect all files in input.directories
files_from_directories = []
directories = reana_spec["inputs"].get("directories") or []
Expand Down
32 changes: 23 additions & 9 deletions reana_client/cli/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

import sys
import click
import logging
import traceback
from reana_client.cli.utils import add_access_token_options, check_connection
from reana_commons.gherkin_parser.parser import (
parse_and_run_tests,
Expand Down Expand Up @@ -98,8 +100,10 @@ def test(ctx, workflow, test_files, access_token):
workflow=workflow, access_token=access_token
)
status = workflow_status["status"]
id = workflow_status["id"]
except Exception:
workflow_name = workflow_status["name"]
except Exception as e:
logging.debug(traceback.format_exc())
logging.debug(str(e))
display_message(f"Could not find workflow ``{workflow}``.", msg_type="error")
sys.exit(1)

Expand All @@ -114,22 +118,29 @@ def test(ctx, workflow, test_files, access_token):
reana_specification = get_workflow_specification(workflow, access_token)
try:
test_files = reana_specification["specification"]["tests"]["files"]
except KeyError:
except KeyError as e:
logging.debug(traceback.format_exc())
logging.debug(str(e))
display_message(
"No test files specified in reana.yaml and no -n option provided.",
msg_type="error",
)
sys.exit(1)

failed = False
data_fetcher = DataFetcherClient(access_token)
for test_file in test_files:
click.secho(f"\nUsing test file {test_file}", fg="cyan", bold=True)
try:
results = parse_and_run_tests(id, test_file, workflow, data_fetcher)
except FileNotFoundError:
results = parse_and_run_tests(test_file, workflow_name, data_fetcher)
except FileNotFoundError as e:
logging.debug(traceback.format_exc())
logging.debug(str(e))
display_message(f"Test file {test_file} not found.", msg_type="error")
sys.exit(1)
except FeatureFileError as e:
logging.debug(traceback.format_exc())
logging.debug(str(e))
display_message(
f"Error parsing feature file {test_file}: {e}", msg_type="error"
)
Expand All @@ -138,7 +149,10 @@ def test(ctx, workflow, test_files, access_token):
click.secho(f"Summary of {test_file}:", bold=True)
for scenario in results[1]:
click.echo(f"Tested {scenario.scenario}: ", nl=False)
click.secho(
f"{scenario.result.name}",
fg=("green" if scenario.result == AnalysisTestStatus.passed else "red"),
)
if scenario.result == AnalysisTestStatus.failed:
click.secho(f"{scenario.result.name}", fg="red")
failed = True
else:
click.secho(f"{scenario.result.name}", fg="green")
if failed:
sys.exit(1)

0 comments on commit b231b90

Please sign in to comment.