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

Side by Side Diff: recipe_modules/bot_update/test_api.py

Issue 2316323002: Remove force parameter from bot_update.ensure_checkout. (Closed)
Patch Set: Remove assert Created 4 years, 3 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
« no previous file with comments | « recipe_modules/bot_update/example.expected/forced.json ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 hashlib 5 import hashlib
6 import os 6 import os
7 import struct 7 import struct
8 import sys 8 import sys
9 from recipe_engine import recipe_test_api 9 from recipe_engine import recipe_test_api
10 10
11 11
12 class BotUpdateTestApi(recipe_test_api.RecipeTestApi): 12 class BotUpdateTestApi(recipe_test_api.RecipeTestApi):
13 def output_json(self, master, builder, slave, root, first_sln, 13 def output_json(self, master, builder, slave, root, first_sln,
14 revision_mapping, force=False, fail_patch=False, 14 revision_mapping, fail_patch=False,
15 output_manifest=False, fixed_revisions=None): 15 output_manifest=False, fixed_revisions=None):
16 """Deterministically synthesize json.output test data for gclient's 16 """Deterministically synthesize json.output test data for gclient's
17 --output-json option. 17 --output-json option.
18 """ 18 """
19 active = True
20
21 output = { 19 output = {
22 'did_run': active, 20 'did_run': True,
23 'patch_failure': False 21 'patch_failure': False
24 } 22 }
25 23
26 # Add in extra json output if active. 24 properties = {
27 if active: 25 property_name: self.gen_revision(project_name)
28 properties = { 26 for project_name, property_name in revision_mapping.iteritems()
29 property_name: self.gen_revision(project_name) 27 }
30 for project_name, property_name in revision_mapping.iteritems() 28 properties.update({
31 } 29 '%s_cp' % property_name: ('refs/heads/master@{#%s}' %
32 properties.update({ 30 self.gen_commit_position(project_name))
33 '%s_cp' % property_name: ('refs/heads/master@{#%s}' % 31 for project_name, property_name in revision_mapping.iteritems()
34 self.gen_commit_position(project_name)) 32 })
35 for project_name, property_name in revision_mapping.iteritems() 33
34 output.update({
35 'patch_root': root or first_sln,
36 'root': first_sln,
37 'properties': properties,
38 'step_text': 'Some step text'
39 })
40
41 if output_manifest:
42 output.update({
43 'manifest': {
44 project_name: {
45 'repository': 'https://fake.org/%s.git' % project_name,
46 'revision': self.gen_revision(project_name),
47 }
48 for project_name in revision_mapping
49 }
36 }) 50 })
37 51
38 output.update({ 52 if fixed_revisions:
39 'patch_root': root or first_sln, 53 output['fixed_revisions'] = fixed_revisions
40 'root': first_sln,
41 'properties': properties,
42 'step_text': 'Some step text'
43 })
44 54
45 if output_manifest: 55 if fail_patch:
46 output.update({ 56 output['log_lines'] = [('patch error', 'Patch failed to apply'),]
47 'manifest': { 57 output['patch_failure'] = True
48 project_name: { 58 output['patch_apply_return_code'] = 1
49 'repository': 'https://fake.org/%s.git' % project_name, 59 if fail_patch == 'download':
50 'revision': self.gen_revision(project_name), 60 output['patch_apply_return_code'] = 3
51 }
52 for project_name in revision_mapping
53 }
54 })
55
56 if fixed_revisions:
57 output['fixed_revisions'] = fixed_revisions
58
59 if fail_patch:
60 output['log_lines'] = [('patch error', 'Patch failed to apply'),]
61 output['patch_failure'] = True
62 output['patch_apply_return_code'] = 1
63 if fail_patch == 'download':
64 output['patch_apply_return_code'] = 3
65 return self.m.json.output(output) 61 return self.m.json.output(output)
66 62
67 @staticmethod 63 @staticmethod
68 def gen_revision(project): 64 def gen_revision(project):
69 """Hash project to bogus deterministic git hash values.""" 65 """Hash project to bogus deterministic git hash values."""
70 h = hashlib.sha1(project) 66 h = hashlib.sha1(project)
71 return h.hexdigest() 67 return h.hexdigest()
72 68
73 @staticmethod 69 @staticmethod
74 def gen_commit_position(project): 70 def gen_commit_position(project):
75 """Hash project to bogus deterministic Cr-Commit-Position values.""" 71 """Hash project to bogus deterministic Cr-Commit-Position values."""
76 h = hashlib.sha1(project) 72 h = hashlib.sha1(project)
77 return struct.unpack('!I', h.digest()[:4])[0] % 300000 73 return struct.unpack('!I', h.digest()[:4])[0] % 300000
OLDNEW
« no previous file with comments | « recipe_modules/bot_update/example.expected/forced.json ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698