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

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

Issue 865563002: Add a Policy template writer that generates Android resources which can be exposed through Android'… (Closed) Base URL: https://chromium.googlesource.com/external/grit-i18n.git@master
Patch Set: Rebased + Changes to Docwriter + Unittests Created 5 years, 10 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
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 # Copyright (c) 2015 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.android_policy_writer'''
7
8
9 import os
10 import sys
11 if __name__ == '__main__':
12 sys.path.append(os.path.join(os.path.dirname(__file__), '../../../..'))
13
14 import unittest
15 from xml.dom import minidom
16
17 from grit.format.policy_templates.writers import writer_unittest_common
18 from grit.format.policy_templates.writers import android_policy_writer
19
20 class AndroidPolicyWriterUnittest(writer_unittest_common.WriterUnittestCommon):
Nico 2015/03/02 19:02:06 nit: two newlines
knn 2015/03/02 19:54:35 Done.
21 '''Unit tests to test assumptions in Android Policy Writer'''
22
23 def testPolicyWithoutItems(self):
24 # Test an example policy without items.
25 policy = {
26 'name': '_policy_name',
27 'caption': '_policy_caption',
28 'desc': 'This is a long policy caption. More than one sentence in a single line because it is very important.\nIgnore this.'
29 }
30 writer = android_policy_writer.GetWriter({})
31 writer.Init()
32 writer.BeginTemplate()
33 writer.WritePolicy(policy)
34 self.assertEquals(
35 writer._resources.toxml(),
36 '<resources>'
37 '<string name="_policy_nameTitle">_policy_caption</string>'
38 '<string name="_policy_nameDesc">This is a long policy caption.'
39 ' More than one sentence in a single line because it is very important.< /string>'
40 '</resources>')
41
42 def testPolicyWithItems(self):
43 # Test an example policy without items.
44 policy = {
45 'name': '_policy_name',
46 'caption': '_policy_caption',
47 'desc': '_policy_desc_first.\n_ignored_policy_desc',
48 'items': [
49 {
50 'caption':'_caption1',
51 'value':'_value1',
52 },
53 {
54 'caption':'_caption2',
55 'value':'_value2',
56 }
57 ]
58 }
59 writer = android_policy_writer.GetWriter({})
60 writer.Init()
61 writer.BeginTemplate()
62 writer.WritePolicy(policy)
63 self.assertEquals(
64 writer._resources.toxml(),
65 '<resources>'
66 '<string name="_policy_nameTitle">_policy_caption</string>'
67 '<string name="_policy_nameDesc">_policy_desc_first.</string>'
68 '<string-array name="_policy_nameEntries">'
69 '<item>_caption1</item>'
70 '<item>_caption2</item>'
71 '</string-array>'
72 '<string-array name="_policy_nameValues">'
73 '<item>_value1</item>'
74 '<item>_value2</item>'
75 '</string-array>'
76 '</resources>')
77
78 if __name__ == '__main__':
79 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698