| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Test gsutil.py.""" | 6 """Test gsutil.py.""" |
| 7 | 7 |
| 8 | 8 |
| 9 import __builtin__ | 9 import __builtin__ |
| 10 import base64 | 10 import base64 |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 with zipfile.ZipFile(tempzip, 'w') as zf: | 137 with zipfile.ZipFile(tempzip, 'w') as zf: |
| 138 zf.writestr('gsutil/gsutil', fake_gsutil) | 138 zf.writestr('gsutil/gsutil', fake_gsutil) |
| 139 with open(tempzip, 'rb') as f: | 139 with open(tempzip, 'rb') as f: |
| 140 self.fake.add_expectation(url, _returns=Buffer(f.read())) | 140 self.fake.add_expectation(url, _returns=Buffer(f.read())) |
| 141 self.fake.add_expectation( | 141 self.fake.add_expectation( |
| 142 [sys.executable, gsutil_bin, 'version'], stdout=subprocess.PIPE, | 142 [sys.executable, gsutil_bin, 'version'], stdout=subprocess.PIPE, |
| 143 stderr=subprocess.STDOUT, _returns=1) | 143 stderr=subprocess.STDOUT, _returns=1) |
| 144 | 144 |
| 145 # This should delete the old bin and rewrite it with 'Fake gsutil' | 145 # This should delete the old bin and rewrite it with 'Fake gsutil' |
| 146 self.assertRaises( | 146 self.assertRaises( |
| 147 gsutil.InvalidGsutilError, gsutil.ensure_gsutil, version, self.tempdir) | 147 gsutil.InvalidGsutilError, gsutil.ensure_gsutil, version, self.tempdir, |
| 148 self.assertTrue(os.path.isdir(os.path.join(self.tempdir, '.cache_dir'))) | 148 False) |
| 149 self.assertTrue(os.path.exists(gsutil_bin)) | 149 self.assertTrue(os.path.exists(gsutil_bin)) |
| 150 with open(gsutil_bin, 'r') as f: | 150 with open(gsutil_bin, 'r') as f: |
| 151 self.assertEquals(f.read(), fake_gsutil) | 151 self.assertEquals(f.read(), fake_gsutil) |
| 152 self.assertEquals(self.fake.expectations, []) | 152 self.assertEquals(self.fake.expectations, []) |
| 153 | 153 |
| 154 def test_ensure_gsutil_short(self): | 154 def test_ensure_gsutil_short(self): |
| 155 version = '4.2' | 155 version = '4.2' |
| 156 gsutil_dir = os.path.join(self.tempdir, 'gsutil_%s' % version, 'gsutil') | 156 gsutil_dir = os.path.join(self.tempdir, 'gsutil_%s' % version, 'gsutil') |
| 157 gsutil_bin = os.path.join(gsutil_dir, 'gsutil') | 157 gsutil_bin = os.path.join(gsutil_dir, 'gsutil') |
| 158 os.makedirs(gsutil_dir) | 158 os.makedirs(gsutil_dir) |
| 159 | 159 |
| 160 # Mock out call(). | 160 # Mock out call(). |
| 161 self.fake.add_expectation( | 161 self.fake.add_expectation( |
| 162 [sys.executable, gsutil_bin, 'version'], | 162 [sys.executable, gsutil_bin, 'version'], |
| 163 stdout=subprocess.PIPE, stderr=subprocess.STDOUT, _returns=0) | 163 stdout=subprocess.PIPE, stderr=subprocess.STDOUT, _returns=0) |
| 164 | 164 |
| 165 with open(gsutil_bin, 'w') as f: | 165 with open(gsutil_bin, 'w') as f: |
| 166 f.write('Foobar') | 166 f.write('Foobar') |
| 167 self.assertEquals( | 167 self.assertEquals( |
| 168 gsutil.ensure_gsutil(version, self.tempdir), gsutil_bin) | 168 gsutil.ensure_gsutil(version, self.tempdir, False), gsutil_bin) |
| 169 | 169 |
| 170 if __name__ == '__main__': | 170 if __name__ == '__main__': |
| 171 unittest.main() | 171 unittest.main() |
| OLD | NEW |