From 0bcd1d343059104a979ceb68abe139cd48bc7a06 Mon Sep 17 00:00:00 2001 From: "maruel@chromium.org" Date: Tue, 26 Apr 2011 15:55:49 +0000 Subject: [PATCH] Make subprocess2.check_call() compliant with subprocess.check_call(). Rename check_call to check_call_out. It's a quite specific need when stderr is needed or when the user doesn't want the default arguments of check_output. R=dpranke@chromium.org BUG= TEST= Review URL: http://codereview.chromium.org/6882127 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@83023 0039d316-1c4b-4281-b951-d872f2087c98 --- checkout.py | 5 +++-- subprocess2.py | 14 ++++++++++---- tests/subprocess2_test.py | 2 +- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/checkout.py b/checkout.py index ab449b4da..38c269abe 100644 --- a/checkout.py +++ b/checkout.py @@ -191,7 +191,8 @@ class SvnMixIn(object): """Runs svn and throws an exception if the command failed.""" kwargs.setdefault('cwd', self.project_path) kwargs.setdefault('stdout', self.VOID) - return subprocess2.check_call(self._add_svn_flags(args, False), **kwargs) + return subprocess2.check_call_out( + self._add_svn_flags(args, False), **kwargs) def _check_output_svn(self, args, **kwargs): """Runs svn and throws an exception if the command failed. @@ -429,7 +430,7 @@ class GitCheckoutBase(CheckoutBase): def _check_call_git(self, args, **kwargs): kwargs.setdefault('cwd', self.project_path) kwargs.setdefault('stdout', self.VOID) - return subprocess2.check_call(['git'] + args, **kwargs) + return subprocess2.check_call_out(['git'] + args, **kwargs) def _call_git(self, args, **kwargs): """Like check_call but doesn't throw on failure.""" diff --git a/subprocess2.py b/subprocess2.py index acfe4a9a5..4ba3c65ab 100644 --- a/subprocess2.py +++ b/subprocess2.py @@ -256,7 +256,7 @@ def call(args, **kwargs): return communicate(args, **kwargs)[1] -def check_call(args, **kwargs): +def check_call_out(args, **kwargs): """Improved version of subprocess.check_call(). Returns (stdout, stderr), unlike subprocess.check_call(). @@ -268,6 +268,12 @@ def check_call(args, **kwargs): return out +def check_call(args, **kwargs): + """Emulate subprocess.check_call().""" + check_call_out(args, **kwargs) + return 0 + + def capture(args, **kwargs): """Captures stdout of a process call and returns it. @@ -287,9 +293,9 @@ def capture(args, **kwargs): def check_output(args, **kwargs): - """Captures stdout of a process call and returns it. + """Emulates subprocess.check_output(). - Returns stdout. + Captures stdout of a process call and returns stdout only. - Discards stderr. By default sets stderr=STDOUT. - Throws if return code is not 0. @@ -302,4 +308,4 @@ def check_output(args, **kwargs): kwargs['stdout'] = PIPE if kwargs.get('stderr') is None: kwargs['stderr'] = STDOUT - return check_call(args, **kwargs)[0] + return check_call_out(args, **kwargs)[0] diff --git a/tests/subprocess2_test.py b/tests/subprocess2_test.py index c419df022..031b6d984 100755 --- a/tests/subprocess2_test.py +++ b/tests/subprocess2_test.py @@ -82,7 +82,7 @@ class Subprocess2Test(unittest.TestCase): def test_check_call_defaults(self): results = self._fake_communicate() self.assertEquals( - ['stdout', 'stderr'], subprocess2.check_call(['foo'], a=True)) + ['stdout', 'stderr'], subprocess2.check_call_out(['foo'], a=True)) expected = { 'args': ['foo'], 'a':True,