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

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

Issue 691873002: Add support to override output_all_resource_defines from command line. (Closed) Base URL: https://chromium.googlesource.com/external/grit-i18n.git@master
Patch Set: Created 6 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
« grit/tool/build.py ('K') | « grit/tool/build.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 the 'grit build' tool. 6 '''Unit tests for the 'grit build' tool.
7 ''' 7 '''
8 8
9 import codecs
9 import os 10 import os
10 import sys 11 import sys
11 import tempfile 12 import tempfile
12 if __name__ == '__main__': 13 if __name__ == '__main__':
13 sys.path.append(os.path.join(os.path.dirname(__file__), '../..')) 14 sys.path.append(os.path.join(os.path.dirname(__file__), '../..'))
14 15
15 import unittest 16 import unittest
16 17
17 from grit import util 18 from grit import util
18 from grit.tool import build 19 from grit.tool import build
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 self.failUnlessEqual(0, 79 self.failUnlessEqual(0,
79 builder_ok.Run(DummyOpts(), [ 80 builder_ok.Run(DummyOpts(), [
80 '-o', output_dir, 81 '-o', output_dir,
81 '-a', os.path.abspath( 82 '-a', os.path.abspath(
82 os.path.join(output_dir, 'en_generated_resources.rc')), 83 os.path.join(output_dir, 'en_generated_resources.rc')),
83 '-a', os.path.abspath( 84 '-a', os.path.abspath(
84 os.path.join(output_dir, 'sv_generated_resources.rc')), 85 os.path.join(output_dir, 'sv_generated_resources.rc')),
85 '-a', os.path.abspath( 86 '-a', os.path.abspath(
86 os.path.join(output_dir, 'resource.h'))])) 87 os.path.join(output_dir, 'resource.h'))]))
87 88
89 def _verifyWhitelistedOutput(self,
90 filename,
91 whitelisted_ids,
92 non_whitelisted_ids,
93 encoding='utf8'):
94 self.failUnless(os.path.exists(filename))
95 whitelisted_ids_found = []
96 non_whitelisted_ids_found = []
97 with codecs.open(filename, encoding=encoding) as f:
98 for line in f.readlines():
99 for whitelisted_id in whitelisted_ids:
100 if whitelisted_id in line:
101 whitelisted_ids_found.append(whitelisted_id)
102 for non_whitelisted_id in non_whitelisted_ids:
103 if non_whitelisted_id in line:
104 non_whitelisted_ids_found.append(non_whitelisted_id)
105 self.longMessage = True
106 self.assertEqual(whitelisted_ids,
107 whitelisted_ids_found,
108 '\nin file {}'.format(os.path.basename(filename)))
109 non_whitelisted_msg = ('Non-Whitelisted IDs {} found in {}'
110 .format(non_whitelisted_ids_found, os.path.basename(filename)))
111 self.assertFalse(non_whitelisted_ids_found, non_whitelisted_msg)
112
113 def testOutputAllResourceDefinesTrue(self):
114 output_dir = tempfile.mkdtemp()
115 builder = build.RcBuilder()
116 class DummyOpts(object):
117 def __init__(self):
118 self.input = util.PathFromRoot('grit/testdata/whitelist_resources.grd')
newt (away) 2014/10/30 20:16:21 whitelist_resources.grd and whitelist.txt don't se
lliabraa 2014/10/31 11:33:13 Done.
119 self.verbose = False
120 self.extra_verbose = False
121 whitelist_file = util.PathFromRoot('grit/testdata/whitelist.txt')
122 builder.Run(DummyOpts(), ['-o', output_dir,
123 '-w', whitelist_file,
124 '--output-all-resource-defines',])
125 header = os.path.join(output_dir, 'whitelist_test_resources.h')
126 map_cc = os.path.join(output_dir, 'whitelist_test_resources_map.cc')
127
128 whitelisted_ids = [
129 'IDR_STRUCTURE_WHITELISTED',
130 'IDR_STRUCTURE_NOT_WHITELISTED',
131 'IDR_STRUCTURE_IN_TRUE_IF_WHITELISTED',
132 'IDR_STRUCTURE_IN_TRUE_IF_NOT_WHITELISTED',
133 'IDR_STRUCTURE_IN_FALSE_IF_WHITELISTED',
134 'IDR_STRUCTURE_IN_FALSE_IF_NOT_WHITELISTED',
135 'IDR_INCLUDE_WHITELISTED',
136 'IDR_INCLUDE_NOT_WHITELISTED',
137 ]
138 non_whitelisted_ids = []
newt (away) 2014/10/30 20:16:20 wouldn't it be more useful if this list were non-e
lliabraa 2014/10/31 11:33:13 This test case covers output_all_resource_defines=
139 for output_file in (header, map_cc):
140 self._verifyWhitelistedOutput(
141 output_file,
142 whitelisted_ids,
143 non_whitelisted_ids,
144 )
145
146
88 if __name__ == '__main__': 147 if __name__ == '__main__':
89 unittest.main() 148 unittest.main()
OLDNEW
« grit/tool/build.py ('K') | « grit/tool/build.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698