OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2006-2009 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 import exceptions | 8 import exceptions |
9 import random | 9 import random |
10 import string | 10 import string |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 class PresubmitUnittest(PresubmitTestsBase): | 106 class PresubmitUnittest(PresubmitTestsBase): |
107 """General presubmit_support.py tests (excluding InputApi and OutputApi).""" | 107 """General presubmit_support.py tests (excluding InputApi and OutputApi).""" |
108 def testMembersChanged(self): | 108 def testMembersChanged(self): |
109 self.mox.ReplayAll() | 109 self.mox.ReplayAll() |
110 members = [ | 110 members = [ |
111 'AffectedFile', 'DoPresubmitChecks', 'GclChange', 'InputApi', | 111 'AffectedFile', 'DoPresubmitChecks', 'GclChange', 'InputApi', |
112 'ListRelevantPresubmitFiles', 'Main', 'NotImplementedException', | 112 'ListRelevantPresubmitFiles', 'Main', 'NotImplementedException', |
113 'OutputApi', 'ParseFiles', 'PresubmitExecuter', | 113 'OutputApi', 'ParseFiles', 'PresubmitExecuter', |
114 'ScanSubDirs', 'SvnAffectedFile', | 114 'ScanSubDirs', 'SvnAffectedFile', |
115 'cPickle', 'cStringIO', 'exceptions', | 115 'cPickle', 'cStringIO', 'exceptions', |
116 'fnmatch', 'gcl', 'gclient', 'glob', 'marshal', 'normpath', 'optparse', | 116 'fnmatch', 'gcl', 'gclient', 'glob', 'logging', 'marshal', 'normpath', |
| 117 'optparse', |
117 'os', 'pickle', 'presubmit_canned_checks', 're', 'subprocess', 'sys', | 118 'os', 'pickle', 'presubmit_canned_checks', 're', 'subprocess', 'sys', |
118 'tempfile', 'traceback', 'types', 'unittest', 'urllib2', 'warnings', | 119 'tempfile', 'traceback', 'types', 'unittest', 'urllib2', 'warnings', |
119 ] | 120 ] |
120 # If this test fails, you should add the relevant test. | 121 # If this test fails, you should add the relevant test. |
121 self.compareMembers(presubmit, members) | 122 self.compareMembers(presubmit, members) |
122 | 123 |
123 def testListRelevantPresubmitFiles(self): | 124 def testListRelevantPresubmitFiles(self): |
124 join = presubmit.os.path.join | 125 join = presubmit.os.path.join |
125 files = [ | 126 files = [ |
126 'blat.cc', | 127 'blat.cc', |
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 # Ignores weird because of whitelist, third_party because of blacklist, | 641 # Ignores weird because of whitelist, third_party because of blacklist, |
641 # binary isn't a text file and beingdeleted doesn't exist. The rest is | 642 # binary isn't a text file and beingdeleted doesn't exist. The rest is |
642 # outside foo/. | 643 # outside foo/. |
643 rhs_lines = [x for x in input_api.RightHandSideLines(None)] | 644 rhs_lines = [x for x in input_api.RightHandSideLines(None)] |
644 self.assertEquals(len(rhs_lines), 4) | 645 self.assertEquals(len(rhs_lines), 4) |
645 self.assertEqual(rhs_lines[0][0].LocalPath(), presubmit.normpath(blat)) | 646 self.assertEqual(rhs_lines[0][0].LocalPath(), presubmit.normpath(blat)) |
646 self.assertEqual(rhs_lines[1][0].LocalPath(), presubmit.normpath(blat)) | 647 self.assertEqual(rhs_lines[1][0].LocalPath(), presubmit.normpath(blat)) |
647 self.assertEqual(rhs_lines[2][0].LocalPath(), presubmit.normpath(another)) | 648 self.assertEqual(rhs_lines[2][0].LocalPath(), presubmit.normpath(another)) |
648 self.assertEqual(rhs_lines[3][0].LocalPath(), presubmit.normpath(another)) | 649 self.assertEqual(rhs_lines[3][0].LocalPath(), presubmit.normpath(another)) |
649 | 650 |
| 651 def testDefaultWhiteListBlackListFilters(self): |
| 652 def f(x): |
| 653 return presubmit.AffectedFile(x, 'M') |
| 654 files = [ |
| 655 ( |
| 656 [ |
| 657 # To be tested. |
| 658 f('a/experimental/b'), |
| 659 f('experimental/b'), |
| 660 f('a/experimental'), |
| 661 f('a/experimental.cc'), |
| 662 ], |
| 663 [ |
| 664 # Expected. |
| 665 'a/experimental', |
| 666 'a/experimental.cc', |
| 667 ], |
| 668 ), |
| 669 ( |
| 670 [ |
| 671 # To be tested. |
| 672 f('a/third_party/b'), |
| 673 f('third_party/b'), |
| 674 f('a/third_party'), |
| 675 f('a/third_party.cc'), |
| 676 ], |
| 677 [ |
| 678 # Expected. |
| 679 'a/third_party', |
| 680 'a/third_party.cc', |
| 681 ], |
| 682 ), |
| 683 ( |
| 684 [ |
| 685 # To be tested. |
| 686 f('a/LOL_FILE/b'), |
| 687 f('b.c/LOL_FILE'), |
| 688 f('a/PRESUBMIT.py'), |
| 689 ], |
| 690 [ |
| 691 # Expected. |
| 692 'a/LOL_FILE/b', |
| 693 'a/PRESUBMIT.py', |
| 694 ], |
| 695 ), |
| 696 ( |
| 697 [ |
| 698 # To be tested. |
| 699 f('a/.git'), |
| 700 f('b.c/.git'), |
| 701 f('a/.git/bleh.py'), |
| 702 f('.git/bleh.py'), |
| 703 ], |
| 704 [ |
| 705 # Expected. |
| 706 'b.c/.git', |
| 707 ], |
| 708 ), |
| 709 ] |
| 710 input_api = presubmit.InputApi(None, './PRESUBMIT.py', False) |
| 711 self.mox.ReplayAll() |
| 712 |
| 713 self.assertEqual(len(input_api.DEFAULT_BLACK_LIST), 9) |
| 714 for item in files: |
| 715 results = filter(input_api.FilterSourceFile, item[0]) |
| 716 for i in range(len(results)): |
| 717 self.assertEquals(results[i].LocalPath(), |
| 718 presubmit.normpath(item[1][i])) |
| 719 # Same number of expected results. |
| 720 self.assertEquals(len(results), len(item[1])) |
| 721 |
650 def testCustomFilter(self): | 722 def testCustomFilter(self): |
651 def FilterSourceFile(affected_file): | 723 def FilterSourceFile(affected_file): |
652 return 'a' in affected_file.LocalPath() | 724 return 'a' in affected_file.LocalPath() |
653 files = [('A', 'eeaee'), ('M', 'eeabee'), ('M', 'eebcee')] | 725 files = [('A', 'eeaee'), ('M', 'eeabee'), ('M', 'eebcee')] |
654 for (action, item) in files: | 726 for (action, item) in files: |
655 presubmit.os.path.exists(item).AndReturn(True) | 727 presubmit.os.path.exists(item).AndReturn(True) |
656 presubmit.os.path.isdir(item).AndReturn(False) | 728 presubmit.os.path.isdir(item).AndReturn(False) |
657 presubmit.gcl.GetSVNFileProperty(item, 'svn:mime-type').AndReturn(None) | 729 presubmit.gcl.GetSVNFileProperty(item, 'svn:mime-type').AndReturn(None) |
658 self.mox.ReplayAll() | 730 self.mox.ReplayAll() |
659 | 731 |
(...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1307 test_result.errors = 0 | 1379 test_result.errors = 0 |
1308 self.mox.ReplayAll() | 1380 self.mox.ReplayAll() |
1309 | 1381 |
1310 results = presubmit_canned_checks.RunPythonUnitTests( | 1382 results = presubmit_canned_checks.RunPythonUnitTests( |
1311 input_api, presubmit.OutputApi, ['test_module']) | 1383 input_api, presubmit.OutputApi, ['test_module']) |
1312 self.assertEquals(len(results), 0) | 1384 self.assertEquals(len(results), 0) |
1313 | 1385 |
1314 | 1386 |
1315 if __name__ == '__main__': | 1387 if __name__ == '__main__': |
1316 unittest.main() | 1388 unittest.main() |
OLD | NEW |