| OLD | NEW |
| 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 presubmit_support.py and presubmit_canned_checks.py.""" | 6 """Unit tests for presubmit_support.py and presubmit_canned_checks.py.""" |
| 7 | 7 |
| 8 # pylint: disable=E1101,E1103 | 8 # pylint: disable=E1101,E1103 |
| 9 | 9 |
| 10 import logging | 10 import logging |
| (...skipping 1257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1268 self.mox.ReplayAll() | 1268 self.mox.ReplayAll() |
| 1269 | 1269 |
| 1270 change = presubmit.Change( | 1270 change = presubmit.Change( |
| 1271 'foo', 'foo', self.fake_root_dir, [('M', 'AA')], 0, 0, None) | 1271 'foo', 'foo', self.fake_root_dir, [('M', 'AA')], 0, 0, None) |
| 1272 input_api = presubmit.InputApi( | 1272 input_api = presubmit.InputApi( |
| 1273 change, presubmit.os.path.join(self.fake_root_dir, '/p'), False, | 1273 change, presubmit.os.path.join(self.fake_root_dir, '/p'), False, |
| 1274 None, False) | 1274 None, False) |
| 1275 input_api.ReadFile(fileobj, 'x') | 1275 input_api.ReadFile(fileobj, 'x') |
| 1276 | 1276 |
| 1277 | 1277 |
| 1278 class OuputApiUnittest(PresubmitTestsBase): | 1278 class OutputApiUnittest(PresubmitTestsBase): |
| 1279 """Tests presubmit.OutputApi.""" | 1279 """Tests presubmit.OutputApi.""" |
| 1280 |
| 1280 def testMembersChanged(self): | 1281 def testMembersChanged(self): |
| 1281 self.mox.ReplayAll() | 1282 self.mox.ReplayAll() |
| 1282 members = [ | 1283 members = [ |
| 1283 'MailTextResult', 'PresubmitAddReviewers', 'PresubmitError', | 1284 'MailTextResult', 'PresubmitAddReviewers', 'PresubmitError', |
| 1284 'PresubmitNotifyResult', 'PresubmitPromptWarning', 'PresubmitResult', | 1285 'PresubmitNotifyResult', 'PresubmitPromptWarning', |
| 1286 'PresubmitPromptOrNotify', 'PresubmitResult', 'is_committing', |
| 1285 ] | 1287 ] |
| 1286 # If this test fails, you should add the relevant test. | 1288 # If this test fails, you should add the relevant test. |
| 1287 self.compareMembers(presubmit.OutputApi(), members) | 1289 self.compareMembers(presubmit.OutputApi(False), members) |
| 1288 | 1290 |
| 1289 def testOutputApiBasics(self): | 1291 def testOutputApiBasics(self): |
| 1290 self.mox.ReplayAll() | 1292 self.mox.ReplayAll() |
| 1291 self.failUnless(presubmit.OutputApi.PresubmitError('').fatal) | 1293 self.failUnless(presubmit.OutputApi.PresubmitError('').fatal) |
| 1292 self.failIf(presubmit.OutputApi.PresubmitError('').should_prompt) | 1294 self.failIf(presubmit.OutputApi.PresubmitError('').should_prompt) |
| 1293 | 1295 |
| 1294 self.failIf(presubmit.OutputApi.PresubmitPromptWarning('').fatal) | 1296 self.failIf(presubmit.OutputApi.PresubmitPromptWarning('').fatal) |
| 1295 self.failUnless( | 1297 self.failUnless( |
| 1296 presubmit.OutputApi.PresubmitPromptWarning('').should_prompt) | 1298 presubmit.OutputApi.PresubmitPromptWarning('').should_prompt) |
| 1297 | 1299 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1323 presubmit.OutputApi.PresubmitNotifyResult('?see?').handle(output) | 1325 presubmit.OutputApi.PresubmitNotifyResult('?see?').handle(output) |
| 1324 self.failUnless(output.should_continue()) | 1326 self.failUnless(output.should_continue()) |
| 1325 self.failUnless(output.getvalue().count('?see?')) | 1327 self.failUnless(output.getvalue().count('?see?')) |
| 1326 | 1328 |
| 1327 output = presubmit.PresubmitOutput(input_stream=StringIO.StringIO('y')) | 1329 output = presubmit.PresubmitOutput(input_stream=StringIO.StringIO('y')) |
| 1328 presubmit.OutputApi.PresubmitPromptWarning('???').handle(output) | 1330 presubmit.OutputApi.PresubmitPromptWarning('???').handle(output) |
| 1329 output.prompt_yes_no('prompt: ') | 1331 output.prompt_yes_no('prompt: ') |
| 1330 self.failUnless(output.should_continue()) | 1332 self.failUnless(output.should_continue()) |
| 1331 self.failUnless(output.getvalue().count('???')) | 1333 self.failUnless(output.getvalue().count('???')) |
| 1332 | 1334 |
| 1333 output = presubmit.PresubmitOutput(input_stream=StringIO.StringIO('y')) | |
| 1334 presubmit.OutputApi.PresubmitPromptWarning('???').handle(output) | |
| 1335 output.prompt_yes_no('prompt: ') | |
| 1336 self.failUnless(output.should_continue()) | |
| 1337 self.failUnless(output.getvalue().count('???')) | |
| 1338 | |
| 1339 output = presubmit.PresubmitOutput(input_stream=StringIO.StringIO('\n')) | 1335 output = presubmit.PresubmitOutput(input_stream=StringIO.StringIO('\n')) |
| 1340 presubmit.OutputApi.PresubmitPromptWarning('???').handle(output) | 1336 presubmit.OutputApi.PresubmitPromptWarning('???').handle(output) |
| 1341 output.prompt_yes_no('prompt: ') | 1337 output.prompt_yes_no('prompt: ') |
| 1342 self.failIf(output.should_continue()) | 1338 self.failIf(output.should_continue()) |
| 1343 self.failUnless(output.getvalue().count('???')) | 1339 self.failUnless(output.getvalue().count('???')) |
| 1344 | 1340 |
| 1341 output_api = presubmit.OutputApi(True) |
| 1342 output = presubmit.PresubmitOutput(input_stream=StringIO.StringIO('y')) |
| 1343 output_api.PresubmitPromptOrNotify('???').handle(output) |
| 1344 output.prompt_yes_no('prompt: ') |
| 1345 self.failUnless(output.should_continue()) |
| 1346 self.failUnless(output.getvalue().count('???')) |
| 1347 |
| 1348 output_api = presubmit.OutputApi(False) |
| 1349 output = presubmit.PresubmitOutput(input_stream=StringIO.StringIO('y')) |
| 1350 output_api.PresubmitPromptOrNotify('???').handle(output) |
| 1351 self.failUnless(output.should_continue()) |
| 1352 self.failUnless(output.getvalue().count('???')) |
| 1353 |
| 1354 output_api = presubmit.OutputApi(True) |
| 1355 output = presubmit.PresubmitOutput(input_stream=StringIO.StringIO('\n')) |
| 1356 output_api.PresubmitPromptOrNotify('???').handle(output) |
| 1357 output.prompt_yes_no('prompt: ') |
| 1358 self.failIf(output.should_continue()) |
| 1359 self.failUnless(output.getvalue().count('???')) |
| 1345 | 1360 |
| 1346 class AffectedFileUnittest(PresubmitTestsBase): | 1361 class AffectedFileUnittest(PresubmitTestsBase): |
| 1347 def testMembersChanged(self): | 1362 def testMembersChanged(self): |
| 1348 self.mox.ReplayAll() | 1363 self.mox.ReplayAll() |
| 1349 members = [ | 1364 members = [ |
| 1350 'AbsoluteLocalPath', 'Action', 'ChangedContents', 'GenerateScmDiff', | 1365 'AbsoluteLocalPath', 'Action', 'ChangedContents', 'GenerateScmDiff', |
| 1351 'IsDirectory', 'IsTextFile', 'LocalPath', 'NewContents', 'OldContents', | 1366 'IsDirectory', 'IsTextFile', 'LocalPath', 'NewContents', 'OldContents', |
| 1352 'OldFileTempPath', 'Property', 'ServerPath', | 1367 'OldFileTempPath', 'Property', 'ServerPath', |
| 1353 ] | 1368 ] |
| 1354 # If this test fails, you should add the relevant test. | 1369 # If this test fails, you should add the relevant test. |
| (...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1996 | 2011 |
| 1997 check = presubmit_canned_checks.CheckSvnModifiedDirectories | 2012 check = presubmit_canned_checks.CheckSvnModifiedDirectories |
| 1998 results = check(input_api, presubmit.OutputApi, None) | 2013 results = check(input_api, presubmit.OutputApi, None) |
| 1999 self.assertEquals(len(results), 1) | 2014 self.assertEquals(len(results), 1) |
| 2000 self.assertEquals(results[0].__class__, | 2015 self.assertEquals(results[0].__class__, |
| 2001 presubmit.OutputApi.PresubmitPromptWarning) | 2016 presubmit.OutputApi.PresubmitPromptWarning) |
| 2002 | 2017 |
| 2003 def testCheckSvnForCommonMimeTypes(self): | 2018 def testCheckSvnForCommonMimeTypes(self): |
| 2004 self.mox.StubOutWithMock(presubmit_canned_checks, 'CheckSvnProperty') | 2019 self.mox.StubOutWithMock(presubmit_canned_checks, 'CheckSvnProperty') |
| 2005 input_api = self.MockInputApi(None, False) | 2020 input_api = self.MockInputApi(None, False) |
| 2006 output_api = presubmit.OutputApi() | 2021 output_api = presubmit.OutputApi(False) |
| 2007 A = lambda x: presubmit.AffectedFile(x, 'M', self.fake_root_dir) | 2022 A = lambda x: presubmit.AffectedFile(x, 'M', self.fake_root_dir) |
| 2008 files = [ | 2023 files = [ |
| 2009 A('a.pdf'), A('b.bmp'), A('c.gif'), A('d.png'), A('e.jpg'), A('f.jpe'), | 2024 A('a.pdf'), A('b.bmp'), A('c.gif'), A('d.png'), A('e.jpg'), A('f.jpe'), |
| 2010 A('random'), A('g.jpeg'), A('h.ico'), | 2025 A('random'), A('g.jpeg'), A('h.ico'), |
| 2011 ] | 2026 ] |
| 2012 input_api.AffectedFiles(include_deletes=False).AndReturn(files) | 2027 input_api.AffectedFiles(include_deletes=False).AndReturn(files) |
| 2013 presubmit_canned_checks.CheckSvnProperty( | 2028 presubmit_canned_checks.CheckSvnProperty( |
| 2014 input_api, output_api, 'svn:mime-type', 'application/pdf', [files[0]] | 2029 input_api, output_api, 'svn:mime-type', 'application/pdf', [files[0]] |
| 2015 ).AndReturn([1]) | 2030 ).AndReturn([1]) |
| 2016 presubmit_canned_checks.CheckSvnProperty( | 2031 presubmit_canned_checks.CheckSvnProperty( |
| (...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2521 owners_check=False) | 2536 owners_check=False) |
| 2522 self.assertEqual(1, len(results)) | 2537 self.assertEqual(1, len(results)) |
| 2523 self.assertEqual( | 2538 self.assertEqual( |
| 2524 'Found line ending with white spaces in:', results[0]._message) | 2539 'Found line ending with white spaces in:', results[0]._message) |
| 2525 self.checkstdout('') | 2540 self.checkstdout('') |
| 2526 | 2541 |
| 2527 | 2542 |
| 2528 if __name__ == '__main__': | 2543 if __name__ == '__main__': |
| 2529 import unittest | 2544 import unittest |
| 2530 unittest.main() | 2545 unittest.main() |
| OLD | NEW |