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

Side by Side Diff: grit/grd_reader_unittest.py

Issue 9802029: Make first_ids_file an optional attribute of the .grd file. (Closed) Base URL: http://grit-i18n.googlecode.com/svn/trunk/
Patch Set: Created 8 years, 8 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
OLDNEW
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 grd_reader package''' 6 '''Unit tests for grd_reader package'''
7 7
8 import os 8 import os
9 import sys 9 import sys
10 if __name__ == '__main__': 10 if __name__ == '__main__':
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 </release> 91 </release>
92 </grit>''' 92 </grit>'''
93 pseudo_file = StringIO.StringIO(input) 93 pseudo_file = StringIO.StringIO(input)
94 tree = grd_reader.Parse(pseudo_file, '.') 94 tree = grd_reader.Parse(pseudo_file, '.')
95 95
96 greeting = tree.GetNodeById('IDS_GREETING') 96 greeting = tree.GetNodeById('IDS_GREETING')
97 self.failUnless(greeting.GetCliques()[0].GetMessage().GetRealContent() == 97 self.failUnless(greeting.GetCliques()[0].GetMessage().GetRealContent() ==
98 'This is a very long line with no linebreaks yes yes it ' 98 'This is a very long line with no linebreaks yes yes it '
99 'stretches on and on and on!') 99 'stretches on and on and on!')
100 100
101 def testAssignFirstIds(self): 101 def doTestAssignFirstIds(self, first_ids_path):
102 input = u'''<?xml version="1.0" encoding="UTF-8"?> 102 input = u'''<?xml version="1.0" encoding="UTF-8"?>
103 <grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_ dir="."> 103 <grit latest_public_release="2" source_lang_id="en-US" current_release="3"
104 base_dir="." first_ids_file="%s">
104 <release seq="3"> 105 <release seq="3">
105 <messages> 106 <messages>
106 <message name="IDS_TEST" desc="test"> 107 <message name="IDS_TEST" desc="test">
107 test 108 test
108 </message> 109 </message>
109 </messages> 110 </messages>
110 </release> 111 </release>
111 </grit>''' 112 </grit>''' % first_ids_path
112 pseudo_file = StringIO.StringIO(input) 113 pseudo_file = StringIO.StringIO(input)
113 root = grd_reader.Parse(pseudo_file, '.')
114 grit_root_dir = os.path.join(os.path.abspath(os.path.dirname(__file__)), 114 grit_root_dir = os.path.join(os.path.abspath(os.path.dirname(__file__)),
115 '..') 115 '..')
116 root.AssignFirstIds( 116 fake_input_path = os.path.join(
117 os.path.join(grit_root_dir, 117 grit_root_dir, "grit/testdata/chrome/app/generated_resources.grd")
118 "grit/testdata/chrome/app/generated_resources.grd"), 118 root = grd_reader.Parse(pseudo_file, os.path.split(fake_input_path)[0])
119 os.path.join(grit_root_dir, "grit/testdata/tools/grit/resource_ids"), 119 root.AssignFirstIds(fake_input_path, {})
120 {})
121 messages_node = root.children[0].children[0] 120 messages_node = root.children[0].children[0]
122 self.failUnless(isinstance(messages_node, empty.MessagesNode)) 121 self.failUnless(isinstance(messages_node, empty.MessagesNode))
123 self.failUnless(messages_node.attrs["first_id"] != 122 self.failUnless(messages_node.attrs["first_id"] !=
124 empty.MessagesNode().DefaultAttributes()["first_id"]) 123 empty.MessagesNode().DefaultAttributes()["first_id"])
125 124
125 def testAssignFirstIds(self):
126 self.doTestAssignFirstIds("../../tools/grit/resource_ids")
127
128 def testAssignFirstIdsUseGritDir(self):
129 self.doTestAssignFirstIds("GRIT_DIR/grit/testdata/tools/grit/resource_ids")
130
126 def testAssignFirstIdsMultipleMessages(self): 131 def testAssignFirstIdsMultipleMessages(self):
127 """If there are multiple messages sections, the resource_ids file 132 """If there are multiple messages sections, the resource_ids file
128 needs to list multiple first_id values.""" 133 needs to list multiple first_id values."""
129 input = u'''<?xml version="1.0" encoding="UTF-8"?> 134 input = u'''<?xml version="1.0" encoding="UTF-8"?>
130 <grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_ dir="."> 135 <grit latest_public_release="2" source_lang_id="en-US" current_release="3"
136 base_dir="." first_ids_file="resource_ids">
131 <release seq="3"> 137 <release seq="3">
132 <messages> 138 <messages>
133 <message name="IDS_TEST" desc="test"> 139 <message name="IDS_TEST" desc="test">
134 test 140 test
135 </message> 141 </message>
136 </messages> 142 </messages>
137 <messages> 143 <messages>
138 <message name="IDS_TEST2" desc="test"> 144 <message name="IDS_TEST2" desc="test">
139 test2 145 test2
140 </message> 146 </message>
141 </messages> 147 </messages>
142 </release> 148 </release>
143 </grit>''' 149 </grit>'''
144 pseudo_file = StringIO.StringIO(input) 150 pseudo_file = StringIO.StringIO(input)
145 root = grd_reader.Parse(pseudo_file, '.')
146 grit_root_dir = os.path.join(os.path.abspath(os.path.dirname(__file__)), 151 grit_root_dir = os.path.join(os.path.abspath(os.path.dirname(__file__)),
147 '..') 152 '..')
148 root.AssignFirstIds( 153 fake_input_path = os.path.join(grit_root_dir, "grit/testdata/test.grd")
149 # This file does not actually exist, but must use absolute 154
150 # path as resource_ids has '' for SRCDIR (see special handling 155 root = grd_reader.Parse(pseudo_file, os.path.split(fake_input_path)[0])
151 # in grit.node.misc). 156 root.AssignFirstIds(fake_input_path, {})
152 os.path.join(grit_root_dir, "grit/testdata/test.grd"),
153 os.path.join(grit_root_dir, "grit/testdata/resource_ids"),
154 {})
155 messages_node = root.children[0].children[0] 157 messages_node = root.children[0].children[0]
156 self.assertTrue(isinstance(messages_node, empty.MessagesNode)) 158 self.assertTrue(isinstance(messages_node, empty.MessagesNode))
157 self.assertEqual('100', messages_node.attrs["first_id"]) 159 self.assertEqual('100', messages_node.attrs["first_id"])
158 messages_node = root.children[0].children[1] 160 messages_node = root.children[0].children[1]
159 self.assertTrue(isinstance(messages_node, empty.MessagesNode)) 161 self.assertTrue(isinstance(messages_node, empty.MessagesNode))
160 self.assertEqual('10000', messages_node.attrs["first_id"]) 162 self.assertEqual('10000', messages_node.attrs["first_id"])
161 163
162 def testUseNameForIdAndPpIfdef(self): 164 def testUseNameForIdAndPpIfdef(self):
163 input = u'''<?xml version="1.0" encoding="UTF-8"?> 165 input = u'''<?xml version="1.0" encoding="UTF-8"?>
164 <grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_ dir="."> 166 <grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_ dir=".">
(...skipping 10 matching lines...) Expand all
175 pseudo_file = StringIO.StringIO(input) 177 pseudo_file = StringIO.StringIO(input)
176 root = grd_reader.Parse(pseudo_file, '.', defines={'hello': '1'}) 178 root = grd_reader.Parse(pseudo_file, '.', defines={'hello': '1'})
177 179
178 # Check if the ID is set to the name. In the past, there was a bug 180 # Check if the ID is set to the name. In the past, there was a bug
179 # that caused the ID to be a generated number. 181 # that caused the ID to be a generated number.
180 hello = root.GetNodeById('IDS_HELLO') 182 hello = root.GetNodeById('IDS_HELLO')
181 self.failUnless(hello.GetCliques()[0].GetId() == 'IDS_HELLO') 183 self.failUnless(hello.GetCliques()[0].GetId() == 'IDS_HELLO')
182 184
183 if __name__ == '__main__': 185 if __name__ == '__main__':
184 unittest.main() 186 unittest.main()
OLDNEW
« no previous file with comments | « grit/grd_reader.py ('k') | grit/node/misc.py » ('j') | grit/node/misc.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698