| OLD | NEW |
| (Empty) |
| 1 #!/usr/bin/env python | |
| 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 | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 '''Unit tests for grit.format.policy_templates.writers.template_writer''' | |
| 7 | |
| 8 import os | |
| 9 import sys | |
| 10 if __name__ == '__main__': | |
| 11 sys.path.append(os.path.join(os.path.dirname(__file__), '../../../..')) | |
| 12 | |
| 13 import unittest | |
| 14 | |
| 15 from grit.format.policy_templates.writers import template_writer | |
| 16 | |
| 17 | |
| 18 POLICY_DEFS = [ | |
| 19 {'name': 'zp', 'type': 'string', 'caption': 'a1', 'supported_on': []}, | |
| 20 { | |
| 21 'type': 'group', | |
| 22 'caption': 'z_group1_caption', | |
| 23 'name': 'group1', | |
| 24 'policies': [ | |
| 25 {'name': 'z0', 'type': 'string', 'supported_on': []}, | |
| 26 {'name': 'a0', 'type': 'string', 'supported_on': []} | |
| 27 ] | |
| 28 }, | |
| 29 { | |
| 30 'type': 'group', | |
| 31 'caption': 'b_group2_caption', | |
| 32 'name': 'group2', | |
| 33 'policies': [{'name': 'q', 'type': 'string', 'supported_on': []}], | |
| 34 }, | |
| 35 {'name': 'ap', 'type': 'string', 'caption': 'a2', 'supported_on': []} | |
| 36 ] | |
| 37 | |
| 38 | |
| 39 GROUP_FIRST_SORTED_POLICY_DEFS = [ | |
| 40 { | |
| 41 'type': 'group', | |
| 42 'caption': 'b_group2_caption', | |
| 43 'name': 'group2', | |
| 44 'policies': [{'name': 'q', 'type': 'string', 'supported_on': []}], | |
| 45 }, | |
| 46 { | |
| 47 'type': 'group', | |
| 48 'caption': 'z_group1_caption', | |
| 49 'name': 'group1', | |
| 50 'policies': [ | |
| 51 {'name': 'z0', 'type': 'string', 'supported_on': []}, | |
| 52 {'name': 'a0', 'type': 'string', 'supported_on': []} | |
| 53 ] | |
| 54 }, | |
| 55 {'name': 'ap', 'type': 'string', 'caption': 'a2', 'supported_on': []}, | |
| 56 {'name': 'zp', 'type': 'string', 'caption': 'a1', 'supported_on': []}, | |
| 57 ] | |
| 58 | |
| 59 | |
| 60 IGNORE_GROUPS_SORTED_POLICY_DEFS = [ | |
| 61 {'name': 'a0', 'type': 'string', 'supported_on': []}, | |
| 62 {'name': 'ap', 'type': 'string', 'caption': 'a2', 'supported_on': []}, | |
| 63 {'name': 'q', 'type': 'string', 'supported_on': []}, | |
| 64 {'name': 'z0', 'type': 'string', 'supported_on': []}, | |
| 65 {'name': 'zp', 'type': 'string', 'caption': 'a1', 'supported_on': []}, | |
| 66 ] | |
| 67 | |
| 68 | |
| 69 class TemplateWriterUnittests(unittest.TestCase): | |
| 70 '''Unit tests for templater_writer.py.''' | |
| 71 | |
| 72 def testSortingGroupsFirst(self): | |
| 73 tw = template_writer.TemplateWriter(None, None) | |
| 74 sorted_list = tw.SortPoliciesGroupsFirst(POLICY_DEFS) | |
| 75 self.assertEqual(sorted_list, GROUP_FIRST_SORTED_POLICY_DEFS) | |
| 76 | |
| 77 def testSortingIgnoreGroups(self): | |
| 78 tw = template_writer.TemplateWriter(None, None) | |
| 79 sorted_list = tw.FlattenGroupsAndSortPolicies(POLICY_DEFS) | |
| 80 self.assertEqual(sorted_list, IGNORE_GROUPS_SORTED_POLICY_DEFS) | |
| 81 | |
| 82 | |
| 83 if __name__ == '__main__': | |
| 84 unittest.main() | |
| OLD | NEW |