OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/python2.4 |
| 2 # Copyright (c) 2006-2008 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 test that checks postprocessing of files. |
| 7 Tests postprocessing by having the postprocessor |
| 8 modify the grd data tree, changing the message name attributes. |
| 9 ''' |
| 10 |
| 11 import os |
| 12 import re |
| 13 import sys |
| 14 if __name__ == '__main__': |
| 15 sys.path.append(os.path.join(os.path.dirname(sys.argv[0]), '..')) |
| 16 |
| 17 import unittest |
| 18 |
| 19 import grit.tool.postprocess_interface |
| 20 from grit.tool import rc2grd |
| 21 |
| 22 |
| 23 class PostProcessingUnittest(unittest.TestCase): |
| 24 |
| 25 def testPostProcessing(self): |
| 26 rctext = '''STRINGTABLE |
| 27 BEGIN |
| 28 DUMMY_STRING_1 "String 1" |
| 29 // Some random description |
| 30 DUMMY_STRING_2 "This text was added during preprocessing" |
| 31 END |
| 32 ''' |
| 33 tool = rc2grd.Rc2Grd() |
| 34 class DummyOpts(object): |
| 35 verbose = False |
| 36 extra_verbose = False |
| 37 tool.o = DummyOpts() |
| 38 tool.post_process = 'grit.tool.postprocess_unittest.DummyPostProcessor' |
| 39 result = tool.Process(rctext, '.\resource.rc') |
| 40 |
| 41 self.failUnless( |
| 42 result.children[2].children[2].children[0].attrs['name'] == 'SMART_STRING_
1') |
| 43 self.failUnless( |
| 44 result.children[2].children[2].children[1].attrs['name'] == 'SMART_STRING_
2') |
| 45 |
| 46 class DummyPostProcessor(grit.tool.postprocess_interface.PostProcessor): |
| 47 ''' |
| 48 Post processing replaces all message name attributes containing "DUMMY" to |
| 49 "SMART". |
| 50 ''' |
| 51 def Process(self, rctext, rcpath, grdnode): |
| 52 smarter = re.compile(r'(DUMMY)(.*)') |
| 53 messages = grdnode.children[2].children[2] |
| 54 for node in messages.children: |
| 55 name_attr = node.attrs['name'] |
| 56 m = smarter.search(name_attr) |
| 57 if m: |
| 58 node.attrs['name'] = 'SMART' + m.group(2) |
| 59 return grdnode |
| 60 |
| 61 if __name__ == '__main__': |
| 62 unittest.main() |
| 63 |
OLD | NEW |