#!/usr/bin/python3
#
# Merge the participant results of a run by this tool into a
# test-standard result.
# Note that this method will be given results for all participants
# whether their runs succeeded or failed and should return a result
# that indicates whether or not the run as a whole failed.  This
# allows multi-participant tools to return a successful result even if
# one of the participants failed but there's enough data to do so.
#

import pscheduler

input = pscheduler.json_load(exit_on_error=True);

try:
    # Single-participant tests usually use the result generated by the
    # tool's 'run' method.  Multiple-participant tests would go over
    # the result from all participants and produce a suitable result.
    result = input['results'][0]['result']
except (IndexError, KeyError) as ex:
    result = {
        'succeeded': False,
        'error': "Error in participant data: {}".format(str(ex))
    }

pscheduler.succeed_json(result)
