download_from_google_storage: Fix tests and rename
the tests haven't been ran by presumbit for a while because of the plural in
the filename.
At some point some post "gsutil cp" file checking happened, which
broke the tests. This adds a callback to the fake gsutil cp so
that the expect file is copied over.
This also removes "gsutil version" checking from gsutil.py
and just assume that if the file exists, then it's good, which
should shave about 1-2s off of each gsutil.py call.
Bug: 772740,776311
Change-Id: I4fef62cfd46a849afed1f095dd6a96069376d13d
Reviewed-on: https://chromium-review.googlesource.com/707758
Commit-Queue: Ryan Tseng <hinoka@chromium.org>
Reviewed-by: Robbie Iannucci <iannucci@chromium.org>
Reviewed-by: Aaron Gable <agable@chromium.org>
diff --git a/tests/gsutil_test.py b/tests/gsutil_test.py
index d34eebf..d0fb8b0 100755
--- a/tests/gsutil_test.py
+++ b/tests/gsutil_test.py
@@ -122,14 +122,9 @@
version = '4.2'
gsutil_dir = os.path.join(self.tempdir, 'gsutil_%s' % version, 'gsutil')
gsutil_bin = os.path.join(gsutil_dir, 'gsutil')
+ gsutil_flag = os.path.join(gsutil_dir, 'install.flag')
os.makedirs(gsutil_dir)
- self.fake.add_expectation(
- [sys.executable, gsutil_bin, 'version'], stdout=subprocess.PIPE,
- stderr=subprocess.STDOUT, _returns=1)
-
- with open(gsutil_bin, 'w') as f:
- f.write('Foobar')
zip_filename = 'gsutil_%s.zip' % version
url = '%s%s' % (gsutil.GSUTIL_URL, zip_filename)
_, tempzip = tempfile.mkstemp()
@@ -138,32 +133,26 @@
zf.writestr('gsutil/gsutil', fake_gsutil)
with open(tempzip, 'rb') as f:
self.fake.add_expectation(url, _returns=Buffer(f.read()))
- self.fake.add_expectation(
- [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(
- gsutil.InvalidGsutilError, gsutil.ensure_gsutil, version, self.tempdir,
- False)
+ # This should write the gsutil_bin with 'Fake gsutil'
+ gsutil.ensure_gsutil(version, self.tempdir, False)
self.assertTrue(os.path.exists(gsutil_bin))
with open(gsutil_bin, 'r') as f:
self.assertEquals(f.read(), fake_gsutil)
+ self.assertTrue(os.path.exists(gsutil_flag))
self.assertEquals(self.fake.expectations, [])
def test_ensure_gsutil_short(self):
version = '4.2'
gsutil_dir = os.path.join(self.tempdir, 'gsutil_%s' % version, 'gsutil')
gsutil_bin = os.path.join(gsutil_dir, 'gsutil')
+ gsutil_flag = os.path.join(gsutil_dir, 'install.flag')
os.makedirs(gsutil_dir)
- # Mock out call().
- self.fake.add_expectation(
- [sys.executable, gsutil_bin, 'version'],
- stdout=subprocess.PIPE, stderr=subprocess.STDOUT, _returns=0)
-
with open(gsutil_bin, 'w') as f:
f.write('Foobar')
+ with open(gsutil_flag, 'w') as f:
+ f.write('Barbaz')
self.assertEquals(
gsutil.ensure_gsutil(version, self.tempdir, False), gsutil_bin)