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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « grit/xtb_reader.py ('k') | grit_info.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 #!/usr/bin/python2.4
2 # Copyright (c) 2011 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.xtb_reader'''
7
8
9 import os
10 import sys
11 if __name__ == '__main__':
12 sys.path.append(os.path.join(os.path.dirname(sys.argv[0]), '..'))
13
14 import StringIO
15 import unittest
16
17 from grit import xtb_reader
18 from grit import clique
19 from grit import grd_reader
20 from grit import tclib
21 from grit import util
22
23
24 class XtbReaderUnittest(unittest.TestCase):
25 def testParsing(self):
26 xtb_file = StringIO.StringIO('''<?xml version="1.0" encoding="UTF-8"?>
27 <!DOCTYPE translationbundle>
28 <translationbundle lang="fr">
29 <translation id="5282608565720904145">Bingo.</translation>
30 <translation id="2955977306445326147">Bongo longo.</translation>
31 <translation id="238824332917605038">Hullo</translation>
32 <translation id="6629135689895381486"><ph name="PROBLEM_REPORT"/> peut < ph name="START_LINK"/>utilisation excessive de majuscules<ph name="END_LINK"/>.< /translation>
33 <translation id="7729135689895381486">Hello
34 this is another line
35 and another
36
37 and another after a blank line.</translation>
38 </translationbundle>''')
39
40 messages = []
41 def Callback(id, structure):
42 messages.append((id, structure))
43 xtb_reader.Parse(xtb_file, Callback)
44 self.failUnless(len(messages[0][1]) == 1)
45 self.failUnless(messages[3][1][0]) # PROBLEM_REPORT placeholder
46 self.failUnless(messages[4][0] == '7729135689895381486')
47 self.failUnless(messages[4][1][7][1] == 'and another after a blank line.')
48
49 def testParsingIntoMessages(self):
50 grd = grd_reader.Parse(StringIO.StringIO('''<?xml version="1.0" encoding="UT F-8"?>
51 <messages>
52 <message name="ID_MEGA">Fantastic!</message>
53 <message name="ID_HELLO_USER">Hello <ph name="USERNAME">%s<ex>Joi</ex></ ph></message>
54 </messages>'''), dir='.', flexible_root=True)
55
56 clique_mega = grd.children[0].GetCliques()[0]
57 msg_mega = clique_mega.GetMessage()
58 clique_hello_user = grd.children[1].GetCliques()[0]
59 msg_hello_user = clique_hello_user.GetMessage()
60
61 xtb_file = StringIO.StringIO('''<?xml version="1.0" encoding="UTF-8"?>
62 <!DOCTYPE translationbundle>
63 <translationbundle lang="is">
64 <translation id="%s">Meirihattar!</translation>
65 <translation id="%s">Saelir <ph name="USERNAME"/></translation>
66 </translationbundle>''' % (msg_mega.GetId(), msg_hello_user.GetId()))
67
68 xtb_reader.Parse(xtb_file, grd.UberClique().GenerateXtbParserCallback('is'))
69 self.failUnless(clique_mega.MessageForLanguage('is').GetRealContent() ==
70 'Meirihattar!')
71 self.failUnless(clique_hello_user.MessageForLanguage('is').GetRealContent() ==
72 'Saelir %s')
73
74 def testParseLargeFile(self):
75 def Callback(id, structure):
76 pass
77 xtb = file(util.PathFromRoot('grit/testdata/generated_resources_fr.xtb'))
78 xtb_reader.Parse(xtb, Callback)
79 xtb.close()
80
81
82 if __name__ == '__main__':
83 unittest.main()
OLDNEW
« 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