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

Side by Side Diff: grit/format/policy_templates/writers/json_writer_unittest.py

Issue 14940026: Fixes the policy template generator to work predictably even with Python hash randomization turned … (Closed) Base URL: http://grit-i18n.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 7 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 | Annotate | Revision Log
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 '''Unit tests for grit.format.policy_templates.writers.json_writer''' 6 '''Unit tests for grit.format.policy_templates.writers.json_writer'''
7 7
8 8
9 import os 9 import os
10 import sys 10 import sys
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 example = { 236 example = {
237 'bool': True, 237 'bool': True,
238 'int': 10, 238 'int': 10,
239 'string': 'abc', 239 'string': 'abc',
240 'list': [1, 2, 3], 240 'list': [1, 2, 3],
241 'dict': { 241 'dict': {
242 'a': 1, 242 'a': 1,
243 'b': 2, 243 'b': 2,
244 } 244 }
245 } 245 }
246 # Encode |value| here, to make sure the string encoded within the reg_writer
247 # and the expected value are the same.
248 value = str(example)
249 grd = self.PrepareTest( 246 grd = self.PrepareTest(
250 '{' 247 '{'
251 ' "policy_definitions": [' 248 ' "policy_definitions": ['
252 ' {' 249 ' {'
253 ' "name": "DictionaryPolicy",' 250 ' "name": "DictionaryPolicy",'
254 ' "type": "dict",' 251 ' "type": "dict",'
255 ' "caption": "Example Dictionary Policy",' 252 ' "caption": "Example Dictionary Policy",'
256 ' "desc": "Example Dictionary Policy",' 253 ' "desc": "Example Dictionary Policy",'
257 ' "supported_on": ["chrome.linux:8-"],' 254 ' "supported_on": ["chrome.linux:8-"],'
258 ' "example_value": ' + value + 255 ' "example_value": ' + str(example) +
259 ' },' 256 ' },'
260 ' ],' 257 ' ],'
261 ' "placeholders": [],' 258 ' "placeholders": [],'
262 ' "messages": {},' 259 ' "messages": {},'
263 '}') 260 '}')
264 output = self.GetOutput(grd, 'fr', {'_chromium' : '1'}, 'json', 'en') 261 output = self.GetOutput(grd, 'fr', {'_chromium' : '1'}, 'json', 'en')
265 expected_output = ( 262 expected_output = (
266 TEMPLATE_HEADER + 263 TEMPLATE_HEADER +
267 ' // Example Dictionary Policy\n' + 264 ' // Example Dictionary Policy\n' +
268 HEADER_DELIMETER + 265 HEADER_DELIMETER +
269 ' // Example Dictionary Policy\n\n' 266 ' // Example Dictionary Policy\n\n'
270 ' //"DictionaryPolicy": ' + str(eval(value)) + '\n\n' 267 ' //"DictionaryPolicy": {\'bool\': True, \'dict\': {\'a\': 1, '
268 '\'b\': 2}, \'int\': 10, \'list\': [1, 2, 3], \'string\': \'abc\'}\n\n'
271 '}') 269 '}')
272 self.CompareOutputs(output, expected_output) 270 self.CompareOutputs(output, expected_output)
273 271
274 def testNonSupportedPolicy(self): 272 def testNonSupportedPolicy(self):
275 # Tests a policy that is not supported on Linux, so it shouldn't 273 # Tests a policy that is not supported on Linux, so it shouldn't
276 # be included in the JSON file. 274 # be included in the JSON file.
277 grd = self.PrepareTest( 275 grd = self.PrepareTest(
278 '{' 276 '{'
279 ' "policy_definitions": [' 277 ' "policy_definitions": ['
280 ' {' 278 ' {'
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 ' // Policy Two\n' + 331 ' // Policy Two\n' +
334 HEADER_DELIMETER + 332 HEADER_DELIMETER +
335 ' // Policy Two\n\n' 333 ' // Policy Two\n\n'
336 ' //"Policy2": "c"\n\n' 334 ' //"Policy2": "c"\n\n'
337 '}') 335 '}')
338 self.CompareOutputs(output, expected_output) 336 self.CompareOutputs(output, expected_output)
339 337
340 338
341 if __name__ == '__main__': 339 if __name__ == '__main__':
342 unittest.main() 340 unittest.main()
OLDNEW
« no previous file with comments | « grit/format/policy_templates/policy_template_generator.py ('k') | grit/format/policy_templates/writers/reg_writer_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698