From 2d6b67c590bc21568b1165f36102605d736c9dc1 Mon Sep 17 00:00:00 2001 From: Edward Lemur Date: Fri, 23 Aug 2019 22:25:41 +0000 Subject: [PATCH] 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 Auto-Submit: Edward Lesmes Reviewed-by: Robbie Iannucci --- presubmit_support.py | 2 +- tests/presubmit_unittest.py | 32 +++++++++++++++++--------------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/presubmit_support.py b/presubmit_support.py index 22ace3f40..205f23e2f 100755 --- a/presubmit_support.py +++ b/presubmit_support.py @@ -70,7 +70,7 @@ class CommandData(object): self.name = name self.cmd = cmd self.stdin = kwargs.get('stdin', None) - self.kwargs = kwargs + self.kwargs = kwargs.copy() self.kwargs['stdout'] = subprocess.PIPE self.kwargs['stderr'] = subprocess.STDOUT self.kwargs['stdin'] = subprocess.PIPE diff --git a/tests/presubmit_unittest.py b/tests/presubmit_unittest.py index d17cbad29..0c0cb6c8e 100755 --- a/tests/presubmit_unittest.py +++ b/tests/presubmit_unittest.py @@ -58,11 +58,6 @@ class MockTemporaryFile(object): pass -class MockProcess(object): - def __init__(self, returncode): - self.returncode = returncode - - class PresubmitTestsBase(TestCaseUtils, unittest.TestCase): """Sets up and tears down the mocks but doesn't test anything as-is.""" presubmit_text = """ @@ -2579,11 +2574,12 @@ the current line as well! input_api.PresubmitLocalPath.return_value = self.fake_root_dir presubmit.sigint_handler.wait.return_value = ('', None) - subprocess.Popen.side_effect = [ - MockProcess(1), - MockProcess(0), - MockProcess(0), + subprocesses = [ + mock.Mock(returncode=1), + mock.Mock(returncode=0), + mock.Mock(returncode=0), ] + subprocess.Popen.side_effect = subprocesses unit_tests = ['allo', 'bar.py'] results = presubmit_canned_checks.RunUnitTests( @@ -2616,6 +2612,12 @@ the current line as well! 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('') @mock.patch('__builtin__.open', mock.mock_open()) @@ -2629,9 +2631,9 @@ the current line as well! presubmit.sigint_handler.wait.return_value = ('', None) subprocess.Popen.side_effect = [ - MockProcess(1), - MockProcess(0), - MockProcess(0), + mock.Mock(returncode=1), + mock.Mock(returncode=0), + mock.Mock(returncode=0), ] unit_tests = ['allo', 'bar.py'] @@ -2673,9 +2675,9 @@ the current line as well! presubmit.sigint_handler.wait.return_value = ('', None) subprocess.Popen.side_effect = [ - MockProcess(1), - MockProcess(0), - MockProcess(0), + mock.Mock(returncode=1), + mock.Mock(returncode=0), + mock.Mock(returncode=0), ] unit_tests = ['allo', 'bar.py']