Commit 2d6b67c5 authored by Edward Lemur's avatar Edward Lemur Committed by Commit Bot

depot_tools: Fix bug when running both python2 and python3 tests.

Don't overwrite passed kwargs. Make a copy instead.
Otherwise, subsequent calls with the same kwargs will have
stdin set to subprocess.PIPE.

Bug: 984182
Change-Id: I358ffa1951e8b42486e0ac3a0d3d587a93c6dc4e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1769405
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
Auto-Submit: Edward Lesmes <ehmaldonado@chromium.org>
Reviewed-by: 's avatarRobbie Iannucci <iannucci@chromium.org>
parent 90e930e2
...@@ -70,7 +70,7 @@ class CommandData(object): ...@@ -70,7 +70,7 @@ class CommandData(object):
self.name = name self.name = name
self.cmd = cmd self.cmd = cmd
self.stdin = kwargs.get('stdin', None) self.stdin = kwargs.get('stdin', None)
self.kwargs = kwargs self.kwargs = kwargs.copy()
self.kwargs['stdout'] = subprocess.PIPE self.kwargs['stdout'] = subprocess.PIPE
self.kwargs['stderr'] = subprocess.STDOUT self.kwargs['stderr'] = subprocess.STDOUT
self.kwargs['stdin'] = subprocess.PIPE self.kwargs['stdin'] = subprocess.PIPE
......
...@@ -58,11 +58,6 @@ class MockTemporaryFile(object): ...@@ -58,11 +58,6 @@ class MockTemporaryFile(object):
pass pass
class MockProcess(object):
def __init__(self, returncode):
self.returncode = returncode
class PresubmitTestsBase(TestCaseUtils, unittest.TestCase): class PresubmitTestsBase(TestCaseUtils, unittest.TestCase):
"""Sets up and tears down the mocks but doesn't test anything as-is.""" """Sets up and tears down the mocks but doesn't test anything as-is."""
presubmit_text = """ presubmit_text = """
...@@ -2579,11 +2574,12 @@ the current line as well! ...@@ -2579,11 +2574,12 @@ the current line as well!
input_api.PresubmitLocalPath.return_value = self.fake_root_dir input_api.PresubmitLocalPath.return_value = self.fake_root_dir
presubmit.sigint_handler.wait.return_value = ('', None) presubmit.sigint_handler.wait.return_value = ('', None)
subprocess.Popen.side_effect = [ subprocesses = [
MockProcess(1), mock.Mock(returncode=1),
MockProcess(0), mock.Mock(returncode=0),
MockProcess(0), mock.Mock(returncode=0),
] ]
subprocess.Popen.side_effect = subprocesses
unit_tests = ['allo', 'bar.py'] unit_tests = ['allo', 'bar.py']
results = presubmit_canned_checks.RunUnitTests( results = presubmit_canned_checks.RunUnitTests(
...@@ -2616,6 +2612,12 @@ the current line as well! ...@@ -2616,6 +2612,12 @@ the current line as well!
stdin=subprocess.PIPE), stdin=subprocess.PIPE),
]) ])
self.assertEqual(presubmit.sigint_handler.wait.mock_calls, [
mock.call(subprocesses[0], None),
mock.call(subprocesses[1], None),
mock.call(subprocesses[2], None),
])
self.checkstdout('') self.checkstdout('')
@mock.patch('__builtin__.open', mock.mock_open()) @mock.patch('__builtin__.open', mock.mock_open())
...@@ -2629,9 +2631,9 @@ the current line as well! ...@@ -2629,9 +2631,9 @@ the current line as well!
presubmit.sigint_handler.wait.return_value = ('', None) presubmit.sigint_handler.wait.return_value = ('', None)
subprocess.Popen.side_effect = [ subprocess.Popen.side_effect = [
MockProcess(1), mock.Mock(returncode=1),
MockProcess(0), mock.Mock(returncode=0),
MockProcess(0), mock.Mock(returncode=0),
] ]
unit_tests = ['allo', 'bar.py'] unit_tests = ['allo', 'bar.py']
...@@ -2673,9 +2675,9 @@ the current line as well! ...@@ -2673,9 +2675,9 @@ the current line as well!
presubmit.sigint_handler.wait.return_value = ('', None) presubmit.sigint_handler.wait.return_value = ('', None)
subprocess.Popen.side_effect = [ subprocess.Popen.side_effect = [
MockProcess(1), mock.Mock(returncode=1),
MockProcess(0), mock.Mock(returncode=0),
MockProcess(0), mock.Mock(returncode=0),
] ]
unit_tests = ['allo', 'bar.py'] unit_tests = ['allo', 'bar.py']
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment