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

Unified Diff: grit/xtb_reader_unittest.py

Issue 7994004: Initial source commit to grit-i18n project. (Closed) Base URL: http://grit-i18n.googlecode.com/svn/trunk/
Patch Set: Created 9 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « grit/xtb_reader.py ('k') | grit_info.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: grit/xtb_reader_unittest.py
===================================================================
--- grit/xtb_reader_unittest.py (revision 0)
+++ grit/xtb_reader_unittest.py (revision 0)
@@ -0,0 +1,83 @@
+#!/usr/bin/python2.4
+# Copyright (c) 2011 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+'''Unit tests for grit.xtb_reader'''
+
+
+import os
+import sys
+if __name__ == '__main__':
+ sys.path.append(os.path.join(os.path.dirname(sys.argv[0]), '..'))
+
+import StringIO
+import unittest
+
+from grit import xtb_reader
+from grit import clique
+from grit import grd_reader
+from grit import tclib
+from grit import util
+
+
+class XtbReaderUnittest(unittest.TestCase):
+ def testParsing(self):
+ xtb_file = StringIO.StringIO('''<?xml version="1.0" encoding="UTF-8"?>
+ <!DOCTYPE translationbundle>
+ <translationbundle lang="fr">
+ <translation id="5282608565720904145">Bingo.</translation>
+ <translation id="2955977306445326147">Bongo longo.</translation>
+ <translation id="238824332917605038">Hullo</translation>
+ <translation id="6629135689895381486"><ph name="PROBLEM_REPORT"/> peut <ph name="START_LINK"/>utilisation excessive de majuscules<ph name="END_LINK"/>.</translation>
+ <translation id="7729135689895381486">Hello
+this is another line
+and another
+
+and another after a blank line.</translation>
+ </translationbundle>''')
+
+ messages = []
+ def Callback(id, structure):
+ messages.append((id, structure))
+ xtb_reader.Parse(xtb_file, Callback)
+ self.failUnless(len(messages[0][1]) == 1)
+ self.failUnless(messages[3][1][0]) # PROBLEM_REPORT placeholder
+ self.failUnless(messages[4][0] == '7729135689895381486')
+ self.failUnless(messages[4][1][7][1] == 'and another after a blank line.')
+
+ def testParsingIntoMessages(self):
+ grd = grd_reader.Parse(StringIO.StringIO('''<?xml version="1.0" encoding="UTF-8"?>
+ <messages>
+ <message name="ID_MEGA">Fantastic!</message>
+ <message name="ID_HELLO_USER">Hello <ph name="USERNAME">%s<ex>Joi</ex></ph></message>
+ </messages>'''), dir='.', flexible_root=True)
+
+ clique_mega = grd.children[0].GetCliques()[0]
+ msg_mega = clique_mega.GetMessage()
+ clique_hello_user = grd.children[1].GetCliques()[0]
+ msg_hello_user = clique_hello_user.GetMessage()
+
+ xtb_file = StringIO.StringIO('''<?xml version="1.0" encoding="UTF-8"?>
+ <!DOCTYPE translationbundle>
+ <translationbundle lang="is">
+ <translation id="%s">Meirihattar!</translation>
+ <translation id="%s">Saelir <ph name="USERNAME"/></translation>
+ </translationbundle>''' % (msg_mega.GetId(), msg_hello_user.GetId()))
+
+ xtb_reader.Parse(xtb_file, grd.UberClique().GenerateXtbParserCallback('is'))
+ self.failUnless(clique_mega.MessageForLanguage('is').GetRealContent() ==
+ 'Meirihattar!')
+ self.failUnless(clique_hello_user.MessageForLanguage('is').GetRealContent() ==
+ 'Saelir %s')
+
+ def testParseLargeFile(self):
+ def Callback(id, structure):
+ pass
+ xtb = file(util.PathFromRoot('grit/testdata/generated_resources_fr.xtb'))
+ xtb_reader.Parse(xtb, Callback)
+ xtb.close()
+
+
+if __name__ == '__main__':
+ unittest.main()
Property changes on: grit/xtb_reader_unittest.py
___________________________________________________________________
Added: svn:eol-style
+ LF
« no previous file with comments | « grit/xtb_reader.py ('k') | grit_info.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698