OLD | NEW |
| (Empty) |
1 #!/usr/bin/env python | |
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 | |
4 # found in the LICENSE file. | |
5 | |
6 import unittest | |
7 import os.path | |
8 import PRESUBMIT | |
9 | |
10 | |
11 class FakeInputApi(object): | |
12 os_path = os.path | |
13 def __init__(self, affected_files=[]): | |
14 self.affected_files = affected_files | |
15 def AffectedFiles(self): | |
16 return self.affected_files | |
17 def LocalPaths(self): | |
18 return [af.LocalPath() for af in self.AffectedFiles()] | |
19 | |
20 | |
21 class FakeAffectedFile(object): | |
22 def __init__(self, local_path='', changed_contents=None): | |
23 self._local_path = os.path.normpath(local_path) | |
24 self._changed_contents = changed_contents | |
25 def LocalPath(self): | |
26 return self._local_path | |
27 def ChangedContents(self): | |
28 return self._changed_contents | |
29 | |
30 | |
31 class FakeOutputApi(object): | |
32 def PresubmitPromptWarning(self, warning_msg): | |
33 return warning_msg | |
34 | |
35 | |
36 class TestPresubmit(unittest.TestCase): | |
37 def setUp(self): | |
38 self.input_api = FakeInputApi() | |
39 self.output_api = FakeOutputApi() | |
40 | |
41 def assertPathsEqual(self, path1, path2): | |
42 self.assertEqual(os.path.normpath(path1), os.path.normpath(path2)) | |
43 | |
44 def testCheckDocsChanges_NoFiles(self): | |
45 input_api = FakeInputApi(affected_files=[]) | |
46 self.assertEqual([], PRESUBMIT.CheckDocChanges(input_api, self.output_api)) | |
47 | |
48 def testCheckDocsChanges_OnlyExcpetions(self): | |
49 input_api = FakeInputApi(affected_files=[ | |
50 FakeAffectedFile(local_path='chrome/common/extensions/docs/README'), | |
51 FakeAffectedFile(local_path='chrome/common/extensions/docs/OWNERS')]) | |
52 self.assertEqual([], PRESUBMIT.CheckDocChanges(input_api, self.output_api)) | |
53 | |
54 def testCheckDocsChanges_NoGeneratedFiles(self): | |
55 input_api = FakeInputApi(affected_files=[ | |
56 FakeAffectedFile( | |
57 local_path='chrome/common/extensions/api/foo.json'), | |
58 FakeAffectedFile( | |
59 local_path='chrome/common/extensions/docs/examples/foo/b/bz.js'), | |
60 FakeAffectedFile( | |
61 local_path='chrome/common/extensions/docs/static/foo.html')]) | |
62 expected_warning = ( | |
63 'This change modifies the extension docs but the generated docs ' | |
64 'have not been updated properly. See %s for more info.\n' | |
65 ' - Changes to %s not reflected in generated doc.\n' | |
66 ' - Changes to sample %s have not been re-zipped.\n' | |
67 ' - Docs out of sync with %s changes.\n' | |
68 'First build DumpRenderTree, then update the docs by running:\n %s' | |
69 ' --page-name=<apiName>' % | |
70 (os.path.normpath('chrome/common/extensions/docs/README.txt'), | |
71 os.path.normpath('chrome/common/extensions/docs/static/foo.html'), | |
72 os.path.normpath('chrome/common/extensions/docs/examples/foo/b/bz.js'), | |
73 os.path.normpath('chrome/common/extensions/api/foo.json'), | |
74 os.path.normpath('chrome/common/extensions/docs/build/build.py'))) | |
75 self.assertEqual([expected_warning], | |
76 PRESUBMIT.CheckDocChanges(input_api, self.output_api)) | |
77 | |
78 def testCheckDocsChanges_OnlyGeneratedDocs(self): | |
79 input_api = FakeInputApi(affected_files=[ | |
80 FakeAffectedFile( | |
81 local_path='chrome/common/extensions/docs/apps/foo.html'), | |
82 FakeAffectedFile( | |
83 local_path='chrome/common/extensions/docs/extensions/foo.html'), | |
84 FakeAffectedFile( | |
85 local_path='chrome/common/extensions/docs/apps/bar.html'), | |
86 FakeAffectedFile( | |
87 local_path='chrome/common/extensions/docs/extensions/baz.html')]) | |
88 expected_warning = ( | |
89 'This change modifies the extension docs but the generated docs ' | |
90 'have not been updated properly. See %s for more info.\n' | |
91 ' - Changes to generated doc %s not reflected in non-generated files.\n' | |
92 ' - Changes to generated doc %s not reflected in non-generated files.\n' | |
93 ' - Changes to generated doc %s not reflected in non-generated files.\n' | |
94 ' - Changes to generated doc %s not reflected in non-generated files.\n' | |
95 'First build DumpRenderTree, then update the docs by running:\n %s' | |
96 ' --page-name=<apiName>' % | |
97 (os.path.normpath('chrome/common/extensions/docs/README.txt'), | |
98 os.path.normpath('chrome/common/extensions/docs/apps/bar.html'), | |
99 os.path.normpath('chrome/common/extensions/docs/apps/foo.html'), | |
100 os.path.normpath('chrome/common/extensions/docs/extensions/baz.html'), | |
101 os.path.normpath('chrome/common/extensions/docs/extensions/foo.html'), | |
102 os.path.normpath('chrome/common/extensions/docs/build/build.py'))) | |
103 self.assertEqual([expected_warning], | |
104 PRESUBMIT.CheckDocChanges(input_api, self.output_api)) | |
105 | |
106 def testIsSkippedFile(self): | |
107 self.assertTrue(PRESUBMIT.IsSkippedFile( | |
108 os.path.normpath('chrome/common/extensions/docs/README.txt'), | |
109 self.input_api)) | |
110 self.assertTrue(PRESUBMIT.IsSkippedFile( | |
111 os.path.normpath('chrome/common/extensions/OWNERS'), self.input_api)) | |
112 self.assertTrue(PRESUBMIT.IsSkippedFile( | |
113 os.path.normpath('chrome/common/extensions/api/README'), | |
114 self.input_api)) | |
115 self.assertTrue(PRESUBMIT.IsSkippedFile( | |
116 os.path.normpath('foo/bar/README.txt'), self.input_api)) | |
117 self.assertFalse(PRESUBMIT.IsSkippedFile( | |
118 os.path.normpath('chrome/common/extensions/README/foo'), | |
119 self.input_api)) | |
120 | |
121 def testIsApiFile(self): | |
122 self.assertFalse(PRESUBMIT.IsApiFile( | |
123 os.path.normpath('chrome/common/extensions/docs/foo.html'), | |
124 self.input_api)) | |
125 self.assertTrue(PRESUBMIT.IsApiFile( | |
126 os.path.normpath('chrome/common/extensions/api/foo.json'), | |
127 self.input_api)) | |
128 self.assertFalse(PRESUBMIT.IsApiFile( | |
129 os.path.normpath('chrome/common/extensions/api/foo.html'), | |
130 self.input_api)) | |
131 self.assertFalse(PRESUBMIT.IsApiFile( | |
132 os.path.normpath('chrome/common/extensions/docs/api/foo.html'), | |
133 self.input_api)) | |
134 | |
135 def testIsBuildFile(self): | |
136 self.assertTrue(PRESUBMIT.IsBuildFile( | |
137 os.path.normpath('chrome/common/extensions/docs/build/foo.py'), | |
138 self.input_api)) | |
139 self.assertTrue(PRESUBMIT.IsBuildFile( | |
140 os.path.normpath('chrome/common/extensions/docs/build/bar.html'), | |
141 self.input_api)) | |
142 self.assertFalse(PRESUBMIT.IsBuildFile( | |
143 os.path.normpath('chrome/common/extensions/docs/build.py'), | |
144 self.input_api)) | |
145 self.assertFalse(PRESUBMIT.IsBuildFile( | |
146 os.path.normpath('chrome/common/extensions/build/foo.py'), | |
147 self.input_api)) | |
148 | |
149 def testIsTemplateFile(self): | |
150 self.assertTrue(PRESUBMIT.IsTemplateFile( | |
151 os.path.normpath('chrome/common/extensions/docs/template/foo.html'), | |
152 self.input_api)) | |
153 self.assertTrue(PRESUBMIT.IsTemplateFile( | |
154 os.path.normpath('chrome/common/extensions/docs/template/bar.js'), | |
155 self.input_api)) | |
156 self.assertFalse(PRESUBMIT.IsTemplateFile( | |
157 os.path.normpath('chrome/common/extensions/docs/template.html'), | |
158 self.input_api)) | |
159 self.assertFalse(PRESUBMIT.IsTemplateFile( | |
160 os.path.normpath('chrome/common/extensions/template/foo.html'), | |
161 self.input_api)) | |
162 | |
163 def testIsStaticDoc(self): | |
164 self.assertFalse(PRESUBMIT.IsStaticDoc( | |
165 os.path.normpath('chrome/common/extensions/docs/foo.html'), | |
166 self.input_api)) | |
167 self.assertTrue(PRESUBMIT.IsStaticDoc( | |
168 os.path.normpath('chrome/common/extensions/docs/static/foo.html'), | |
169 self.input_api)) | |
170 self.assertFalse(PRESUBMIT.IsStaticDoc( | |
171 os.path.normpath('chrome/common/extensions/docs/api/foo.html'), | |
172 self.input_api)) | |
173 self.assertFalse(PRESUBMIT.IsStaticDoc( | |
174 os.path.normpath('chrome/common/extensions/docs/static/foo.css'), | |
175 self.input_api)) | |
176 | |
177 def testIsSampleFile(self): | |
178 self.assertTrue(PRESUBMIT.IsSampleFile( | |
179 os.path.normpath( | |
180 'chrome/common/extensions/docs/examples/ex1/manifest.json'), | |
181 self.input_api)) | |
182 self.assertTrue(PRESUBMIT.IsSampleFile( | |
183 os.path.normpath( | |
184 'chrome/common/extensions/docs/examples/ex1/images/icon.png'), | |
185 self.input_api)) | |
186 self.assertTrue(PRESUBMIT.IsSampleFile( | |
187 os.path.normpath('chrome/common/extensions/docs/examples/dir'), | |
188 self.input_api)) | |
189 self.assertTrue(PRESUBMIT.IsSampleFile( | |
190 os.path.normpath('chrome/common/extensions/docs/examples/dir/'), | |
191 self.input_api)) | |
192 self.assertFalse(PRESUBMIT.IsSampleFile( | |
193 os.path.normpath( | |
194 'chrome/common/extensions/docs/samples/ex1/manifest.json'), | |
195 self.input_api)) | |
196 | |
197 def testIsJsFile(self): | |
198 self.assertFalse(PRESUBMIT.IsJsFile( | |
199 os.path.normpath('chrome/common/extensions/docs/foo.js'), | |
200 self.input_api)) | |
201 self.assertTrue(PRESUBMIT.IsJsFile( | |
202 os.path.normpath('chrome/common/extensions/docs/js/foo.js'), | |
203 self.input_api)) | |
204 self.assertFalse(PRESUBMIT.IsJsFile( | |
205 os.path.normpath('chrome/common/extensions/docs/js/foo.html'), | |
206 self.input_api)) | |
207 | |
208 def testIsCssFile(self): | |
209 self.assertFalse(PRESUBMIT.IsCssFile( | |
210 os.path.normpath('chrome/common/extensions/docs/foo.css'), | |
211 self.input_api)) | |
212 self.assertTrue(PRESUBMIT.IsCssFile( | |
213 os.path.normpath('chrome/common/extensions/docs/css/foo.css'), | |
214 self.input_api)) | |
215 self.assertFalse(PRESUBMIT.IsCssFile( | |
216 os.path.normpath('chrome/common/extensions/docs/css/foo.html'), | |
217 self.input_api)) | |
218 | |
219 def testIsGeneratedDoc(self): | |
220 self.assertTrue(PRESUBMIT.IsGeneratedDoc( | |
221 os.path.normpath('chrome/common/extensions/docs/apps/foo.html'), | |
222 self.input_api)) | |
223 self.assertTrue(PRESUBMIT.IsGeneratedDoc( | |
224 os.path.normpath('chrome/common/extensions/docs/extensions/foo.html'), | |
225 self.input_api)) | |
226 self.assertFalse(PRESUBMIT.IsGeneratedDoc( | |
227 os.path.normpath('chrome/common/extensions/docs/static/foo.html'), | |
228 self.input_api)) | |
229 self.assertFalse(PRESUBMIT.IsGeneratedDoc( | |
230 os.path.normpath('chrome/common/extensions/docs/api/foo.html'), | |
231 self.input_api)) | |
232 self.assertFalse(PRESUBMIT.IsGeneratedDoc( | |
233 os.path.normpath('chrome/common/extensions/docs/foo.css'), | |
234 self.input_api)) | |
235 | |
236 def testDocsGenerated_SomeGeneratedDocs(self): | |
237 for path in ['apps', 'extensions']: | |
238 input_api = FakeInputApi(affected_files=[ | |
239 FakeAffectedFile( | |
240 local_path='chrome/common/extensions/docs/%s/foo.html' % path)]) | |
241 self.assertTrue(PRESUBMIT.DocsGenerated(input_api)) | |
242 | |
243 def testDocsGenerated_NoGeneratedDocs(self): | |
244 api_file = FakeAffectedFile( | |
245 local_path='chrome/common/extensions/api/foo.json') | |
246 input_api = FakeInputApi(affected_files=[api_file]) | |
247 self.assertFalse(PRESUBMIT.DocsGenerated(input_api)) | |
248 | |
249 def testNonGeneratedFilesEdited_SomeNonGeneratedFiles(self): | |
250 input_api = FakeInputApi(affected_files=[ | |
251 FakeAffectedFile(local_path='chrome/common/extensions/api/foo.json'), | |
252 FakeAffectedFile( | |
253 local_path='chrome/common/extensions/docs/static/index.html')]) | |
254 self.assertTrue(PRESUBMIT.NonGeneratedFilesEdited(input_api)) | |
255 | |
256 def testNonGeneratedFilesEdited_ZeroNonGeneratedFiles(self): | |
257 input_api = FakeInputApi(affected_files=[ | |
258 FakeAffectedFile(local_path='chrome/common/extensions/docs/one.html'), | |
259 FakeAffectedFile(local_path='chrome/common/extensions/docs/two.html')]) | |
260 self.assertFalse(PRESUBMIT.NonGeneratedFilesEdited(input_api)) | |
261 | |
262 def testStaticDocBuilt_ChangesMatchApps(self): | |
263 static_file = FakeAffectedFile( | |
264 local_path='chrome/common/extensions/docs/static/index.html', | |
265 changed_contents=[(3, 'foo!'), (4, 'bar!')]) | |
266 generated_apps_file = FakeAffectedFile( | |
267 local_path='chrome/common/extensions/docs/apps/index.html', | |
268 changed_contents=[(13, 'foo!'), (14, 'bar!')]) | |
269 input_api = FakeInputApi(affected_files=[ | |
270 generated_apps_file, | |
271 static_file]) | |
272 | |
273 self.assertTrue(PRESUBMIT.StaticDocBuilt(static_file, input_api)) | |
274 | |
275 def testStaticDocBuilt_ChangesMatchExtensions(self): | |
276 static_file = FakeAffectedFile( | |
277 local_path='chrome/common/extensions/docs/static/index.html', | |
278 changed_contents=[(3, 'foo!'), (4, 'bar!')]) | |
279 generated_extensions_file = FakeAffectedFile( | |
280 local_path='chrome/common/extensions/docs/extensions/index.html', | |
281 changed_contents=[(13, 'foo!'), (14, 'bar!')]) | |
282 input_api = FakeInputApi(affected_files=[ | |
283 generated_extensions_file, | |
284 static_file]) | |
285 | |
286 self.assertTrue(PRESUBMIT.StaticDocBuilt(static_file, input_api)) | |
287 | |
288 def testStaticDocBuilt_OnlyStaticChanged(self): | |
289 static_file = FakeAffectedFile( | |
290 local_path='chrome/common/extensions/docs/static/index.html', | |
291 changed_contents=[(3, 'foo!'), (4, 'bar!')]) | |
292 other_static_file = FakeAffectedFile( | |
293 local_path='chrome/common/extensions/docs/static/next.html', | |
294 changed_contents=[(3, 'double foo!'), (4, 'double bar!')]) | |
295 input_api = FakeInputApi(affected_files=[static_file, other_static_file]) | |
296 | |
297 self.assertFalse(PRESUBMIT.StaticDocBuilt(static_file, input_api)) | |
298 self.assertFalse(PRESUBMIT.StaticDocBuilt(other_static_file, input_api)) | |
299 | |
300 def testStaticDocBuilt_ChangesDoNotMatch(self): | |
301 static_file = FakeAffectedFile( | |
302 local_path='chrome/common/extensions/docs/static/index.html', | |
303 changed_contents=[(3, 'double foo!'), (4, 'double bar!')]) | |
304 generated_file = FakeAffectedFile( | |
305 local_path='chrome/common/extensions/docs/index.html', | |
306 changed_contents=[(13, 'foo!'), (14, 'bar!')]) | |
307 input_api = FakeInputApi(affected_files=[generated_file, static_file]) | |
308 | |
309 self.assertFalse(PRESUBMIT.StaticDocBuilt(static_file, input_api)) | |
310 | |
311 def testAlternateFilePath(self): | |
312 path = os.path.normpath('foo/bar/baz.html') | |
313 alt_dir = os.path.normpath('woop/dee/doo') | |
314 self.assertPathsEqual('woop/dee/doo/baz.html', | |
315 PRESUBMIT._AlternateFilePath(path, alt_dir, | |
316 self.input_api)) | |
317 alt_dir = 'foo' | |
318 self.assertPathsEqual('foo/baz.html', | |
319 PRESUBMIT._AlternateFilePath(path, alt_dir, | |
320 self.input_api)) | |
321 alt_dir = '' | |
322 self.assertPathsEqual('baz.html', | |
323 PRESUBMIT._AlternateFilePath(path, alt_dir, | |
324 self.input_api)) | |
325 | |
326 def testFindFileInAlternateDir(self): | |
327 input_api = FakeInputApi(affected_files=[ | |
328 FakeAffectedFile(local_path='dir/1.html'), | |
329 FakeAffectedFile(local_path='dir/2.html'), | |
330 FakeAffectedFile(local_path='dir/alt/1.html'), | |
331 FakeAffectedFile(local_path='dir/alt/3.html')]) | |
332 alt_dir = os.path.normpath('dir/alt') | |
333 | |
334 # Both files in affected files. | |
335 alt_file = PRESUBMIT._FindFileInAlternateDir( | |
336 FakeAffectedFile(local_path='dir/1.html'), alt_dir, input_api) | |
337 self.assertTrue(alt_file) | |
338 self.assertPathsEqual('dir/alt/1.html', alt_file.LocalPath()) | |
339 | |
340 # Given file not in affected files. | |
341 alt_file = PRESUBMIT._FindFileInAlternateDir( | |
342 FakeAffectedFile(local_path='dir/3.html'), alt_dir, input_api) | |
343 self.assertTrue(alt_file) | |
344 self.assertPathsEqual('dir/alt/3.html', alt_file.LocalPath()) | |
345 | |
346 # Alternate file not found. | |
347 alt_file = PRESUBMIT._FindFileInAlternateDir( | |
348 FakeAffectedFile(local_path='dir/2.html'), alt_dir, input_api) | |
349 self.assertFalse(alt_file) | |
350 | |
351 def testChangesMatch_Same(self): | |
352 af1 = FakeAffectedFile(changed_contents=[(1, 'foo'), (14, 'bar')]) | |
353 af2 = FakeAffectedFile(changed_contents=[(1, 'foo'), (14, 'bar')]) | |
354 self.assertTrue(PRESUBMIT._ChangesMatch(af1, af2)) | |
355 self.assertTrue(PRESUBMIT._ChangesMatch(af2, af1)) | |
356 | |
357 def testChangesMatch_OneFileNone(self): | |
358 af1 = FakeAffectedFile(changed_contents=[(1, 'foo'), (14, 'bar')]) | |
359 af2 = None | |
360 self.assertFalse(PRESUBMIT._ChangesMatch(af1, af2)) | |
361 self.assertFalse(PRESUBMIT._ChangesMatch(af2, af1)) | |
362 | |
363 def testChangesMatch_BothFilesNone(self): | |
364 af1 = None | |
365 af2 = None | |
366 self.assertTrue(PRESUBMIT._ChangesMatch(af1, af2)) | |
367 self.assertTrue(PRESUBMIT._ChangesMatch(af2, af1)) | |
368 | |
369 def testChangesMatch_DifferentLineNumbers(self): | |
370 af1 = FakeAffectedFile(changed_contents=[(1, 'foo'), (14, 'bar')]) | |
371 af2 = FakeAffectedFile(changed_contents=[(1, 'foo'), (15, 'bar')]) | |
372 self.assertTrue(PRESUBMIT._ChangesMatch(af1, af2)) | |
373 self.assertTrue(PRESUBMIT._ChangesMatch(af2, af1)) | |
374 | |
375 def testChangesMatch_DifferentOrder(self): | |
376 af = FakeAffectedFile(changed_contents=[(1, 'foo'), (2, 'bar')]) | |
377 af2 = FakeAffectedFile(changed_contents=[(1, 'bar'), (2, 'foo')]) | |
378 self.assertFalse(PRESUBMIT._ChangesMatch(af, af2)) | |
379 self.assertFalse(PRESUBMIT._ChangesMatch(af2, af)) | |
380 | |
381 def testChangesMatch_DifferentLength(self): | |
382 af = FakeAffectedFile(changed_contents=[(14, 'bar'), (15, 'qxxy')]) | |
383 af_extra = FakeAffectedFile(changed_contents=[(1, 'foo'), (14, 'bar'), | |
384 (23, 'baz'), (25, 'qxxy')]) | |
385 # The generated file (first arg) may have extra lines. | |
386 self.assertTrue(PRESUBMIT._ChangesMatch(af_extra, af)) | |
387 # But not the static file (second arg). | |
388 self.assertFalse(PRESUBMIT._ChangesMatch(af, af_extra)) | |
389 | |
390 def testChangesMatch_SameLengthButDifferentText(self): | |
391 af1 = FakeAffectedFile(changed_contents=[(1, 'foo'), (14, 'bar')]) | |
392 af2 = FakeAffectedFile(changed_contents=[(1, 'foo'), (14, 'baz')]) | |
393 self.assertFalse(PRESUBMIT._ChangesMatch(af1, af2)) | |
394 self.assertFalse(PRESUBMIT._ChangesMatch(af2, af1)) | |
395 | |
396 def testChangesMatch_LineIsSubstring(self): | |
397 af = FakeAffectedFile(changed_contents=[(1, 'foo'), (2, 'bar')]) | |
398 af_plus = FakeAffectedFile(changed_contents=[(6, 'foo'), (9, '<b>bar</b>')]) | |
399 # The generated file (first arg) can have extra formatting. | |
400 self.assertTrue(PRESUBMIT._ChangesMatch(af_plus, af)) | |
401 # But not the static file (second arg). | |
402 self.assertFalse(PRESUBMIT._ChangesMatch(af, af_plus)) | |
403 | |
404 def testChangesMatch_DuplicateLines(self): | |
405 af = FakeAffectedFile(changed_contents=[(1, 'foo'), (2, 'bar')]) | |
406 af_dups = FakeAffectedFile(changed_contents=[(7, 'foo'), (8, 'foo'), | |
407 (9, 'bar')]) | |
408 # Duplciate lines in the generated file (first arg) will be ignored | |
409 # like extra lines. | |
410 self.assertTrue(PRESUBMIT._ChangesMatch(af_dups, af)) | |
411 # Duplicate lines in static file (second arg) must each have a matching | |
412 # line in the generated file. | |
413 self.assertFalse(PRESUBMIT._ChangesMatch(af, af_dups)) | |
414 | |
415 def testChangesMatch_SkipEmptyLinesInStaticFile(self): | |
416 generated_file = FakeAffectedFile(changed_contents=[(1, 'foo'), | |
417 (14, 'bar')]) | |
418 static_file = FakeAffectedFile(changed_contents=[(1, 'foo'), | |
419 (2, ''), | |
420 (14, 'bar')]) | |
421 self.assertTrue(PRESUBMIT._ChangesMatch(generated_file, static_file)) | |
422 | |
423 def testChangesMatch_SkipExtraTextInGeneratedFile(self): | |
424 generated_file = FakeAffectedFile(changed_contents=[(1, 'foo'), | |
425 (14, 'bar'), | |
426 (15, 'baz')]) | |
427 static_file = FakeAffectedFile(changed_contents=[(1, 'bar')]) | |
428 self.assertTrue(PRESUBMIT._ChangesMatch(generated_file, static_file)) | |
429 | |
430 def testChangesMatch_Multiline(self): | |
431 generated_file = FakeAffectedFile(changed_contents=[(1, '<pre>{')]) | |
432 static_file = FakeAffectedFile(changed_contents=[(1, 'pre'), (2, '{')]) | |
433 self.assertTrue(PRESUBMIT._ChangesMatch(generated_file, static_file)) | |
434 | |
435 def testSampleZipped_ZipInAffectedFiles(self): | |
436 sample_file = FakeAffectedFile( | |
437 local_path='chrome/common/extensions/docs/examples/foo/bar/baz.jpg') | |
438 zip_file = FakeAffectedFile( | |
439 local_path='chrome/common/extensions/docs/examples/foo/bar.zip') | |
440 input_api = FakeInputApi(affected_files=[sample_file, zip_file]) | |
441 self.assertTrue(PRESUBMIT.SampleZipped(sample_file, input_api)) | |
442 | |
443 def testSampleZipped_NoZip(self): | |
444 sample_file = FakeAffectedFile( | |
445 local_path='chrome/common/extensions/docs/examples/foo/bar.jpg') | |
446 input_api = FakeInputApi(affected_files=[sample_file]) | |
447 | |
448 self.assertFalse(PRESUBMIT.SampleZipped(sample_file, input_api)) | |
449 | |
450 def testSampleZipped_WrongZip(self): | |
451 sample_file = FakeAffectedFile( | |
452 local_path='chrome/common/extensions/docs/examples/foo/bar.jpg') | |
453 zip_file = FakeAffectedFile( | |
454 local_path='chrome/common/extensions/docs/examples/baz.zip') | |
455 input_api = FakeInputApi(affected_files=[sample_file, zip_file]) | |
456 | |
457 self.assertFalse(PRESUBMIT.SampleZipped(sample_file, input_api)) | |
458 | |
459 | |
460 if __name__ == '__main__': | |
461 unittest.main() | |
OLD | NEW |