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

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

Issue 7994004: Initial source commit to grit-i18n project. (Closed) Base URL: http://grit-i18n.googlecode.com/svn/trunk/
Patch Set: Created 9 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 | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 #!/usr/bin/python2.4
2 # Copyright (c) 2011 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.json_writer'''
7
8
9 import os
10 import sys
11 if __name__ == '__main__':
12 sys.path.append(os.path.join(os.path.dirname(sys.argv[0]), '../../../..'))
13
14 import unittest
15
16 from grit.format.policy_templates.writers import writer_unittest_common
17
18
19 class JsonWriterUnittest(writer_unittest_common.WriterUnittestCommon):
20 '''Unit tests for JsonWriter.'''
21
22 def CompareOutputs(self, output, expected_output):
23 '''Compares the output of the json_writer with its expected output.
24
25 Args:
26 output: The output of the json writer as returned by grit.
27 expected_output: The expected output.
28
29 Raises:
30 AssertionError: if the two strings are not equivalent.
31 '''
32 self.assertEquals(
33 output.strip(),
34 expected_output.strip())
35
36 def testEmpty(self):
37 # Test the handling of an empty policy list.
38 grd = self.PrepareTest(
39 '{'
40 ' "policy_definitions": [],'
41 ' "placeholders": [],'
42 ' "messages": {},'
43 '}')
44 output = self.GetOutput(grd, 'fr', {'_chromium': '1',}, 'json', 'en')
45 expected_output = '{\n}'
46 self.CompareOutputs(output, expected_output)
47
48 def testMainPolicy(self):
49 # Tests a policy group with a single policy of type 'main'.
50 grd = self.PrepareTest(
51 '{'
52 ' "policy_definitions": ['
53 ' {'
54 ' "name": "MainPolicy",'
55 ' "type": "main",'
56 ' "caption": "",'
57 ' "desc": "",'
58 ' "supported_on": ["chrome.linux:8-"],'
59 ' "example_value": True'
60 ' },'
61 ' ],'
62 ' "placeholders": [],'
63 ' "messages": {},'
64 '}')
65 output = self.GetOutput(grd, 'fr', {'_google_chrome' : '1'}, 'json', 'en')
66 expected_output = (
67 '{\n'
68 ' "MainPolicy": true\n'
69 '}')
70 self.CompareOutputs(output, expected_output)
71
72 def testStringPolicy(self):
73 # Tests a policy group with a single policy of type 'string'.
74 grd = self.PrepareTest(
75 '{'
76 ' "policy_definitions": ['
77 ' {'
78 ' "name": "StringPolicy",'
79 ' "type": "string",'
80 ' "caption": "",'
81 ' "desc": "",'
82 ' "supported_on": ["chrome.linux:8-"],'
83 ' "example_value": "hello, world!"'
84 ' },'
85 ' ],'
86 ' "placeholders": [],'
87 ' "messages": {},'
88 '}')
89 output = self.GetOutput(grd, 'fr', {'_chromium' : '1'}, 'json', 'en')
90 expected_output = (
91 '{\n'
92 ' "StringPolicy": "hello, world!"\n'
93 '}')
94 self.CompareOutputs(output, expected_output)
95
96 def testIntPolicy(self):
97 # Tests a policy group with a single policy of type 'string'.
98 grd = self.PrepareTest(
99 '{'
100 ' "policy_definitions": ['
101 ' {'
102 ' "name": "IntPolicy",'
103 ' "type": "int",'
104 ' "caption": "",'
105 ' "desc": "",'
106 ' "supported_on": ["chrome.linux:8-"],'
107 ' "example_value": 15'
108 ' },'
109 ' ],'
110 ' "placeholders": [],'
111 ' "messages": {},'
112 '}')
113 output = self.GetOutput(grd, 'fr', {'_chromium' : '1'}, 'json', 'en')
114 expected_output = (
115 '{\n'
116 ' "IntPolicy": 15\n'
117 '}')
118 self.CompareOutputs(output, expected_output)
119
120 def testIntEnumPolicy(self):
121 # Tests a policy group with a single policy of type 'int-enum'.
122 grd = self.PrepareTest(
123 '{'
124 ' "policy_definitions": ['
125 ' {'
126 ' "name": "EnumPolicy",'
127 ' "type": "int-enum",'
128 ' "caption": "",'
129 ' "desc": "",'
130 ' "items": ['
131 ' {"name": "ProxyServerDisabled", "value": 0, "caption": ""},'
132 ' {"name": "ProxyServerAutoDetect", "value": 1, "caption": ""},'
133 ' ],'
134 ' "supported_on": ["chrome.linux:8-"],'
135 ' "example_value": 1'
136 ' },'
137 ' ],'
138 ' "placeholders": [],'
139 ' "messages": {},'
140 '}')
141 output = self.GetOutput(grd, 'fr', {'_google_chrome': '1'}, 'json', 'en')
142 expected_output = (
143 '{\n'
144 ' "EnumPolicy": 1\n'
145 '}')
146 self.CompareOutputs(output, expected_output)
147
148 def testStringEnumPolicy(self):
149 # Tests a policy group with a single policy of type 'string-enum'.
150 grd = self.PrepareTest(
151 '{'
152 ' "policy_definitions": ['
153 ' {'
154 ' "name": "EnumPolicy",'
155 ' "type": "string-enum",'
156 ' "caption": "",'
157 ' "desc": "",'
158 ' "items": ['
159 ' {"name": "ProxyServerDisabled", "value": "one",'
160 ' "caption": ""},'
161 ' {"name": "ProxyServerAutoDetect", "value": "two",'
162 ' "caption": ""},'
163 ' ],'
164 ' "supported_on": ["chrome.linux:8-"],'
165 ' "example_value": "one"'
166 ' },'
167 ' ],'
168 ' "placeholders": [],'
169 ' "messages": {},'
170 '}')
171 output = self.GetOutput(grd, 'fr', {'_google_chrome': '1'}, 'json', 'en')
172 expected_output = (
173 '{\n'
174 ' "EnumPolicy": "one"\n'
175 '}')
176 self.CompareOutputs(output, expected_output)
177
178 def testListPolicy(self):
179 # Tests a policy group with a single policy of type 'list'.
180 grd = self.PrepareTest(
181 '{'
182 ' "policy_definitions": ['
183 ' {'
184 ' "name": "ListPolicy",'
185 ' "type": "list",'
186 ' "caption": "",'
187 ' "desc": "",'
188 ' "supported_on": ["chrome.linux:8-"],'
189 ' "example_value": ["foo", "bar"]'
190 ' },'
191 ' ],'
192 ' "placeholders": [],'
193 ' "messages": {},'
194 '}')
195 output = self.GetOutput(grd, 'fr', {'_chromium' : '1'}, 'json', 'en')
196 expected_output = (
197 '{\n'
198 ' "ListPolicy": ["foo", "bar"]\n'
199 '}')
200 self.CompareOutputs(output, expected_output)
201
202 def testNonSupportedPolicy(self):
203 # Tests a policy that is not supported on Linux, so it shouldn't
204 # be included in the JSON file.
205 grd = self.PrepareTest(
206 '{'
207 ' "policy_definitions": ['
208 ' {'
209 ' "name": "NonLinuxPolicy",'
210 ' "type": "list",'
211 ' "caption": "",'
212 ' "desc": "",'
213 ' "supported_on": ["chrome.mac:8-"],'
214 ' "example_value": ["a"]'
215 ' },'
216 ' ],'
217 ' "placeholders": [],'
218 ' "messages": {},'
219 '}')
220 output = self.GetOutput(grd, 'fr', {'_chromium' : '1'}, 'json', 'en')
221 expected_output = '{\n}'
222 self.CompareOutputs(output, expected_output)
223
224 def testPolicyGroup(self):
225 # Tests a policy group that has more than one policies.
226 grd = self.PrepareTest(
227 '{'
228 ' "policy_definitions": ['
229 ' {'
230 ' "name": "Group1",'
231 ' "type": "group",'
232 ' "caption": "",'
233 ' "desc": "",'
234 ' "policies": [{'
235 ' "name": "Policy1",'
236 ' "type": "list",'
237 ' "caption": "",'
238 ' "desc": "",'
239 ' "supported_on": ["chrome.linux:8-"],'
240 ' "example_value": ["a", "b"]'
241 ' },{'
242 ' "name": "Policy2",'
243 ' "type": "string",'
244 ' "caption": "",'
245 ' "desc": "",'
246 ' "supported_on": ["chrome.linux:8-"],'
247 ' "example_value": "c"'
248 ' }],'
249 ' },'
250 ' ],'
251 ' "placeholders": [],'
252 ' "messages": {},'
253 '}')
254 output = self.GetOutput(grd, 'fr', {'_chromium' : '1'}, 'json', 'en')
255 expected_output = (
256 '{\n'
257 ' "Policy1": ["a", "b"],\n'
258 ' "Policy2": "c"\n'
259 '}')
260 self.CompareOutputs(output, expected_output)
261
262
263 if __name__ == '__main__':
264 unittest.main()
OLDNEW
« no previous file with comments | « grit/format/policy_templates/writers/json_writer.py ('k') | grit/format/policy_templates/writers/mock_writer.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698