OLD | NEW |
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__': |
11 sys.path.append(os.path.join(os.path.dirname(__file__), '..')) | 11 sys.path.append(os.path.join(os.path.dirname(__file__), '..')) |
12 | 12 |
13 import unittest | 13 import unittest |
14 import StringIO | 14 import StringIO |
15 | 15 |
16 from grit import exception | 16 from grit import exception |
17 from grit import grd_reader | 17 from grit import grd_reader |
18 from grit import util | 18 from grit import util |
| 19 from grit.node import base |
19 from grit.node import empty | 20 from grit.node import empty |
20 | 21 |
21 | 22 |
22 class GrdReaderUnittest(unittest.TestCase): | 23 class GrdReaderUnittest(unittest.TestCase): |
23 def testParsingAndXmlOutput(self): | 24 def testParsingAndXmlOutput(self): |
24 input = u'''<?xml version="1.0" encoding="UTF-8"?> | 25 input = u'''<?xml version="1.0" encoding="UTF-8"?> |
25 <grit base_dir="." current_release="3" latest_public_release="2" source_lang_id=
"en-US"> | 26 <grit base_dir="." current_release="3" latest_public_release="2" source_lang_id=
"en-US"> |
26 <release seq="3"> | 27 <release seq="3"> |
27 <includes> | 28 <includes> |
28 <include file="images/logo.gif" name="ID_LOGO" type="gif" /> | 29 <include file="images/logo.gif" name="ID_LOGO" type="gif" /> |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 | 279 |
279 gritpart_failures = [ | 280 gritpart_failures = [ |
280 (exception.UnexpectedAttribute, u'<grit-part file="xyz"></grit-part>'), | 281 (exception.UnexpectedAttribute, u'<grit-part file="xyz"></grit-part>'), |
281 (exception.MissingElement, u'<output filename="x" type="y" />'), | 282 (exception.MissingElement, u'<output filename="x" type="y" />'), |
282 ] | 283 ] |
283 for raises, data in gritpart_failures: | 284 for raises, data in gritpart_failures: |
284 top_grd = StringIO.StringIO(template % u'<part file="bad.grp" />') | 285 top_grd = StringIO.StringIO(template % u'<part file="bad.grp" />') |
285 with util.TempDir({'bad.grp': data}) as temp_dir: | 286 with util.TempDir({'bad.grp': data}) as temp_dir: |
286 self.assertRaises(raises, grd_reader.Parse, top_grd, temp_dir.GetPath()) | 287 self.assertRaises(raises, grd_reader.Parse, top_grd, temp_dir.GetPath()) |
287 | 288 |
| 289 def testEarlyEnoughPlatformSpecification(self): |
| 290 # This is a regression test for issue |
| 291 # https://code.google.com/p/grit-i18n/issues/detail?id=23 |
| 292 # |
| 293 # This test only works on platforms for which one of the is_xyz |
| 294 # shortcuts in .grd expressions is true. If this string remains |
| 295 # empty, abort the test. |
| 296 platform = base.Node.GetPlatformAssertion(sys.platform) |
| 297 if not platform: |
| 298 return |
| 299 |
| 300 grd_text = u'''<?xml version="1.0" encoding="UTF-8"?> |
| 301 <grit latest_public_release="1" current_release="1"> |
| 302 <release seq="1"> |
| 303 <messages> |
| 304 <if expr="not pp_ifdef('use_titlecase')"> |
| 305 <message name="IDS_XYZ">foo</message> |
| 306 </if> |
| 307 <!-- The assumption is that use_titlecase is never true for |
| 308 this platform. When the platform isn't set to 'android' |
| 309 early enough, we get a duplicate message name. --> |
| 310 <if expr="%s"> |
| 311 <message name="IDS_XYZ">boo</message> |
| 312 </if> |
| 313 </messages> |
| 314 </release> |
| 315 </grit>''' % platform |
| 316 with util.TempDir({}) as temp_dir: |
| 317 grd_reader.Parse(StringIO.StringIO(grd_text), temp_dir.GetPath(), |
| 318 target_platform='android') |
| 319 |
288 | 320 |
289 if __name__ == '__main__': | 321 if __name__ == '__main__': |
290 unittest.main() | 322 unittest.main() |
OLD | NEW |