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

Side by Side Diff: tests/presubmit_unittest.py

Issue 10654002: Pass arguments to pylint child process via a pipe. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Addressed nit. Created 8 years, 6 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 | « pylint.py ('k') | third_party/pylint.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/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 subprocess
13 import sys 14 import sys
14 import time 15 import time
15 16
16 _ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 17 _ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
17 sys.path.insert(0, _ROOT) 18 sys.path.insert(0, _ROOT)
18 19
19 from testing_support.super_mox import mox, SuperMoxTestBase 20 from testing_support.super_mox import mox, SuperMoxTestBase
20 21
21 import owners 22 import owners
22 import presubmit_support as presubmit 23 import presubmit_support as presubmit
(...skipping 2113 matching lines...) Expand 10 before | Expand all | Expand 10 after
2136 def testCannedRunPylint(self): 2137 def testCannedRunPylint(self):
2137 input_api = self.MockInputApi(None, True) 2138 input_api = self.MockInputApi(None, True)
2138 input_api.environ = self.mox.CreateMock(os.environ) 2139 input_api.environ = self.mox.CreateMock(os.environ)
2139 input_api.environ.copy().AndReturn({}) 2140 input_api.environ.copy().AndReturn({})
2140 input_api.AffectedSourceFiles(mox.IgnoreArg()).AndReturn(True) 2141 input_api.AffectedSourceFiles(mox.IgnoreArg()).AndReturn(True)
2141 input_api.PresubmitLocalPath().AndReturn('/foo') 2142 input_api.PresubmitLocalPath().AndReturn('/foo')
2142 input_api.PresubmitLocalPath().AndReturn('/foo') 2143 input_api.PresubmitLocalPath().AndReturn('/foo')
2143 input_api.os_walk('/foo').AndReturn([('/foo', [], ['file1.py'])]) 2144 input_api.os_walk('/foo').AndReturn([('/foo', [], ['file1.py'])])
2144 pylint = os.path.join(_ROOT, 'third_party', 'pylint.py') 2145 pylint = os.path.join(_ROOT, 'third_party', 'pylint.py')
2145 pylintrc = os.path.join(_ROOT, 'pylintrc') 2146 pylintrc = os.path.join(_ROOT, 'pylintrc')
2146 input_api.subprocess.call( 2147
2147 ['pyyyyython', pylint, 'file1.py', '--rcfile=%s' % pylintrc], 2148 # Create a mock Popen object, and set up its expectations.
2148 env=mox.IgnoreArg()) 2149 child = self.mox.CreateMock(subprocess.Popen)
2150 child.stdin = self.mox.CreateMock(file)
2151 child.stdin.write('file1.py\n')
2152 child.stdin.write('--rcfile=%s\n' % pylintrc)
2153 child.stdin.close()
2154 child.communicate()
2155 child.returncode = 0
2156
2157 input_api.subprocess.Popen(['pyyyyython', pylint, '--args-on-stdin'],
2158 env=mox.IgnoreArg(), stdin=subprocess.PIPE).AndReturn(child)
2149 self.mox.ReplayAll() 2159 self.mox.ReplayAll()
2150 2160
2151 results = presubmit_canned_checks.RunPylint( 2161 results = presubmit_canned_checks.RunPylint(
2152 input_api, presubmit.OutputApi) 2162 input_api, presubmit.OutputApi)
2153 self.assertEquals([], results) 2163 self.assertEquals([], results)
2154 2164
2155 def testCheckBuildbotPendingBuildsBad(self): 2165 def testCheckBuildbotPendingBuildsBad(self):
2156 input_api = self.MockInputApi(None, True) 2166 input_api = self.MockInputApi(None, True)
2157 connection = self.mox.CreateMockAnything() 2167 connection = self.mox.CreateMockAnything()
2158 input_api.urllib2.urlopen('uurl').AndReturn(connection) 2168 input_api.urllib2.urlopen('uurl').AndReturn(connection)
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
2458 owners_check=False) 2468 owners_check=False)
2459 self.assertEqual(1, len(results)) 2469 self.assertEqual(1, len(results))
2460 self.assertEqual( 2470 self.assertEqual(
2461 'Found line ending with white spaces in:', results[0]._message) 2471 'Found line ending with white spaces in:', results[0]._message)
2462 self.checkstdout('') 2472 self.checkstdout('')
2463 2473
2464 2474
2465 if __name__ == '__main__': 2475 if __name__ == '__main__':
2466 import unittest 2476 import unittest
2467 unittest.main() 2477 unittest.main()
OLDNEW
« no previous file with comments | « pylint.py ('k') | third_party/pylint.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698