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