| OLD | NEW |
| 1 import json | 1 import json |
| 2 | 2 |
| 3 from recipe_engine import recipe_test_api | 3 from recipe_engine import recipe_test_api |
| 4 | 4 |
| 5 from .util import GTestResults, TestResults | 5 from .util import GTestResults, TestResults |
| 6 | 6 |
| 7 class TestUtilsTestApi(recipe_test_api.RecipeTestApi): | 7 class TestUtilsTestApi(recipe_test_api.RecipeTestApi): |
| 8 @recipe_test_api.placeholder_step_data | 8 @recipe_test_api.placeholder_step_data |
| 9 def test_results(self, test_results, retcode=None): | 9 def test_results(self, test_results, retcode=None): |
| 10 return self.m.json.output(test_results.as_jsonish(), retcode) | 10 return self.m.json.output(test_results.as_jsonish(), retcode) |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 retcode = None if passing else 1 | 106 retcode = None if passing else 1 |
| 107 return self.raw_gtest_output(canned_jsonish, retcode) | 107 return self.raw_gtest_output(canned_jsonish, retcode) |
| 108 | 108 |
| 109 def raw_gtest_output(self, jsonish, retcode): | 109 def raw_gtest_output(self, jsonish, retcode): |
| 110 t = GTestResults(jsonish) | 110 t = GTestResults(jsonish) |
| 111 ret = self.gtest_results(t) | 111 ret = self.gtest_results(t) |
| 112 ret.retcode = retcode | 112 ret.retcode = retcode |
| 113 return ret | 113 return ret |
| 114 | 114 |
| 115 def canned_isolated_script_output(self, passing, is_win, swarming=False, | 115 def canned_isolated_script_output(self, passing, is_win, swarming=False, |
| 116 swarming_internal_failure=False, | 116 shards=1, swarming_internal_failure=False, |
| 117 isolated_script_passing=True, valid=True): | 117 isolated_script_passing=True, valid=True, |
| 118 missing_shards=[]): |
| 118 """Produces a test results' compatible json for isolated script tests. """ | 119 """Produces a test results' compatible json for isolated script tests. """ |
| 119 jsonish_results = {} | 120 per_shard_results = [] |
| 120 jsonish_results['valid'] = valid | 121 for i in xrange(shards): |
| 121 if isolated_script_passing: | 122 jsonish_results = {} |
| 122 jsonish_results['failures'] = [] | 123 jsonish_results['valid'] = valid |
| 123 else: | 124 # Keep shard 0's results equivalent to the old code to minimize |
| 124 jsonish_results['failures'] = ['test1.Test1', 'test2.Test2'] | 125 # expectation diffs. |
| 125 | 126 idx = 1 + (2 * i) |
| 126 jsonish_summary = { | 127 tests_run = ['test%d.Test%d' % (idx, idx), |
| 127 'shards': [ | 128 'test%d.Test%d' % (idx + 1, idx + 1)] |
| 128 { | 129 if isolated_script_passing: |
| 130 jsonish_results['failures'] = [] |
| 131 jsonish_results['successes'] = tests_run |
| 132 else: |
| 133 jsonish_results['failures'] = tests_run |
| 134 jsonish_results['successes'] = [] |
| 135 per_shard_results.append(jsonish_results) |
| 136 if swarming: |
| 137 jsonish_shards = [] |
| 138 files_dict = {} |
| 139 for i in xrange(shards): |
| 140 jsonish_shards.append({ |
| 129 'failure': not passing, | 141 'failure': not passing, |
| 130 'internal_failure': swarming_internal_failure | 142 'internal_failure': swarming_internal_failure |
| 131 } | 143 }) |
| 132 ] | 144 if not i in missing_shards: |
| 133 } | 145 swarming_path = str(i) |
| 134 | 146 swarming_path += '\\output.json' if is_win else '/output.json' |
| 135 if swarming: | 147 files_dict[swarming_path] = json.dumps(per_shard_results[i]) |
| 136 swarming_path = '0\\output.json' if is_win else '0/output.json' | 148 jsonish_summary = {'shards': jsonish_shards} |
| 137 files_dict = { | 149 files_dict['summary.json'] = json.dumps(jsonish_summary) |
| 138 swarming_path: json.dumps(jsonish_results), | |
| 139 'summary.json': json.dumps(jsonish_summary) | |
| 140 } | |
| 141 return self.m.raw_io.output_dir(files_dict) | 150 return self.m.raw_io.output_dir(files_dict) |
| 142 else: | 151 else: |
| 143 return self.m.json.output(jsonish_results) | 152 return self.m.json.output(per_shard_results[0]) |
| OLD | NEW |