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

Side by Side Diff: tools/grit/grit/grd_reader_unittest.py

Issue 2923103002: Allow GRD reader to process a custom GRDP file stored in a folder different from its parent GRD fil… (Closed)
Patch Set: Correct author name typo Created 3 years, 5 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
« no previous file with comments | « tools/grit/grit/grd_reader.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 </grit>''' 204 </grit>'''
205 pseudo_file = StringIO.StringIO(input) 205 pseudo_file = StringIO.StringIO(input)
206 root = grd_reader.Parse(pseudo_file, '.', defines={'hello': '1'}) 206 root = grd_reader.Parse(pseudo_file, '.', defines={'hello': '1'})
207 207
208 # Check if the ID is set to the name. In the past, there was a bug 208 # Check if the ID is set to the name. In the past, there was a bug
209 # that caused the ID to be a generated number. 209 # that caused the ID to be a generated number.
210 hello = root.GetNodeById('IDS_HELLO') 210 hello = root.GetNodeById('IDS_HELLO')
211 self.failUnless(hello.GetCliques()[0].GetId() == 'IDS_HELLO') 211 self.failUnless(hello.GetCliques()[0].GetId() == 'IDS_HELLO')
212 212
213 def testPartInclusion(self): 213 def testPartInclusion(self):
214 arbitrary_path_grd = u'''\
215 <grit-part>
216 <message name="IDS_TEST5" desc="test5">test5</message>
217 </grit-part>'''
218 arbitrary_path_grd_file = os.path.join(
219 util.TempDir({'arbitrary_path.grp': arbitrary_path_grd}).GetPath(),
220 'arbitrary_path.grp')
214 top_grd = u'''\ 221 top_grd = u'''\
215 <grit latest_public_release="2" current_release="3"> 222 <grit latest_public_release="2" current_release="3">
216 <release seq="3"> 223 <release seq="3">
217 <messages> 224 <messages>
218 <message name="IDS_TEST" desc="test"> 225 <message name="IDS_TEST" desc="test">
219 test 226 test
220 </message> 227 </message>
221 <part file="sub.grp" /> 228 <part file="sub.grp" />
229 <part file="%s" />
222 </messages> 230 </messages>
223 </release> 231 </release>
224 </grit>''' 232 </grit>''' % arbitrary_path_grd_file
225 sub_grd = u'''\ 233 sub_grd = u'''\
226 <grit-part> 234 <grit-part>
227 <message name="IDS_TEST2" desc="test2">test2</message> 235 <message name="IDS_TEST2" desc="test2">test2</message>
228 <part file="subsub.grp" /> 236 <part file="subsub.grp" />
229 <message name="IDS_TEST3" desc="test3">test3</message> 237 <message name="IDS_TEST3" desc="test3">test3</message>
230 </grit-part>''' 238 </grit-part>'''
231 subsub_grd = u'''\ 239 subsub_grd = u'''\
232 <grit-part> 240 <grit-part>
233 <message name="IDS_TEST4" desc="test4">test4</message> 241 <message name="IDS_TEST4" desc="test4">test4</message>
234 </grit-part>''' 242 </grit-part>'''
(...skipping 10 matching lines...) Expand all
245 </message> 253 </message>
246 <part file="subsub.grp"> 254 <part file="subsub.grp">
247 <message desc="test4" name="IDS_TEST4"> 255 <message desc="test4" name="IDS_TEST4">
248 test4 256 test4
249 </message> 257 </message>
250 </part> 258 </part>
251 <message desc="test3" name="IDS_TEST3"> 259 <message desc="test3" name="IDS_TEST3">
252 test3 260 test3
253 </message> 261 </message>
254 </part> 262 </part>
263 <part file="%s">
264 <message desc="test5" name="IDS_TEST5">
265 test5
266 </message>
267 </part>
255 </messages> 268 </messages>
256 </release> 269 </release>
257 </grit>''' 270 </grit>''' % arbitrary_path_grd_file
258 with util.TempDir({'sub.grp': sub_grd, 271 with util.TempDir({'sub.grp': sub_grd,
259 'subsub.grp': subsub_grd}) as temp_dir: 272 'subsub.grp': subsub_grd}) as temp_dir:
260 output = grd_reader.Parse(StringIO.StringIO(top_grd), temp_dir.GetPath()) 273 output = grd_reader.Parse(StringIO.StringIO(top_grd), temp_dir.GetPath())
261 self.assertEqual(expected_output.split(), output.FormatXml().split()) 274 self.assertEqual(expected_output.split(), output.FormatXml().split())
262 275
263 def testPartInclusionFailure(self): 276 def testPartInclusionFailure(self):
264 template = u''' 277 template = u'''
265 <grit latest_public_release="2" current_release="3"> 278 <grit latest_public_release="2" current_release="3">
266 <outputs> 279 <outputs>
267 %s 280 %s
268 </outputs> 281 </outputs>
269 </grit>''' 282 </grit>'''
270 283
271 part_failures = [ 284 part_failures = [
272 (exception.UnexpectedContent, u'<part file="x">fnord</part>'), 285 (exception.UnexpectedContent, u'<part file="x">fnord</part>'),
273 (exception.UnexpectedChild, 286 (exception.UnexpectedChild,
274 u'<part file="x"><output filename="x" type="y" /></part>'), 287 u'<part file="x"><output filename="x" type="y" /></part>'),
288 (exception.FileNotFound, u'<part file="yet_created_x" />'),
275 ] 289 ]
276 for raises, data in part_failures: 290 for raises, data in part_failures:
277 data = StringIO.StringIO(template % data) 291 data = StringIO.StringIO(template % data)
278 self.assertRaises(raises, grd_reader.Parse, data, '.') 292 self.assertRaises(raises, grd_reader.Parse, data, '.')
279 293
280 gritpart_failures = [ 294 gritpart_failures = [
281 (exception.UnexpectedAttribute, u'<grit-part file="xyz"></grit-part>'), 295 (exception.UnexpectedAttribute, u'<grit-part file="xyz"></grit-part>'),
282 (exception.MissingElement, u'<output filename="x" type="y" />'), 296 (exception.MissingElement, u'<output filename="x" type="y" />'),
283 ] 297 ]
284 for raises, data in gritpart_failures: 298 for raises, data in gritpart_failures:
(...skipping 20 matching lines...) Expand all
305 </messages> 319 </messages>
306 </release> 320 </release>
307 </grit>''' % sys.platform 321 </grit>''' % sys.platform
308 with util.TempDir({}) as temp_dir: 322 with util.TempDir({}) as temp_dir:
309 grd_reader.Parse(StringIO.StringIO(grd_text), temp_dir.GetPath(), 323 grd_reader.Parse(StringIO.StringIO(grd_text), temp_dir.GetPath(),
310 target_platform='android') 324 target_platform='android')
311 325
312 326
313 if __name__ == '__main__': 327 if __name__ == '__main__':
314 unittest.main() 328 unittest.main()
OLDNEW
« no previous file with comments | « tools/grit/grit/grd_reader.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698