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

Side by Side Diff: grit/gather/admin_template_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/gather/admin_template.py ('k') | grit/gather/interface.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 the admin template gatherer.'''
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 StringIO
14 import tempfile
15 import unittest
16
17 from grit.gather import admin_template
18 from grit import util
19 from grit import grd_reader
20 from grit import grit_runner
21 from grit.tool import build
22
23
24 class AdmGathererUnittest(unittest.TestCase):
25 def testParsingAndTranslating(self):
26 pseudofile = StringIO.StringIO(
27 'bingo bongo\n'
28 'ding dong\n'
29 '[strings] \n'
30 'whatcha="bingo bongo"\n'
31 'gotcha = "bingolabongola "the wise" fingulafongula" \n')
32 gatherer = admin_template.AdmGatherer.FromFile(pseudofile)
33 gatherer.Parse()
34 self.failUnless(len(gatherer.GetCliques()) == 2)
35 self.failUnless(gatherer.GetCliques()[1].GetMessage().GetRealContent() ==
36 'bingolabongola "the wise" fingulafongula')
37
38 translation = gatherer.Translate('en')
39 self.failUnless(translation == gatherer.GetText().strip())
40
41 def testErrorHandling(self):
42 pseudofile = StringIO.StringIO(
43 'bingo bongo\n'
44 'ding dong\n'
45 'whatcha="bingo bongo"\n'
46 'gotcha = "bingolabongola "the wise" fingulafongula" \n')
47 gatherer = admin_template.AdmGatherer.FromFile(pseudofile)
48 self.assertRaises(admin_template.MalformedAdminTemplateException,
49 gatherer.Parse)
50
51 _TRANSLATABLES_FROM_FILE = (
52 'Google', 'Google Desktop', 'Preferences',
53 'Controls Google Desktop preferences',
54 'Indexing and Capture Control',
55 'Controls what files, web pages, and other content will be indexed by Google Desktop.',
56 'Prevent indexing of email',
57 # there are lots more but we don't check any further
58 )
59
60 def VerifyCliquesFromAdmFile(self, cliques):
61 self.failUnless(len(cliques) > 20)
62 for ix in range(len(self._TRANSLATABLES_FROM_FILE)):
63 text = cliques[ix].GetMessage().GetRealContent()
64 self.failUnless(text == self._TRANSLATABLES_FROM_FILE[ix])
65
66 def testFromFile(self):
67 fname = util.PathFromRoot('grit/testdata/GoogleDesktop.adm')
68 gatherer = admin_template.AdmGatherer.FromFile(fname)
69 gatherer.Parse()
70 cliques = gatherer.GetCliques()
71 self.VerifyCliquesFromAdmFile(cliques)
72
73 def MakeGrd(self):
74 grd = grd_reader.Parse(StringIO.StringIO('''<?xml version="1.0" encoding="UT F-8"?>
75 <grit latest_public_release="2" source_lang_id="en-US" current_release="3" >
76 <release seq="3">
77 <structures>
78 <structure type="admin_template" name="IDAT_GOOGLE_DESKTOP_SEARCH"
79 file="GoogleDesktop.adm" exclude_from_rc="true" />
80 <structure type="txt" name="BINGOBONGO"
81 file="README.txt" exclude_from_rc="true" />
82 </structures>
83 </release>
84 <outputs>
85 <output filename="de_res.rc" type="rc_all" lang="de" />
86 </outputs>
87 </grit>'''), util.PathFromRoot('grit/testdata'))
88 grd.RunGatherers(recursive=True)
89 return grd
90
91 def testInGrd(self):
92 grd = self.MakeGrd()
93 cliques = grd.children[0].children[0].children[0].GetCliques()
94 self.VerifyCliquesFromAdmFile(cliques)
95
96 def testFileIsOutput(self):
97 grd = self.MakeGrd()
98 dirname = tempfile.mkdtemp()
99 try:
100 tool = build.RcBuilder()
101 tool.o = grit_runner.Options()
102 tool.output_directory = dirname
103 tool.res = grd
104 tool.Process()
105
106 self.failUnless(os.path.isfile(
107 os.path.join(dirname, 'de_GoogleDesktop.adm')))
108 self.failUnless(os.path.isfile(
109 os.path.join(dirname, 'de_README.txt')))
110 finally:
111 for f in os.listdir(dirname):
112 os.unlink(os.path.join(dirname, f))
113 os.rmdir(dirname)
114
115 if __name__ == '__main__':
116 unittest.main()
OLDNEW
« no previous file with comments | « grit/gather/admin_template.py ('k') | grit/gather/interface.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698