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

Side by Side Diff: grit/format/html_inline_unittest.py

Issue 16539002: GRIT: Enable variable expansion in filenames during HTML inlining. (Closed) Base URL: https://chromium.googlesource.com/external/grit-i18n.git@master
Patch Set: Created 7 years, 6 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
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.format.html_inline''' 6 '''Unit tests for grit.format.html_inline'''
7 7
8 8
9 import os 9 import os
10 import re 10 import re
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 for filename in files: 195 for filename in files:
196 source_resources.add(tmp_dir.GetPath(filename)) 196 source_resources.add(tmp_dir.GetPath(filename))
197 197
198 result = html_inline.DoInline(tmp_dir.GetPath('index.html'), None) 198 result = html_inline.DoInline(tmp_dir.GetPath('index.html'), None)
199 resources = result.inlined_files 199 resources = result.inlined_files
200 resources.add(tmp_dir.GetPath('index.html')) 200 resources.add(tmp_dir.GetPath('index.html'))
201 self.failUnlessEqual(resources, source_resources) 201 self.failUnlessEqual(resources, source_resources)
202 self.failUnlessEqual(expected_inlined, 202 self.failUnlessEqual(expected_inlined,
203 util.FixLineEnd(result.inlined_data, '\n')) 203 util.FixLineEnd(result.inlined_data, '\n'))
204 204
205 def testFilenameVariableExpansion(self):
206 '''Tests that variables are expanded in filenames before inlining.'''
207
208 files = {
209 'index.html': '''
210 <html>
211 <head>
212 <link rel="stylesheet" href="style[WHICH].css">
213 </head>
214 <include src="tmpl[WHICH].html">
215 </html>
216 ''',
217 'style1.css': '''h1 {}''',
218 'tmpl1.html': '''<h1></h1>''',
219 }
220
221 expected_inlined = '''
222 <html>
223 <head>
224 <style>h1 {}</style>
225 </head>
226 <h1></h1>
227 </html>
228 '''
229
230 source_resources = set()
231 tmp_dir = util.TempDir(files)
232 for filename in files:
233 source_resources.add(tmp_dir.GetPath(filename))
234
235 def replacer(var, repl):
236 return lambda filename: filename.replace('[%s]' % var, repl)
237
238 result = html_inline.DoInline(
239 tmp_dir.GetPath('index.html'),
240 None,
241 filename_expansion_function=replacer('WHICH', '1'))
242 resources = result.inlined_files
243 resources.add(tmp_dir.GetPath('index.html'))
244 self.failUnlessEqual(resources, source_resources)
flackr 2013/06/06 14:07:19 It might be worth adding a test which calls DoInli
dconnelly 2013/06/07 09:10:38 Done.
245 self.failUnlessEqual(expected_inlined,
246 util.FixLineEnd(result.inlined_data, '\n'))
247
205 248
206 if __name__ == '__main__': 249 if __name__ == '__main__':
207 unittest.main() 250 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698