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 """Unittest for chrome_messages_json.py. | 6 """Unittest for chrome_messages_json.py. |
7 """ | 7 """ |
8 | 8 |
9 import os | 9 import os |
10 import sys | 10 import sys |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 def testTranslations(self): | 101 def testTranslations(self): |
102 root = util.ParseGrdForUnittest(""" | 102 root = util.ParseGrdForUnittest(""" |
103 <messages> | 103 <messages> |
104 <message name="ID_HELLO">Hello!</message> | 104 <message name="ID_HELLO">Hello!</message> |
105 <message name="ID_HELLO_USER">Hello <ph name="USERNAME">%s<ex> | 105 <message name="ID_HELLO_USER">Hello <ph name="USERNAME">%s<ex> |
106 Joi</ex></ph></message> | 106 Joi</ex></ph></message> |
107 </messages> | 107 </messages> |
108 """) | 108 """) |
109 | 109 |
110 buf = StringIO.StringIO() | 110 buf = StringIO.StringIO() |
111 build.RcBuilder.ProcessNode(root, DummyOutput('chrome_messages_json', 'fr'),
buf) | 111 build.RcBuilder.ProcessNode(root, DummyOutput('chrome_messages_json', 'fr'), |
| 112 buf) |
112 output = buf.getvalue() | 113 output = buf.getvalue() |
113 test = u""" | 114 test = u""" |
114 { | 115 { |
115 "ID_HELLO": { | 116 "ID_HELLO": { |
116 "message": "H\\u00e9P\\u00e9ll\\u00f4P\\u00f4!" | 117 "message": "H\\u00e9P\\u00e9ll\\u00f4P\\u00f4!" |
117 }, | 118 }, |
118 "ID_HELLO_USER": { | 119 "ID_HELLO_USER": { |
119 "message": "H\\u00e9P\\u00e9ll\\u00f4P\\u00f4 %s" | 120 "message": "H\\u00e9P\\u00e9ll\\u00f4P\\u00f4 %s" |
120 } | 121 } |
121 } | 122 } |
122 """ | 123 """ |
123 self.assertEqual(test.strip(), output.strip()) | 124 self.assertEqual(test.strip(), output.strip()) |
| 125 |
| 126 def testSkipMissingTranslations(self): |
| 127 grd = """<?xml version="1.0" encoding="UTF-8"?> |
| 128 <grit latest_public_release="2" current_release="3" source_lang_id="en" |
| 129 base_dir="%s"> |
| 130 <outputs> |
| 131 </outputs> |
| 132 <release seq="3" allow_pseudo="False"> |
| 133 <messages fallback_to_english="true"> |
| 134 <message name="ID_HELLO_NO_TRANSLATION">Hello not translated</message> |
| 135 </messages> |
| 136 </release> |
| 137 </grit>""" |
| 138 root = grd_reader.Parse(StringIO.StringIO(grd), dir=".") |
| 139 |
| 140 buf = StringIO.StringIO() |
| 141 build.RcBuilder.ProcessNode(root, DummyOutput('chrome_messages_json', 'fr'), |
| 142 buf) |
| 143 output = buf.getvalue() |
| 144 test = u""" |
| 145 { |
| 146 |
| 147 } |
| 148 """ |
| 149 self.assertEqual(test.strip(), output.strip()) |
124 | 150 |
125 | 151 |
126 class DummyOutput(object): | 152 class DummyOutput(object): |
127 | 153 |
128 def __init__(self, type, language): | 154 def __init__(self, type, language): |
129 self.type = type | 155 self.type = type |
130 self.language = language | 156 self.language = language |
131 | 157 |
132 def GetType(self): | 158 def GetType(self): |
133 return self.type | 159 return self.type |
134 | 160 |
135 def GetLanguage(self): | 161 def GetLanguage(self): |
136 return self.language | 162 return self.language |
137 | 163 |
138 def GetOutputFilename(self): | 164 def GetOutputFilename(self): |
139 return 'hello.gif' | 165 return 'hello.gif' |
140 | 166 |
141 | 167 |
142 if __name__ == '__main__': | 168 if __name__ == '__main__': |
143 unittest.main() | 169 unittest.main() |
OLD | NEW |