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

Side by Side Diff: tools/grit/grit/tool/xmb_unittest.py

Issue 2697383002: Fix xmb_unittest.py in GRIT. (Closed)
Patch Set: Correct sequence for \U00110000. Created 3 years, 10 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
« no previous file with comments | « tools/grit/grit/tool/xmb.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 '''Unit tests for 'grit xmb' tool.''' 6 '''Unit tests for 'grit xmb' tool.'''
7 7
8 import os 8 import os
9 import sys 9 import sys
10 if __name__ == '__main__': 10 if __name__ == '__main__':
11 sys.path.append(os.path.join(os.path.dirname(__file__), '../..')) 11 sys.path.append(os.path.join(os.path.dirname(__file__), '../..'))
12 12
13 import unittest 13 import unittest
14 import StringIO 14 import StringIO
15 import xml.sax
15 16
16 from grit import grd_reader 17 from grit import grd_reader
17 from grit import util 18 from grit import util
18 from grit.tool import xmb 19 from grit.tool import xmb
19 20
20 21
21 class XmbUnittest(unittest.TestCase): 22 class XmbUnittest(unittest.TestCase):
22 def setUp(self): 23 def setUp(self):
23 self.res_tree = grd_reader.Parse( 24 self.res_tree = grd_reader.Parse(
24 StringIO.StringIO(u'''<?xml version="1.0" encoding="UTF-8"?> 25 StringIO.StringIO(u'''<?xml version="1.0" encoding="UTF-8"?>
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 # Regression test for problems outputting messages with leading or 97 # Regression test for problems outputting messages with leading or
97 # trailing whitespace (these come in via structures only, as 98 # trailing whitespace (these come in via structures only, as
98 # message nodes already strip and store whitespace). 99 # message nodes already strip and store whitespace).
99 self.res_tree.SetOutputLanguage('en') 100 self.res_tree.SetOutputLanguage('en')
100 os.chdir(util.PathFromRoot('.')) # so it can find klonk.rc 101 os.chdir(util.PathFromRoot('.')) # so it can find klonk.rc
101 self.res_tree.RunGatherers() 102 self.res_tree.RunGatherers()
102 xmb.OutputXmb().Process(self.res_tree, self.xmb_file) 103 xmb.OutputXmb().Process(self.res_tree, self.xmb_file)
103 output = self.xmb_file.getvalue() 104 output = self.xmb_file.getvalue()
104 self.failUnless(output.count('OK ? </msg>')) 105 self.failUnless(output.count('OK ? </msg>'))
105 106
107 def testDisallowedChars(self):
108 # Validate that the invalid unicode is not accepted. Since it's not valid,
109 # we can't specify it in a string literal, so write as a byte sequence.
110 bad_xml = StringIO.StringIO()
111 bad_xml.write('''<?xml version="1.0" encoding="UTF-8"?>
112 <grit latest_public_release="2" source_lang_id="en-US"
113 current_release="3" base_dir=".">
114 <release seq="3">
115 <messages>
116 <message name="ID_FOO">''')
117 # UTF-8 corresponding to to \U00110000
118 # http://apps.timwhitlock.info/unicode/inspect/hex/110000
119 bad_xml.write(b'\xF4\x90\x80\x80')
120 bad_xml.write('''</message>
121 </messages>
122 </release>
123 </grit>''')
124 bad_xml.seek(0)
125 self.assertRaises(xml.sax.SAXParseException, grd_reader.Parse, bad_xml, '.')
106 126
107 if __name__ == '__main__': 127 if __name__ == '__main__':
108 unittest.main() 128 unittest.main()
OLDNEW
« no previous file with comments | « tools/grit/grit/tool/xmb.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698