Chromium Code Reviews| OLD | NEW |
|---|---|
| (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'))) | |
|
Sergiy Byelozyorov
2016/10/05 15:36:06
Please move close to actual 'import test_env' line
nednguyen
2016/10/05 18:50:53
Done.
| |
| 15 | |
| 16 sys.path.insert(0, os.path.join(THIS_DIR, '..', '..')) | |
|
Sergiy Byelozyorov
2016/10/05 15:36:06
What is this one for?
nednguyen
2016/10/05 18:50:53
For importing resource_merger. PTAL again
| |
| 17 | |
| 18 # Imported for side effects on sys.path. | |
| 19 import test_env | |
| 20 | |
| 21 from swarming 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 | |
| 212 class MergingTest(unittest.TestCase): # pragma: no cover | |
|
Sergiy Byelozyorov
2016/10/05 15:36:06
Why is this marked to be without coverage? Aren't
nednguyen
2016/10/05 18:50:53
We aren't running these test in expectation framew
Sergiy Byelozyorov
2016/10/09 14:43:10
This is sad that we have to misuse pragma-no-cover
nednguyen
2016/10/10 13:24:52
Done.
| |
| 213 def test_merge_json_test_results_format_ok(self): | |
| 214 self.maxDiff = None # Show full diff if assertion fail | |
| 215 self.assertEquals(results_merger.merge_test_results( | |
| 216 [GOOD_JSON_TEST_RESULT_0, | |
| 217 GOOD_JSON_TEST_RESULT_1, | |
| 218 GOOD_JSON_TEST_RESULT_2]), | |
| 219 GOOD_JSON_TEST_RESULT_MERGED) | |
| 220 | |
| 221 def test_merge_unsupported_json_test_results_format(self): | |
| 222 with self.assertRaises(Exception): | |
| 223 results_merger.merge_test_results( | |
| 224 [GOOD_JSON_TEST_RESULT_0, INVALID_JSON_TEST_RESULT_0]) | |
| 225 | |
| 226 def test_merge_incompatible_json_test_results_format(self): | |
| 227 with self.assertRaises(Exception): | |
| 228 results_merger.merge_test_results( | |
| 229 [GOOD_JSON_TEST_RESULT_0, GOOD_JSON_TEST_RESULT_SLASH_DELIMITER_3]) | |
| 230 | |
| 231 if __name__ == '__main__': | |
| 232 unittest.main() # pragma: no cover | |
| OLD | NEW |