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

Side by Side Diff: tests/presubmit_unittest.py

Issue 10199016: Add disabled_warnings arg to RunPylint() and use the default pylintrc file by default. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Add hashlib to the ignored symbols by pylint Created 8 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « pylintrc ('k') | no next file » | 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/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
11 import os 11 import os
12 import StringIO 12 import StringIO
13 import sys 13 import sys
14 import time 14 import time
15 15
16 # TODO(maruel): Include inside depot_tools.
17 from pylint import lint
18
16 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) 19 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
17 20
18 from testing_support.super_mox import mox, SuperMoxTestBase 21 from testing_support.super_mox import mox, SuperMoxTestBase
19 22
20 import owners 23 import owners
21 import presubmit_support as presubmit 24 import presubmit_support as presubmit
22 import rietveld 25 import rietveld
23 26
24 # Shortcut. 27 # Shortcut.
25 presubmit_canned_checks = presubmit.presubmit_canned_checks 28 presubmit_canned_checks = presubmit.presubmit_canned_checks
(...skipping 1416 matching lines...) Expand 10 before | Expand all | Expand 10 after
1442 1445
1443 1446
1444 class CannedChecksUnittest(PresubmitTestsBase): 1447 class CannedChecksUnittest(PresubmitTestsBase):
1445 """Tests presubmit_canned_checks.py.""" 1448 """Tests presubmit_canned_checks.py."""
1446 1449
1447 def MockInputApi(self, change, committing): 1450 def MockInputApi(self, change, committing):
1448 # pylint: disable=R0201 1451 # pylint: disable=R0201
1449 input_api = self.mox.CreateMock(presubmit.InputApi) 1452 input_api = self.mox.CreateMock(presubmit.InputApi)
1450 input_api.cStringIO = presubmit.cStringIO 1453 input_api.cStringIO = presubmit.cStringIO
1451 input_api.json = presubmit.json 1454 input_api.json = presubmit.json
1455 input_api.logging = logging
1452 input_api.os_listdir = self.mox.CreateMockAnything() 1456 input_api.os_listdir = self.mox.CreateMockAnything()
1453 input_api.os_walk = self.mox.CreateMockAnything() 1457 input_api.os_walk = self.mox.CreateMockAnything()
1454 input_api.os_path = presubmit.os.path 1458 input_api.os_path = presubmit.os.path
1455 input_api.re = presubmit.re 1459 input_api.re = presubmit.re
1456 input_api.rietveld = self.mox.CreateMock(rietveld.Rietveld) 1460 input_api.rietveld = self.mox.CreateMock(rietveld.Rietveld)
1457 input_api.traceback = presubmit.traceback 1461 input_api.traceback = presubmit.traceback
1458 input_api.urllib2 = self.mox.CreateMock(presubmit.urllib2) 1462 input_api.urllib2 = self.mox.CreateMock(presubmit.urllib2)
1459 input_api.unittest = unittest 1463 input_api.unittest = unittest
1460 input_api.subprocess = self.mox.CreateMock(presubmit.subprocess) 1464 input_api.subprocess = self.mox.CreateMock(presubmit.subprocess)
1461 class fake_CalledProcessError(Exception): 1465 class fake_CalledProcessError(Exception):
1462 def __str__(self): 1466 def __str__(self):
1463 return 'foo' 1467 return 'foo'
1464 input_api.subprocess.CalledProcessError = fake_CalledProcessError 1468 input_api.subprocess.CalledProcessError = fake_CalledProcessError
1469 input_api.verbose = False
1465 1470
1466 input_api.change = change 1471 input_api.change = change
1467 input_api.host_url = 'http://localhost' 1472 input_api.host_url = 'http://localhost'
1468 input_api.is_committing = committing 1473 input_api.is_committing = committing
1469 input_api.tbr = False 1474 input_api.tbr = False
1470 input_api.python_executable = 'pyyyyython' 1475 input_api.python_executable = 'pyyyyython'
1471 input_api.platform = sys.platform 1476 input_api.platform = sys.platform
1472 input_api.time = time 1477 input_api.time = time
1473 input_api.canned_checks = presubmit_canned_checks 1478 input_api.canned_checks = presubmit_canned_checks
1474 return input_api 1479 return input_api
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after
2123 input_api.unittest = self.mox.CreateMock(unittest) 2128 input_api.unittest = self.mox.CreateMock(unittest)
2124 input_api.subprocess.check_output( 2129 input_api.subprocess.check_output(
2125 ['pyyyyython', '-m', 'test_module'], cwd=None, env=None, 2130 ['pyyyyython', '-m', 'test_module'], cwd=None, env=None,
2126 stderr=input_api.subprocess.STDOUT) 2131 stderr=input_api.subprocess.STDOUT)
2127 self.mox.ReplayAll() 2132 self.mox.ReplayAll()
2128 2133
2129 results = presubmit_canned_checks.RunPythonUnitTests( 2134 results = presubmit_canned_checks.RunPythonUnitTests(
2130 input_api, presubmit.OutputApi, ['test_module']) 2135 input_api, presubmit.OutputApi, ['test_module'])
2131 self.assertEquals(len(results), 0) 2136 self.assertEquals(len(results), 0)
2132 2137
2138 def testCannedRunPylint(self):
2139 # lint.Run() always calls sys.exit()...
2140 lint.Run = lambda x: sys.exit(0)
2141 input_api = self.MockInputApi(None, True)
2142 input_api.AffectedSourceFiles(mox.IgnoreArg()).AndReturn(True)
2143 input_api.PresubmitLocalPath().AndReturn('/foo')
2144 input_api.PresubmitLocalPath().AndReturn('/foo')
2145 input_api.os_walk('/foo').AndReturn([('/foo', [], ['file1.py'])])
2146 self.mox.ReplayAll()
2147
2148 results = presubmit_canned_checks.RunPylint(
2149 input_api, presubmit.OutputApi)
2150 self.assertEquals([], results)
2151
2133 def testCheckBuildbotPendingBuildsBad(self): 2152 def testCheckBuildbotPendingBuildsBad(self):
2134 input_api = self.MockInputApi(None, True) 2153 input_api = self.MockInputApi(None, True)
2135 connection = self.mox.CreateMockAnything() 2154 connection = self.mox.CreateMockAnything()
2136 input_api.urllib2.urlopen('uurl').AndReturn(connection) 2155 input_api.urllib2.urlopen('uurl').AndReturn(connection)
2137 connection.read().AndReturn('foo') 2156 connection.read().AndReturn('foo')
2138 connection.close() 2157 connection.close()
2139 self.mox.ReplayAll() 2158 self.mox.ReplayAll()
2140 2159
2141 results = presubmit_canned_checks.CheckBuildbotPendingBuilds( 2160 results = presubmit_canned_checks.CheckBuildbotPendingBuilds(
2142 input_api, presubmit.OutputApi, 'uurl', 2, ('foo')) 2161 input_api, presubmit.OutputApi, 'uurl', 2, ('foo'))
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
2434 owners_check=False) 2453 owners_check=False)
2435 self.assertEqual(1, len(results)) 2454 self.assertEqual(1, len(results))
2436 self.assertEqual( 2455 self.assertEqual(
2437 'Found line ending with white spaces in:', results[0]._message) 2456 'Found line ending with white spaces in:', results[0]._message)
2438 self.checkstdout('') 2457 self.checkstdout('')
2439 2458
2440 2459
2441 if __name__ == '__main__': 2460 if __name__ == '__main__':
2442 import unittest 2461 import unittest
2443 unittest.main() 2462 unittest.main()
OLDNEW
« no previous file with comments | « pylintrc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698