

def parse_benchmark(base_url, node):
    ' Try building a benchmark configuration from deserialized configuration root node '
    node = lowercase_keys(flatten_dictionaries(node))
    benchmark = Benchmark()
    benchmark = Test.parse_test(base_url, node, benchmark)
    for (key, value) in node.items():
        if (key == 'warmup_runs'):
            benchmark.warmup_runs = int(value)
        elif (key == 'benchmark_runs'):
            benchmark.benchmark_runs = int(value)
        elif (key == 'output_format'):
            format = value.lower()
            if (format in OUTPUT_FORMATS):
                benchmark.output_format = format
            else:
                raise ValueError(('Invalid benchmark output format: ' + format))
        elif (key == 'output_file'):
            if (not isinstance(value, basestring)):
                raise ValueError('Invalid output file format')
            benchmark.output_file = value
        elif (key == 'metrics'):
            if isinstance(value, basestring):
                benchmark.add_metric(tests.coerce_to_string(value))
            elif (isinstance(value, list) or isinstance(value, set)):
                for metric in value:
                    if isinstance(metric, dict):
                        for (metricname, aggregate) in metric.items():
                            if (not isinstance(metricname, basestring)):
                                raise TypeError('Invalid metric input: non-string metric name')
                            if (not isinstance(aggregate, basestring)):
                                raise TypeError('Invalid aggregate input: non-string aggregate name')
                            benchmark.add_metric(tests.coerce_to_string(metricname), tests.coerce_to_string(aggregate))
                    elif isinstance(metric, basestring):
                        benchmark.add_metric(tests.coerce_to_string(metric))
            elif isinstance(value, dict):
                for (metricname, aggregate) in value.items():
                    if (not isinstance(metricname, basestring)):
                        raise TypeError('Invalid metric input: non-string metric name')
                    if (not isinstance(aggregate, basestring)):
                        raise TypeError('Invalid aggregate input: non-string aggregate name')
                    benchmark.add_metric(tests.coerce_to_string(metricname), tests.coerce_to_string(aggregate))
            else:
                raise TypeError(('Invalid benchmark metric datatype: ' + str(value)))
    return benchmark

dataset/ETHPy150Open svanoort/pyresttest/pyresttest/benchmarks.py parse_benchmark/original