Chromium Code Reviews| Index: build/android/pylib/results/json_results.py |
| diff --git a/build/android/pylib/results/json_results.py b/build/android/pylib/results/json_results.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b1d99b587c8e68b39b7b0622701dd39e61d633df |
| --- /dev/null |
| +++ b/build/android/pylib/results/json_results.py |
| @@ -0,0 +1,73 @@ |
| +# Copyright 2014 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +import json |
| +import logging |
| + |
| +from pylib.base import base_test_result |
| + |
| + |
| +def GenerateResultsDict(test_run_result): |
|
klundberg
2014/11/25 18:59:49
I think it would be useful to have some unit tests
jbudorick
2014/11/25 23:32:18
Sounds like a good idea to me. Tests added.
|
| + """Create a results dict from |test_run_result| suitable for writing to JSON. |
| + Args: |
| + test_run_result: a base_test_result.TestRunResults object. |
| + Returns: |
| + A results dict that mirrors the one generated by |
| + base/test/launcher/test_results_tracker.cc:SaveSummaryAsJSON. |
| + """ |
| + assert isinstance(test_run_result, base_test_result.TestRunResults) |
| + |
| + def status_as_string(s): |
| + if s == base_test_result.ResultType.PASS: |
| + return 'SUCCESS' |
| + elif s == base_test_result.ResultType.SKIP: |
| + return 'SKIPPED' |
| + elif s == base_test_result.ResultType.FAIL: |
| + return 'FAILURE' |
| + elif s == base_test_result.ResultType.CRASH: |
| + return 'CRASH' |
| + elif s == base_test_result.ResultType.TIMEOUT: |
| + return 'TIMEOUT' |
| + elif s == base_test_result.ResultType.UNKNOWN: |
| + return 'UNKNOWN' |
| + |
| + def generate_iteration_data(t): |
| + return { |
| + t.GetName(): [ |
| + { |
| + 'status': status_as_string(t.GetType()), |
| + 'elapsed_time_ms': t.GetDuration(), |
| + 'output_snippet': '', |
| + 'losless_snippet': '', |
| + 'output_snippet_base64:': '', |
| + } |
| + ] |
| + } |
| + |
| + all_tests, per_iteration_data = zip( |
| + *[(t.GetName(), generate_iteration_data(t)) |
| + for t in test_run_result.GetAll()]) |
| + |
| + return { |
| + 'global_tags': [], |
| + 'all_tests': all_tests, |
| + # TODO(jbudorick): Add support for disabled tests within base_test_result. |
| + 'disabled_tests': [], |
| + 'per_iteration_data': per_iteration_data, |
| + } |
| + |
| + |
| +def GenerateJsonResultsFile(test_run_result, file_path): |
| + """Write |test_run_result| to JSON. |
| + |
| + This emulates the format of the JSON emitted by |
| + base/test/launcher/test_results_tracker.cc:SaveSummaryAsJSON. |
| + |
| + Args: |
| + test_run_result: a base_test_result.TestRunResults object. |
| + file_path: The path to the JSON file to write. |
| + """ |
| + with open(file_path, 'w') as json_result_file: |
| + json_result_file.write(json.dumps(GenerateResultsDict(test_run_result))) |
| + |