Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 |
| 11 if __name__ == '__main__': | 11 if __name__ == '__main__': |
| 12 sys.path.append(os.path.join(os.path.dirname(__file__), '../../../..')) | 12 sys.path.append(os.path.join(os.path.dirname(__file__), '../../../..')) |
| 13 | 13 |
| 14 import unittest | 14 import unittest |
| 15 | 15 |
| 16 from grit.format.policy_templates.writers import writer_unittest_common | 16 from grit.format.policy_templates.writers import writer_unittest_common |
| 17 | 17 |
| 18 | 18 |
| 19 TEMPLATE_HEADER="""\ | 19 TEMPLATE_HEADER="""\ |
| 20 // Policy template for Linux. | 20 // Policy template for Linux. |
| 21 // Uncomment the policies you wish to activate and change their values to | 21 // Uncomment the policies you wish to activate and change their values to |
| 22 // something useful for your case. The provided values are for reference only | 22 // something useful for your case. The provided values are for reference only |
| 23 // and do not provide meaningful defaults! | 23 // and do not provide meaningful defaults! |
| 24 { | 24 { |
| 25 """ | 25 """ |
| 26 | 26 |
| 27 TEMPLATE_HEADER_WITH_VERSION="""\ | |
| 28 // chromium version: 39.0.0.0 | |
| 29 // Policy template for Linux. | |
| 30 // Uncomment the policies you wish to activate and change their values to | |
| 31 // something useful for your case. The provided values are for reference only | |
| 32 // and do not provide meaningful defaults! | |
| 33 { | |
| 34 """ | |
| 35 | |
| 27 | 36 |
| 28 HEADER_DELIMETER="""\ | 37 HEADER_DELIMETER="""\ |
| 29 //------------------------------------------------------------------------- | 38 //------------------------------------------------------------------------- |
| 30 """ | 39 """ |
| 31 | 40 |
| 32 | 41 |
| 33 class JsonWriterUnittest(writer_unittest_common.WriterUnittestCommon): | 42 class JsonWriterUnittest(writer_unittest_common.WriterUnittestCommon): |
| 34 '''Unit tests for JsonWriter.''' | 43 '''Unit tests for JsonWriter.''' |
| 35 | 44 |
| 36 def CompareOutputs(self, output, expected_output): | 45 def CompareOutputs(self, output, expected_output): |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 48 expected_output.strip()) | 57 expected_output.strip()) |
| 49 | 58 |
| 50 def testEmpty(self): | 59 def testEmpty(self): |
| 51 # Test the handling of an empty policy list. | 60 # Test the handling of an empty policy list. |
| 52 grd = self.PrepareTest( | 61 grd = self.PrepareTest( |
| 53 '{' | 62 '{' |
| 54 ' "policy_definitions": [],' | 63 ' "policy_definitions": [],' |
| 55 ' "placeholders": [],' | 64 ' "placeholders": [],' |
| 56 ' "messages": {},' | 65 ' "messages": {},' |
| 57 '}') | 66 '}') |
| 58 output = self.GetOutput(grd, 'fr', {'_chromium': '1',}, 'json', 'en') | 67 output = self.GetOutput(grd, 'fr', {'_chromium': '1'}, 'json', 'en') |
| 59 expected_output = TEMPLATE_HEADER + '}' | 68 expected_output = TEMPLATE_HEADER + '}' |
| 60 self.CompareOutputs(output, expected_output) | 69 self.CompareOutputs(output, expected_output) |
| 61 | 70 |
| 71 def testEmptyWithVersion(self): | |
| 72 # Test the handling of an empty policy list. | |
| 73 grd = self.PrepareTest( | |
| 74 '{' | |
| 75 ' "policy_definitions": [],' | |
| 76 ' "placeholders": [],' | |
| 77 ' "messages": {},' | |
| 78 '}') | |
| 79 output = self.GetOutput(grd, 'fr', {'_chromium': '1', 'version':'39.0.0.0'}, 'json', 'en') | |
|
pastarmovj
2014/10/07 14:54:36
Line too long.
cschuet1
2014/10/07 15:42:47
Done.
| |
| 80 expected_output = TEMPLATE_HEADER_WITH_VERSION + '}' | |
| 81 self.CompareOutputs(output, expected_output) | |
| 82 | |
| 62 def testMainPolicy(self): | 83 def testMainPolicy(self): |
| 63 # Tests a policy group with a single policy of type 'main'. | 84 # Tests a policy group with a single policy of type 'main'. |
| 64 grd = self.PrepareTest( | 85 grd = self.PrepareTest( |
| 65 '{' | 86 '{' |
| 66 ' "policy_definitions": [' | 87 ' "policy_definitions": [' |
| 67 ' {' | 88 ' {' |
| 68 ' "name": "MainPolicy",' | 89 ' "name": "MainPolicy",' |
| 69 ' "type": "main",' | 90 ' "type": "main",' |
| 70 ' "caption": "Example Main Policy",' | 91 ' "caption": "Example Main Policy",' |
| 71 ' "desc": "Example Main Policy",' | 92 ' "desc": "Example Main Policy",' |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 398 ' // Policy Two\n' + | 419 ' // Policy Two\n' + |
| 399 HEADER_DELIMETER + | 420 HEADER_DELIMETER + |
| 400 ' // Policy Two\n\n' | 421 ' // Policy Two\n\n' |
| 401 ' //"Policy2": "c"\n\n' | 422 ' //"Policy2": "c"\n\n' |
| 402 '}') | 423 '}') |
| 403 self.CompareOutputs(output, expected_output) | 424 self.CompareOutputs(output, expected_output) |
| 404 | 425 |
| 405 | 426 |
| 406 if __name__ == '__main__': | 427 if __name__ == '__main__': |
| 407 unittest.main() | 428 unittest.main() |
| OLD | NEW |