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

Side by Side Diff: tests/presubmit_unittest.py

Issue 4360002: Largely reduce the number of pylint warnings and fix one typo. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: address comments Created 10 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 | Annotate | Revision Log
« no previous file with comments | « tests/gclient_utils_test.py ('k') | trychange.py » ('j') | 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/python 1 #!/usr/bin/python
2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2010 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 StringIO 8 import StringIO
9 9
10 # Fixes include path. 10 # Fixes include path.
(...skipping 19 matching lines...) Expand all
30 return () 30 return ()
31 """ 31 """
32 presubmit_tryslave = """ 32 presubmit_tryslave = """
33 def GetPreferredTrySlaves(): 33 def GetPreferredTrySlaves():
34 return %s 34 return %s
35 """ 35 """
36 36
37 def setUp(self): 37 def setUp(self):
38 SuperMoxTestBase.setUp(self) 38 SuperMoxTestBase.setUp(self)
39 self.mox.StubOutWithMock(presubmit, 'random') 39 self.mox.StubOutWithMock(presubmit, 'random')
40 self.mox.StubOutWithMock(presubmit, 'warnings') 40 self.mox.StubOutWithMock(presubmit, 'warn')
41 presubmit._ASKED_FOR_FEEDBACK = False 41 presubmit._ASKED_FOR_FEEDBACK = False
42 self.fake_root_dir = self.RootDir() 42 self.fake_root_dir = self.RootDir()
43 # Special mocks. 43 # Special mocks.
44 def MockAbsPath(f): 44 def MockAbsPath(f):
45 return f 45 return f
46 def MockChdir(f): 46 def MockChdir(f):
47 return None 47 return None
48 # SuperMoxTestBase already mock these but simplify our life. 48 # SuperMoxTestBase already mock these but simplify our life.
49 presubmit.os.path.abspath = MockAbsPath 49 presubmit.os.path.abspath = MockAbsPath
50 presubmit.os.getcwd = self.RootDir 50 presubmit.os.getcwd = self.RootDir
(...skipping 11 matching lines...) Expand all
62 62
63 def testMembersChanged(self): 63 def testMembersChanged(self):
64 self.mox.ReplayAll() 64 self.mox.ReplayAll()
65 members = [ 65 members = [
66 'AffectedFile', 'Change', 'DoGetTrySlaves', 'DoPresubmitChecks', 66 'AffectedFile', 'Change', 'DoGetTrySlaves', 'DoPresubmitChecks',
67 'GetTrySlavesExecuter', 'GitAffectedFile', 'GitChange', 67 'GetTrySlavesExecuter', 'GitAffectedFile', 'GitChange',
68 'InputApi', 'ListRelevantPresubmitFiles', 'Main', 68 'InputApi', 'ListRelevantPresubmitFiles', 'Main',
69 'NotImplementedException', 'OutputApi', 'ParseFiles', 69 'NotImplementedException', 'OutputApi', 'ParseFiles',
70 'PresubmitExecuter', 'PromptYesNo', 'ScanSubDirs', 70 'PresubmitExecuter', 'PromptYesNo', 'ScanSubDirs',
71 'SvnAffectedFile', 'SvnChange', 'cPickle', 'cStringIO', 71 'SvnAffectedFile', 'SvnChange', 'cPickle', 'cStringIO',
72 'exceptions', 'fnmatch', 'gcl', 'gclient_utils', 'glob', 'json', 72 'exceptions', 'fnmatch', 'gclient_utils', 'glob', 'json',
73 'logging', 'marshal', 'normpath', 'optparse', 'os', 'pickle', 73 'logging', 'marshal', 'normpath', 'optparse', 'os', 'pickle',
74 'presubmit_canned_checks', 'random', 're', 'scm', 'subprocess', 74 'presubmit_canned_checks', 'random', 're', 'scm', 'subprocess',
75 'sys', 'tempfile', 'time', 'traceback', 'types', 'unittest', 'urllib2', 75 'sys', 'tempfile', 'time', 'traceback', 'types', 'unittest', 'urllib2',
76 'warnings', 76 'warn',
77 ] 77 ]
78 # If this test fails, you should add the relevant test. 78 # If this test fails, you should add the relevant test.
79 self.compareMembers(presubmit, members) 79 self.compareMembers(presubmit, members)
80 80
81 def testListRelevantPresubmitFiles(self): 81 def testListRelevantPresubmitFiles(self):
82 join = presubmit.os.path.join 82 join = presubmit.os.path.join
83 files = [ 83 files = [
84 'blat.cc', 84 'blat.cc',
85 join('foo', 'haspresubmit', 'yodle', 'smart.h'), 85 join('foo', 'haspresubmit', 'yodle', 'smart.h'),
86 join('moo', 'mat', 'gat', 'yo.h'), 86 join('moo', 'mat', 'gat', 'yo.h'),
(...skipping 804 matching lines...) Expand 10 before | Expand all | Expand 10 after
891 is_committing=True) 891 is_committing=True)
892 paths_from_api = api.AbsoluteLocalPaths(include_dirs=True) 892 paths_from_api = api.AbsoluteLocalPaths(include_dirs=True)
893 self.assertEqual(len(paths_from_api), 2) 893 self.assertEqual(len(paths_from_api), 2)
894 for absolute_paths in [paths_from_change, paths_from_api]: 894 for absolute_paths in [paths_from_change, paths_from_api]:
895 self.assertEqual(absolute_paths[0], 895 self.assertEqual(absolute_paths[0],
896 normpath(join(self.fake_root_dir, 'isdir'))) 896 normpath(join(self.fake_root_dir, 'isdir')))
897 self.assertEqual(absolute_paths[1], 897 self.assertEqual(absolute_paths[1],
898 normpath(join(self.fake_root_dir, 'isdir', 'blat.cc'))) 898 normpath(join(self.fake_root_dir, 'isdir', 'blat.cc')))
899 899
900 def testDeprecated(self): 900 def testDeprecated(self):
901 presubmit.warnings.warn(mox.IgnoreArg(), category=mox.IgnoreArg(), 901 presubmit.warn(mox.IgnoreArg(), category=mox.IgnoreArg(), stacklevel=2)
902 stacklevel=2)
903 self.mox.ReplayAll() 902 self.mox.ReplayAll()
904 903
905 change = presubmit.Change('mychange', '', self.fake_root_dir, [], 0, 0) 904 change = presubmit.Change('mychange', '', self.fake_root_dir, [], 0, 0)
906 api = presubmit.InputApi( 905 api = presubmit.InputApi(
907 change, 906 change,
908 presubmit.os.path.join(self.fake_root_dir, 'foo', 'PRESUBMIT.py'), True) 907 presubmit.os.path.join(self.fake_root_dir, 'foo', 'PRESUBMIT.py'), True)
909 api.AffectedTextFiles(include_deletes=False) 908 api.AffectedTextFiles(include_deletes=False)
910 909
911 def testReadFileStringDenied(self): 910 def testReadFileStringDenied(self):
912 self.mox.ReplayAll() 911 self.mox.ReplayAll()
(...skipping 835 matching lines...) Expand 10 before | Expand all | Expand 10 after
1748 results = presubmit_canned_checks.CheckBuildbotPendingBuilds( 1747 results = presubmit_canned_checks.CheckBuildbotPendingBuilds(
1749 input_api, presubmit.OutputApi, 'uurl', 2, ('foo')) 1748 input_api, presubmit.OutputApi, 'uurl', 2, ('foo'))
1750 self.assertEquals(len(results), 1) 1749 self.assertEquals(len(results), 1)
1751 self.assertEquals(results[0].__class__, 1750 self.assertEquals(results[0].__class__,
1752 presubmit.OutputApi.PresubmitNotifyResult) 1751 presubmit.OutputApi.PresubmitNotifyResult)
1753 1752
1754 1753
1755 if __name__ == '__main__': 1754 if __name__ == '__main__':
1756 import unittest 1755 import unittest
1757 unittest.main() 1756 unittest.main()
OLDNEW
« no previous file with comments | « tests/gclient_utils_test.py ('k') | trychange.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698