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

Side by Side Diff: grit/tool/transl2tc_unittest.py

Issue 1438403002: Remove contents of grit's git-svn-mirror repository. (Closed) Base URL: https://chromium.googlesource.com/external/grit-i18n@master
Patch Set: Created 5 years, 1 month 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
« no previous file with comments | « grit/tool/transl2tc.py ('k') | grit/tool/unit.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
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
4 # found in the LICENSE file.
5
6 '''Unit tests for the 'grit transl2tc' tool.'''
7
8
9 import os
10 import sys
11 if __name__ == '__main__':
12 sys.path.append(os.path.join(os.path.dirname(__file__), '../..'))
13
14 import StringIO
15 import unittest
16
17 from grit.tool import transl2tc
18 from grit import grd_reader
19 from grit import util
20
21
22 def MakeOptions():
23 from grit import grit_runner
24 return grit_runner.Options()
25
26
27 class TranslationToTcUnittest(unittest.TestCase):
28
29 def testOutput(self):
30 buf = StringIO.StringIO()
31 tool = transl2tc.TranslationToTc()
32 translations = [
33 ['1', 'Hello USERNAME, how are you?'],
34 ['12', 'Howdie doodie!'],
35 ['123', 'Hello\n\nthere\n\nhow are you?'],
36 ['1234', 'Hello is > goodbye but < howdie pardner'],
37 ]
38 tool.WriteTranslations(buf, translations)
39 output = buf.getvalue()
40 self.failUnless(output.strip() == '''
41 1 Hello USERNAME, how are you?
42 12 Howdie doodie!
43 123 Hello
44
45 there
46
47 how are you?
48 1234 Hello is &gt; goodbye but &lt; howdie pardner
49 '''.strip())
50
51 def testExtractTranslations(self):
52 path = util.PathFromRoot('grit/testdata')
53 current_grd = grd_reader.Parse(StringIO.StringIO('''<?xml version="1.0" enco ding="UTF-8"?>
54 <grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_dir=".">
55 <release seq="3">
56 <messages>
57 <message name="IDS_SIMPLE">
58 One
59 </message>
60 <message name="IDS_PLACEHOLDER">
61 <ph name="NUMBIRDS">%s<ex>3</ex></ph> birds
62 </message>
63 <message name="IDS_PLACEHOLDERS">
64 <ph name="ITEM">%d<ex>1</ex></ph> of <ph name="COUNT">%d<ex>3</ex> </ph>
65 </message>
66 <message name="IDS_REORDERED_PLACEHOLDERS">
67 <ph name="ITEM">$1<ex>1</ex></ph> of <ph name="COUNT">$2<ex>3</ex> </ph>
68 </message>
69 <message name="IDS_CHANGED">
70 This is the new version
71 </message>
72 <message name="IDS_TWIN_1">Hello</message>
73 <message name="IDS_TWIN_2">Hello</message>
74 <message name="IDS_NOT_TRANSLATEABLE" translateable="false">:</messa ge>
75 <message name="IDS_LONGER_TRANSLATED">
76 Removed document <ph name="FILENAME">$1<ex>c:\temp</ex></ph>
77 </message>
78 <message name="IDS_DIFFERENT_TWIN_1">Howdie</message>
79 <message name="IDS_DIFFERENT_TWIN_2">Howdie</message>
80 </messages>
81 <structures>
82 <structure type="dialog" name="IDD_ABOUTBOX" encoding="utf-16" file= "klonk.rc" />
83 <structure type="menu" name="IDC_KLONKMENU" encoding="utf-16" file=" klonk.rc" />
84 </structures>
85 </release>
86 </grit>'''), path)
87 current_grd.SetOutputLanguage('en')
88 current_grd.RunGatherers()
89
90 source_rc_path = util.PathFromRoot('grit/testdata/source.rc')
91 source_rc = util.ReadFile(source_rc_path, util.RAW_TEXT)
92 transl_rc_path = util.PathFromRoot('grit/testdata/transl.rc')
93 transl_rc = util.ReadFile(transl_rc_path, util.RAW_TEXT)
94
95 tool = transl2tc.TranslationToTc()
96 output_buf = StringIO.StringIO()
97 globopts = MakeOptions()
98 globopts.verbose = True
99 globopts.output_stream = output_buf
100 tool.Setup(globopts, [])
101 translations = tool.ExtractTranslations(current_grd,
102 source_rc, source_rc_path,
103 transl_rc, transl_rc_path)
104
105 values = translations.values()
106 output = output_buf.getvalue()
107
108 self.failUnless('Ein' in values)
109 self.failUnless('NUMBIRDS Vogeln' in values)
110 self.failUnless('ITEM von COUNT' in values)
111 self.failUnless(values.count('Hallo') == 1)
112 self.failIf('Dass war die alte Version' in values)
113 self.failIf(':' in values)
114 self.failIf('Dokument FILENAME ist entfernt worden' in values)
115 self.failIf('Nicht verwendet' in values)
116 self.failUnless(('Howdie' in values or 'Hallo sagt man' in values) and not
117 ('Howdie' in values and 'Hallo sagt man' in values))
118
119 self.failUnless('XX01XX&SkraXX02XX&HaettaXX03XXThetta er "Klonk" sem eg fyla XX04XXgonkurinnXX05XXKlonk && er [good]XX06XX&HjalpXX07XX&Um...XX08XX' in values )
120
121 self.failUnless('I lagi' in values)
122
123 self.failUnless(output.count('Structure of message IDS_REORDERED_PLACEHOLDER S has changed'))
124 self.failUnless(output.count('Message IDS_CHANGED has changed'))
125 self.failUnless(output.count('Structure of message IDS_LONGER_TRANSLATED has changed'))
126 self.failUnless(output.count('Two different translations for "Howdie"'))
127 self.failUnless(output.count('IDD_DIFFERENT_LENGTH_IN_TRANSL has wrong # of cliques'))
128
129
130 if __name__ == '__main__':
131 unittest.main()
OLDNEW
« no previous file with comments | « grit/tool/transl2tc.py ('k') | grit/tool/unit.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698