Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(226)

Side by Side Diff: scripts/slave/recipe_modules/swarming/tests/results_merger_unittest.py

Issue 2375663003: Add json test results format support for SwarmingIsolatedScriptTest (Closed)
Patch Set: Add no cover Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 # Copyright 2016 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 import os
7 import sys
8 import unittest
9
10 THIS_DIR = os.path.dirname(os.path.abspath(__file__))
11
12 # For 'test_env'.
13 sys.path.insert(
14 0, os.path.abspath(os.path.join(THIS_DIR, '..', '..', '..', 'unittests')))
15
16 # Imported for side effects on sys.path.
17 import test_env
18
19 # For results_merger.
20 sys.path.insert(0, os.path.join(THIS_DIR, '..'))
21 import results_merger
22
23
24 GOOD_JSON_TEST_RESULT_0 = {
25 'tests': {
26 'car': {
27 'honda': {
28 'expected': 'PASS',
29 'actual': 'PASS'
30 },
31 'toyota': {
32 'expected': 'FAIL',
33 'actual': 'FAIL'
34 }
35 },
36 'computer': {
37 'dell': {
38 'expected': 'PASS',
39 'actual': 'PASS'
40 }
41 },
42 },
43 'interrupted': False,
44 'path_delimiter': '.',
45 'version': 3,
46 'seconds_since_epoch': 1406662289.76,
47 'num_failures_by_type': {
48 'FAIL': 0,
49 'PASS': 2
50 }
51 }
52
53 GOOD_JSON_TEST_RESULT_1 = {
54 'tests': {
55 'car': {
56 'tesla': {
57 'expected': 'PASS',
58 'actual': 'PASS'
59 },
60 },
61 'burger': {
62 'mcdonald': {
63 'expected': 'PASS',
64 'actual': 'PASS'
65 }
66 },
67 },
68 'interrupted': False,
69 'path_delimiter': '.',
70 'version': 3,
71 'seconds_since_epoch': 1406662283.11,
72 'num_failures_by_type': {
73 'FAIL': 0,
74 'PASS': 2
75 }
76 }
77
78 GOOD_JSON_TEST_RESULT_2 = {
79 'tests': {
80 'car': {
81 'mercedes': {
82 'expected': 'PASS',
83 'actual': 'FAIL'
84 },
85 },
86 'burger': {
87 'in n out': {
88 'expected': 'PASS',
89 'actual': 'PASS'
90 }
91 },
92 },
93 'interrupted': True,
94 'path_delimiter': '.',
95 'version': 3,
96 'seconds_since_epoch': 1406662200.01,
97 'num_failures_by_type': {
98 'FAIL': 1,
99 'PASS': 1
100 }
101 }
102
103 GOOD_JSON_TEST_RESULT_SLASH_DELIMITER_3 = {
104 'tests': {
105 'car': {
106 'mustang': {
107 'expected': 'PASS',
108 'actual': 'FAIL'
109 },
110 },
111 'burger': {
112 'white castle': {
113 'expected': 'PASS',
114 'actual': 'PASS'
115 }
116 },
117 },
118 'interrupted': True,
119 'path_delimiter': '/',
120 'version': 3,
121 'seconds_since_epoch': 1406662200.01,
122 'num_failures_by_type': {
123 'FAIL': 1,
124 'PASS': 1
125 }
126 }
127
128 GOOD_JSON_TEST_RESULT_MERGED = {
129 'tests': {
130 'car': {
131 'tesla': {
132 'expected': 'PASS',
133 'actual': 'PASS'
134 },
135 'mercedes': {
136 'expected': 'PASS',
137 'actual': 'FAIL'
138 },
139 'honda': {
140 'expected': 'PASS',
141 'actual': 'PASS'
142 },
143 'toyota': {
144 'expected': 'FAIL',
145 'actual': 'FAIL'
146 }
147 },
148 'computer': {
149 'dell': {
150 'expected': 'PASS',
151 'actual': 'PASS'
152 }
153 },
154 'burger': {
155 'mcdonald': {
156 'expected': 'PASS',
157 'actual': 'PASS'
158 },
159 'in n out': {
160 'expected': 'PASS',
161 'actual': 'PASS'
162 }
163 }
164 },
165 'interrupted': True,
166 'path_delimiter': '.',
167 'version': 3,
168 'seconds_since_epoch': 1406662200.01,
169 'num_failures_by_type': {
170 'FAIL': 1,
171 'PASS': 5
172 }
173 }
174
175 INVALID_JSON_TEST_RESULT_UNSUPPORTED_VERSION = {
176 'tests': {
177 'car': {
178 'tesla': {
179 'expected': 'PASS',
180 'actual': 'PASS'
181 }
182 },
183 'computer': {
184 'dell': {
185 'expected': 'PASS',
186 'actual': 'PASS'
187 }
188 },
189 'burger': {
190 'mcdonald': {
191 'expected': 'PASS',
192 'actual': 'PASS'
193 },
194 'in n out': {
195 'expected': 'PASS',
196 'actual': 'PASS'
197 }
198 }
199 },
200 'interrupted': True,
201 'path_delimiter': '.',
202 'version': 5,
203 'seconds_since_epoch': 1406662200.01,
204 'num_failures_by_type': {
205 'FAIL': 1,
206 'PASS': 5
207 }
208 }
209
210
211 # These unittests are run in PRESUBMIT, but not by recipe_simulation_test, hence
212 # to avoid false alert on missing coverage by recipe_simulation_test, we mark
213 # these code as no cover.
214 class MergingTest(unittest.TestCase): # pragma: no cover
215 def test_merge_json_test_results_format_ok(self):
216 self.maxDiff = None # Show full diff if assertion fail
217 self.assertEquals(results_merger.merge_test_results(
218 [GOOD_JSON_TEST_RESULT_0,
219 GOOD_JSON_TEST_RESULT_1,
220 GOOD_JSON_TEST_RESULT_2]),
221 GOOD_JSON_TEST_RESULT_MERGED)
222
223 def test_merge_unsupported_json_test_results_format(self):
224 with self.assertRaises(Exception):
225 results_merger.merge_test_results(
226 [GOOD_JSON_TEST_RESULT_0, INVALID_JSON_TEST_RESULT_0])
227
228 def test_merge_incompatible_json_test_results_format(self):
229 with self.assertRaises(Exception):
230 results_merger.merge_test_results(
231 [GOOD_JSON_TEST_RESULT_0, GOOD_JSON_TEST_RESULT_SLASH_DELIMITER_3])
232
233 if __name__ == '__main__':
234 unittest.main() # pragma: no cover
OLDNEW
« no previous file with comments | « scripts/slave/recipe_modules/swarming/results_merger.py ('k') | scripts/slave/recipe_modules/test_utils/api.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698