OLD | NEW |
| (Empty) |
1 #!/usr/bin/env python | |
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 | |
4 # found in the LICENSE file. | |
5 | |
6 '''Unit tests for grit.gather.muppet_strings''' | |
7 | |
8 import os | |
9 import sys | |
10 if __name__ == '__main__': | |
11 sys.path.append(os.path.join(os.path.dirname(__file__), '../..')) | |
12 | |
13 import unittest | |
14 import StringIO | |
15 | |
16 from grit.gather import muppet_strings | |
17 | |
18 class MuppetStringsUnittest(unittest.TestCase): | |
19 def testParsing(self): | |
20 original = '''<strings><BLA desc="Says hello">hello!</BLA><BINGO>YEEEESSS!!!
</BINGO></strings>''' | |
21 gatherer = muppet_strings.MuppetStrings(StringIO.StringIO(original)) | |
22 gatherer.Parse() | |
23 self.failUnless(len(gatherer.GetCliques()) == 2) | |
24 self.failUnless(gatherer.Translate('en').replace('\n', '') == original) | |
25 | |
26 def testEscapingAndLinebreaks(self): | |
27 original = ('''\ | |
28 <strings> | |
29 <LINEBREAK desc="Howdie">Hello | |
30 there | |
31 how | |
32 are | |
33 you?</LINEBREAK> <ESCAPED meaning="bingo">4 < 6</ESCAPED> | |
34 </strings>''') | |
35 gatherer = muppet_strings.MuppetStrings(StringIO.StringIO(original)) | |
36 gatherer.Parse() | |
37 self.failUnless(gatherer.GetCliques()[0].translateable) | |
38 self.failUnless(len(gatherer.GetCliques()) == 2) | |
39 self.failUnless(gatherer.GetCliques()[0].GetMessage().GetRealContent() == | |
40 'Hello\nthere\nhow\nare\nyou?') | |
41 self.failUnless(gatherer.GetCliques()[0].GetMessage().GetDescription() == 'H
owdie') | |
42 self.failUnless(gatherer.GetCliques()[1].GetMessage().GetRealContent() == | |
43 '4 < 6') | |
44 self.failUnless(gatherer.GetCliques()[1].GetMessage().GetMeaning() == 'bingo
') | |
45 | |
46 def testPlaceholders(self): | |
47 original = "<strings><MESSAGE translateable='True'>Hello [![USER]!] how are
you? [![HOUR]!]:[![MINUTE]!]</MESSAGE></strings>" | |
48 gatherer = muppet_strings.MuppetStrings(StringIO.StringIO(original)) | |
49 gatherer.Parse() | |
50 self.failUnless(gatherer.GetCliques()[0].translateable) | |
51 msg = gatherer.GetCliques()[0].GetMessage() | |
52 self.failUnless(len(msg.GetPlaceholders()) == 3) | |
53 ph = msg.GetPlaceholders()[0] | |
54 self.failUnless(ph.GetOriginal() == '[![USER]!]') | |
55 self.failUnless(ph.GetPresentation() == 'USER') | |
56 | |
57 def testTranslateable(self): | |
58 original = "<strings><BINGO translateable='false'>Yo yo hi there</BINGO></st
rings>" | |
59 gatherer = muppet_strings.MuppetStrings(StringIO.StringIO(original)) | |
60 gatherer.Parse() | |
61 msg = gatherer.GetCliques()[0].GetMessage() | |
62 self.failUnless(msg.GetRealContent() == "Yo yo hi there") | |
63 self.failUnless(not gatherer.GetCliques()[0].translateable) | |
64 | |
65 if __name__ == '__main__': | |
66 unittest.main() | |
67 | |
OLD | NEW |