| 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 grit.clique''' | 6 '''Unit tests for grit.clique''' |
| 7 | 7 |
| 8 import os | 8 import os |
| 9 import sys | 9 import sys |
| 10 if __name__ == '__main__': | 10 if __name__ == '__main__': |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 pass # expected case - 'Bingo bongo' does not start with 'jjj' | 182 pass # expected case - 'Bingo bongo' does not start with 'jjj' |
| 183 | 183 |
| 184 message = tclib.Message(text='jjjBingo bongo') | 184 message = tclib.Message(text='jjjBingo bongo') |
| 185 c = factory.MakeClique(message) | 185 c = factory.MakeClique(message) |
| 186 c.SetCustomType(util.NewClassInstance( | 186 c.SetCustomType(util.NewClassInstance( |
| 187 'grit.clique_unittest.DummyCustomType', clique.CustomType)) | 187 'grit.clique_unittest.DummyCustomType', clique.CustomType)) |
| 188 translation = tclib.Translation(id=message.GetId(), text='Bilingo bolongo') | 188 translation = tclib.Translation(id=message.GetId(), text='Bilingo bolongo') |
| 189 c.AddTranslation(translation, 'fr') | 189 c.AddTranslation(translation, 'fr') |
| 190 self.failUnless(c.MessageForLanguage('fr').GetRealContent().startswith('jjj'
)) | 190 self.failUnless(c.MessageForLanguage('fr').GetRealContent().startswith('jjj'
)) |
| 191 | 191 |
| 192 def testWhitespaceMessagesAreNontranslateable(self): |
| 193 factory = clique.UberClique() |
| 194 |
| 195 message = tclib.Message(text=' \t') |
| 196 c = factory.MakeClique(message, translateable=True) |
| 197 self.failIf(c.IsTranslateable()) |
| 198 |
| 199 message = tclib.Message(text='\n \n ') |
| 200 c = factory.MakeClique(message, translateable=True) |
| 201 self.failIf(c.IsTranslateable()) |
| 202 |
| 203 message = tclib.Message(text='\n hello') |
| 204 c = factory.MakeClique(message, translateable=True) |
| 205 self.failUnless(c.IsTranslateable()) |
| 206 |
| 192 | 207 |
| 193 class DummyCustomType(clique.CustomType): | 208 class DummyCustomType(clique.CustomType): |
| 194 def Validate(self, message): | 209 def Validate(self, message): |
| 195 return message.GetRealContent().startswith('jjj') | 210 return message.GetRealContent().startswith('jjj') |
| 196 def ValidateAndModify(self, lang, translation): | 211 def ValidateAndModify(self, lang, translation): |
| 197 is_ok = self.Validate(translation) | 212 is_ok = self.Validate(translation) |
| 198 self.ModifyEachTextPart(lang, translation) | 213 self.ModifyEachTextPart(lang, translation) |
| 199 def ModifyTextPart(self, lang, text): | 214 def ModifyTextPart(self, lang, text): |
| 200 return 'jjj%s' % text | 215 return 'jjj%s' % text |
| 201 | 216 |
| 202 | 217 |
| 203 if __name__ == '__main__': | 218 if __name__ == '__main__': |
| 204 unittest.main() | 219 unittest.main() |
| OLD | NEW |