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

Side by Side Diff: testing/variations/PRESUBMIT.py

Issue 2296493002: Merge all Field Trial Testing Configuration Together (Closed)
Patch Set: Review 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
OLDNEW
1 # Copyright 2015 The Chromium Authors. All rights reserved. 1 # Copyright 2015 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 """Presubmit script validating field trial configs. 4 """Presubmit script validating field trial configs.
5 5
6 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts 6 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
7 for more details on the presubmit API built into depot_tools. 7 for more details on the presubmit API built into depot_tools.
8 """ 8 """
9 9
10 import json 10 import json
(...skipping 26 matching lines...) Expand all
37 message_type: Type of message from |output_api| to return in the case of 37 message_type: Type of message from |output_api| to return in the case of
38 errors/warnings. 38 errors/warnings.
39 39
40 Returns: 40 Returns:
41 A list of |message_type| messages. In the case of all tests passing with no 41 A list of |message_type| messages. In the case of all tests passing with no
42 warnings/errors, this will return []. 42 warnings/errors, this will return [].
43 """ 43 """
44 if not isinstance(json_data, dict): 44 if not isinstance(json_data, dict):
45 return [message_type( 45 return [message_type(
46 'Malformed config file %s: Expecting dict' % file_path)] 46 'Malformed config file %s: Expecting dict' % file_path)]
47 for (study, groups) in json_data.iteritems(): 47 for (trial, group_configs) in json_data.iteritems():
48 if not isinstance(study, unicode): 48 if not isinstance(trial, unicode):
49 return [message_type( 49 return [message_type(
50 'Malformed config file %s: Expecting keys to be string, got %s' 50 'Malformed config file %s: Expecting keys to be string, got %s' %
51 % (file_path, type(study)))] 51 (file_path, type(trial)))]
52 if not isinstance(groups, list): 52 if not isinstance(group_configs, list):
53 return [message_type( 53 return [message_type(
54 'Malformed config file %s: Expecting list for study %s' 54 'Malformed config file %s: Expecting list for trial %s' % (file_path,
55 % (file_path, study))] 55 trial))]
56 for group in groups: 56 for group_config in group_configs:
57 if not isinstance(group, dict): 57 if not isinstance(group_config, dict):
58 return [message_type('Malformed config file %s: Expecting dict for '
59 'group config in Trial[%s]' % (file_path, trial))]
60 if not 'groups' in group_config:
58 return [message_type( 61 return [message_type(
59 'Malformed config file %s: Expecting dict for group in ' 62 'Malformed config file %s: Missing valid groups for group config '
60 'Study[%s]' % (file_path, study))] 63 'in Trial[%s]' % (file_path, trial))]
61 if not 'group_name' in group or not isinstance(group['group_name'], 64 if not isinstance(group_config['groups'], list):
62 unicode): 65 return [message_type('Malformed config file %s: Expecting list for '
63 return [message_type( 66 'groups in Trial[%s]' % (file_path, trial))]
Alexei Svitkine (slow) 2016/08/31 20:17:27 Nit: There's a bunch of repetition in these messag
robliao 2016/09/01 21:49:07 Done.
64 'Malformed config file %s: Missing valid group_name for group' 67 for group in group_config['groups']:
65 ' in Study[%s]' % (file_path, study))] 68 if not 'group_name' in group or not isinstance(group['group_name'],
66 if 'params' in group: 69 unicode):
67 params = group['params']
68 if not isinstance(params, dict):
69 return [message_type( 70 return [message_type(
70 'Malformed config file %s: Invalid params for Group[%s]' 71 'Malformed config file %s: Missing valid group_name for group in '
71 ' in Study[%s]' % (file_path, group['group_name'], 72 'Trial[%s]' % (file_path, trial))]
72 study))] 73 if 'params' in group:
73 for (key, value) in params.iteritems(): 74 params = group['params']
74 if not isinstance(key, unicode) or not isinstance(value, 75 if not isinstance(params, dict):
75 unicode):
76 return [message_type( 76 return [message_type(
77 'Malformed config file %s: Invalid params for Group[%s]' 77 'Malformed config file %s: Invalid params for Group[%s] in '
78 ' in Study[%s]' % (file_path, group['group_name'], 78 'Trial[%s]' % (file_path, group['group_name'], trial))]
79 study))] 79 for (key, value) in params.iteritems():
80 for key in group.keys(): 80 if not isinstance(key, unicode) or not isinstance(value, unicode):
81 if key not in VALID_GROUP_KEYS: 81 return [message_type('Malformed config file %s: Invalid params '
82 return [message_type( 82 'for Group[%s] in Study[%s]' % (file_path,
83 'Malformed config file %s: Key[%s] in Group[%s] in Study[%s] ' 83 group['group_name'], trial))]
84 'is not a valid key.' % ( 84 for key in group.keys():
85 file_path, key, group['group_name'], study))] 85 if key not in VALID_GROUP_KEYS:
86 return [message_type(
87 'Malformed config file %s: Key[%s] in Group[%s] in Trial[%s] '
88 'is not a valid key.' % (file_path, key,
89 group['group_name'], trial))]
90 if not 'platforms' in group_config:
91 return [message_type('Malformed config file %s: Missing valid '
92 'platforms for group config in Trial[%s]' % (file_path, trial))]
93 if not isinstance(group_config['platforms'], list):
94 return [message_type('Malformed config file %s: Expecting list for '
95 'platforms in Trial[%s]' % (file_path, trial))]
96 supported_platforms = ['android', 'chromeos', 'ios', 'linux', 'mac',
97 'win']
98 unsupported_platforms = list(set(group_config['platforms']).difference(
99 supported_platforms))
100 if unsupported_platforms:
101 return [message_type('Malformed config file %s: Unsupported platforms '
102 '%s in Trial[%s]' % (file_path, unsupported_platforms, trial))]
86 103
87 return [] 104 return []
88 105
89 def CheckPretty(contents, file_path, message_type): 106 def CheckPretty(contents, file_path, message_type):
90 """Validates the pretty printing of fieldtrial configuration. 107 """Validates the pretty printing of fieldtrial configuration.
91 108
92 Args: 109 Args:
93 contents: File contents as a string. 110 contents: File contents as a string.
94 file_path: String representing the path to the JSON file. 111 file_path: String representing the path to the JSON file.
95 message_type: Type of message from |output_api| to return in the case of 112 message_type: Type of message from |output_api| to return in the case of
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 return CommonChecks(input_api, output_api) 150 return CommonChecks(input_api, output_api)
134 151
135 152
136 def main(argv): 153 def main(argv):
137 content = open(argv[1]).read() 154 content = open(argv[1]).read()
138 pretty = PrettyPrint(content) 155 pretty = PrettyPrint(content)
139 open(argv[1],'w').write(pretty) 156 open(argv[1],'w').write(pretty)
140 157
141 if __name__ == "__main__": 158 if __name__ == "__main__":
142 sys.exit(main(sys.argv)) 159 sys.exit(main(sys.argv))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698