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

Unified Diff: tests/gsutil_test.py

Issue 870093003: Hook sys.stdio directly to the gsutil subprocess for the gsutil call (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Fix tests Created 5 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gsutil.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/gsutil_test.py
diff --git a/tests/gsutil_test.py b/tests/gsutil_test.py
index 30648279d363408f5528f3f4cbb096fa027b3b5f..76570dd31034727b4c38346ea6e84fe383f9b234 100755
--- a/tests/gsutil_test.py
+++ b/tests/gsutil_test.py
@@ -7,16 +7,17 @@
import __builtin__
-import unittest
+import base64
import hashlib
-import zipfile
+import json
+import os
import shutil
+import subprocess
import sys
-import base64
import tempfile
-import json
-import os
+import unittest
import urllib2
+import zipfile
# Add depot_tools to path
@@ -62,8 +63,6 @@ class FakeCall(object):
message = 'Expected:\n args: %s\n kwargs: %s\n' % (exp_args, exp_kwargs)
message += 'Got:\n args: %s\n kwargs: %s\n' % (args, kwargs)
raise TestError(message)
- if isinstance(exp_returns, Exception):
- raise exp_returns
return exp_returns
@@ -72,15 +71,15 @@ class GsutilUnitTests(unittest.TestCase):
self.fake = FakeCall()
self.tempdir = tempfile.mkdtemp()
self.old_urlopen = getattr(urllib2, 'urlopen')
- self.old_call = getattr(gsutil, 'call')
+ self.old_call = getattr(subprocess, 'call')
setattr(urllib2, 'urlopen', self.fake)
- setattr(gsutil, 'call', self.fake)
+ setattr(subprocess, 'call', self.fake)
def tearDown(self):
self.assertEqual(self.fake.expectations, [])
shutil.rmtree(self.tempdir)
setattr(urllib2, 'urlopen', self.old_urlopen)
- setattr(gsutil, 'call', self.old_call)
+ setattr(subprocess, 'call', self.old_call)
def test_download_gsutil(self):
version = '4.2'
@@ -126,8 +125,8 @@ class GsutilUnitTests(unittest.TestCase):
os.makedirs(gsutil_dir)
self.fake.add_expectation(
- [sys.executable, gsutil_bin, 'version'], verbose=False,
- _returns=gsutil.SubprocessError())
+ [sys.executable, gsutil_bin, 'version'], stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT, _returns=1)
with open(gsutil_bin, 'w') as f:
f.write('Foobar')
@@ -140,8 +139,8 @@ class GsutilUnitTests(unittest.TestCase):
with open(tempzip, 'rb') as f:
self.fake.add_expectation(url, _returns=Buffer(f.read()))
self.fake.add_expectation(
- [sys.executable, gsutil_bin, 'version'], verbose=False,
- _returns=gsutil.SubprocessError())
+ [sys.executable, gsutil_bin, 'version'], stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT, _returns=1)
# This should delete the old bin and rewrite it with 'Fake gsutil'
self.assertRaises(
@@ -160,7 +159,8 @@ class GsutilUnitTests(unittest.TestCase):
# Mock out call().
self.fake.add_expectation(
- [sys.executable, gsutil_bin, 'version'], verbose=False, _returns=True)
+ [sys.executable, gsutil_bin, 'version'],
+ stdout=subprocess.PIPE, stderr=subprocess.STDOUT, _returns=0)
with open(gsutil_bin, 'w') as f:
f.write('Foobar')
« no previous file with comments | « gsutil.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698