OLD | NEW |
---|---|
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import json | 5 import json |
6 import logging | 6 import logging |
7 | 7 |
8 from pylib.base import base_test_result | 8 from pylib.base import base_test_result |
9 | 9 |
10 | 10 |
11 def GenerateResultsDict(test_run_result): | 11 def GenerateResultsDict(test_run_result): |
12 """Create a results dict from |test_run_result| suitable for writing to JSON. | 12 """Create a results dict from |test_run_result| suitable for writing to JSON. |
13 Args: | 13 Args: |
14 test_run_result: a base_test_result.TestRunResults object. | 14 test_run_result: a base_test_result.TestRunResults object. |
15 Returns: | 15 Returns: |
16 A results dict that mirrors the one generated by | 16 A results dict that mirrors the one generated by |
17 base/test/launcher/test_results_tracker.cc:SaveSummaryAsJSON. | 17 base/test/launcher/test_results_tracker.cc:SaveSummaryAsJSON. |
18 """ | 18 """ |
19 # Example json output. | |
20 # { | |
21 # "global_tags": [], | |
22 # "all_tests": [ | |
23 # "test1", | |
24 # "test2", | |
25 # ], | |
26 # "disabled_tests": [], | |
27 # "per_iteration_data": [ | |
28 # { | |
29 # "test1": [ | |
30 # { | |
31 # "status": "SUCCESS", | |
32 # "elapsed_time_ms": 1, | |
33 # "output_snippet": "", | |
34 # "output_snippet_base64": "", | |
35 # "losless_snippet": "". | |
jbudorick
2015/03/12 19:41:49
nit: .?
mikecase (-- gone --)
2015/03/13 01:07:23
Done.
| |
36 # }, | |
37 # ], | |
38 # "test2": [ | |
39 # { | |
40 # "status": "FAILURE", | |
41 # "elapsed_time_ms": 12, | |
42 # "output_snippet": "", | |
43 # "output_snippet_base64": "", | |
44 # "losless_snippet": "". | |
jbudorick
2015/03/12 19:41:49
nit: .?
mikecase (-- gone --)
2015/03/13 01:07:23
Done.
| |
45 # }, | |
46 # ], | |
47 # }, | |
48 # ], | |
49 # } | |
50 | |
19 assert isinstance(test_run_result, base_test_result.TestRunResults) | 51 assert isinstance(test_run_result, base_test_result.TestRunResults) |
20 | 52 |
21 def status_as_string(s): | 53 def status_as_string(s): |
22 if s == base_test_result.ResultType.PASS: | 54 if s == base_test_result.ResultType.PASS: |
23 return 'SUCCESS' | 55 return 'SUCCESS' |
24 elif s == base_test_result.ResultType.SKIP: | 56 elif s == base_test_result.ResultType.SKIP: |
25 return 'SKIPPED' | 57 return 'SKIPPED' |
26 elif s == base_test_result.ResultType.FAIL: | 58 elif s == base_test_result.ResultType.FAIL: |
27 return 'FAILURE' | 59 return 'FAILURE' |
28 elif s == base_test_result.ResultType.CRASH: | 60 elif s == base_test_result.ResultType.CRASH: |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
64 This emulates the format of the JSON emitted by | 96 This emulates the format of the JSON emitted by |
65 base/test/launcher/test_results_tracker.cc:SaveSummaryAsJSON. | 97 base/test/launcher/test_results_tracker.cc:SaveSummaryAsJSON. |
66 | 98 |
67 Args: | 99 Args: |
68 test_run_result: a base_test_result.TestRunResults object. | 100 test_run_result: a base_test_result.TestRunResults object. |
69 file_path: The path to the JSON file to write. | 101 file_path: The path to the JSON file to write. |
70 """ | 102 """ |
71 with open(file_path, 'w') as json_result_file: | 103 with open(file_path, 'w') as json_result_file: |
72 json_result_file.write(json.dumps(GenerateResultsDict(test_run_result))) | 104 json_result_file.write(json.dumps(GenerateResultsDict(test_run_result))) |
73 | 105 |
106 | |
107 def ParseResultsFromJson(json_results): | |
108 """Creates a list of BaseTestResult objects from JSON. | |
109 | |
110 Args: | |
111 json_results: A JSON dict in the format created by | |
112 GenerateJsonResultsFile. | |
113 """ | |
114 | |
115 def string_as_status(s): | |
116 if s == 'SUCCESS': | |
117 return base_test_result.ResultType.PASS | |
118 elif s == 'SKIPPED': | |
119 return base_test_result.ResultType.SKIP | |
120 elif s == 'FAILURE': | |
121 return base_test_result.ResultType.FAIL | |
122 elif s == 'CRASH': | |
123 return base_test_result.ResultType.CRASH | |
124 elif s == 'TIMEOUT': | |
125 return base_test_result.ResultType.TIMEOUT | |
126 elif s == 'UNKNOWN': | |
jbudorick
2015/03/12 19:41:49
This should just be an else case.
mikecase (-- gone --)
2015/03/13 01:07:23
Done.
| |
127 return base_test_result.ResultType.UNKNOWN | |
128 | |
129 results_list = [] | |
130 testsuite_runs = json_results['per_iteration_data'] | |
131 for testsuite_run in testsuite_runs: | |
132 for test in testsuite_run: | |
jbudorick
2015/03/12 19:41:49
for test, test_runs in testsuite_run.iteritems():
mikecase (-- gone --)
2015/03/13 01:07:23
Done.
| |
133 test_runs = testsuite_run[test] | |
134 for test_run in test_runs: | |
135 name = test | |
jbudorick
2015/03/12 19:41:49
Why does this exist?
mikecase (-- gone --)
2015/03/13 01:07:23
Done.
| |
136 test_type = string_as_status(test_run['status']) | |
137 duration_ms = test_run['elapsed_time_ms'] | |
138 results_list.append(base_test_result.BaseTestResult( | |
139 name, test_type, duration=duration_ms)) | |
140 return results_list | |
141 | |
OLD | NEW |