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