Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add merge_test_reports command #974

Merged
merged 3 commits into from
Dec 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions planemo/commands/cmd_merge_test_reports.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""Module describing the planemo ``test_reports`` command."""
import os

import click

from planemo import io
from planemo import options
from planemo.cli import command_function
from planemo.galaxy.test.actions import merge_reports


@click.command('merge_test_reports')
@options.merge_test_json()
@options.tool_test_json('output_path')
@command_function
def cli(ctx, input_paths, output_path, **kwds):
"""Merge tool_test_output.json files from multiple runs."""
for input_path in input_paths:
if not os.path.exists(input_path):
io.error("Failed to tool test json file at %s" % input_path)
return 1
merge_reports(input_paths=input_paths, output_path=output_path)
13 changes: 13 additions & 0 deletions planemo/galaxy/test/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,19 @@ def handle_reports_and_summary(ctx, structured_data, exit_code=None, kwds={}):
return exit_code if exit_code is not None else summary_exit_code


def merge_reports(input_paths, output_path):
reports = []
for path in input_paths:
with io.open(path, encoding='utf-8') as f:
reports.append(json.load(f))
tests = []
for report in reports:
tests.extend(report["tests"])
merged_report = {"tests": tests}
with io.open(output_path, mode="w", encoding='utf-8') as out:
out.write(unicodify(json.dumps(merged_report)))


def handle_reports(ctx, structured_data, kwds):
"""Write reports based on user specified kwds."""
exceptions = []
Expand Down
18 changes: 16 additions & 2 deletions planemo/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -1328,14 +1328,28 @@ def recursive_option(help="Recursively perform command for subdirectories."):
)


def tool_test_json():
def merge_test_json():
target_path = click.Path(
file_okay=True,
dir_okay=False,
resolve_path=True,
)
return click.argument(
'path',
'input_paths',
metavar="INPUT_PATHS",
type=target_path,
nargs=-1,
)


def tool_test_json(var="path"):
target_path = click.Path(
file_okay=True,
dir_okay=False,
resolve_path=True,
)
return click.argument(
var,
metavar="FILE_PATH",
type=target_path,
default="tool_test_output.json",
Expand Down
11 changes: 11 additions & 0 deletions tests/test_merge_reports.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import os

from .test_utils import CliTestCase, TEST_DATA_DIR


class TestReportsTestCase(CliTestCase):

def test_merge_reports(self):
with self._isolate():
json_path = os.path.join(TEST_DATA_DIR, "issue381.json")
self._check_exit_code(["merge_test_reports", json_path, json_path, json_path, "out.json"], exit_code=0)