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

Side by Side Diff: tests/gsutil_test.py

Issue 809053002: gsutil: Use urllib2 instead of urllib. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Patch v3, update the tests Created 6 years 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 unified diff | Download patch
« no previous file with comments | « gsutil.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 unittest 10 import unittest
11 import hashlib 11 import hashlib
12 import zipfile 12 import zipfile
13 import shutil 13 import shutil
14 import sys 14 import sys
15 import base64 15 import base64
16 import tempfile 16 import tempfile
17 import json 17 import json
18 import os 18 import os
19 import urllib 19 import urllib2
20 20
21 21
22 # Add depot_tools to path 22 # Add depot_tools to path
23 THIS_DIR = os.path.dirname(os.path.abspath(__file__)) 23 THIS_DIR = os.path.dirname(os.path.abspath(__file__))
24 DEPOT_TOOLS_DIR = os.path.dirname(THIS_DIR) 24 DEPOT_TOOLS_DIR = os.path.dirname(THIS_DIR)
25 sys.path.append(DEPOT_TOOLS_DIR) 25 sys.path.append(DEPOT_TOOLS_DIR)
26 26
27 import gsutil 27 import gsutil
28 28
29 29
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 raise TestError(message) 64 raise TestError(message)
65 if isinstance(exp_returns, Exception): 65 if isinstance(exp_returns, Exception):
66 raise exp_returns 66 raise exp_returns
67 return exp_returns 67 return exp_returns
68 68
69 69
70 class GsutilUnitTests(unittest.TestCase): 70 class GsutilUnitTests(unittest.TestCase):
71 def setUp(self): 71 def setUp(self):
72 self.fake = FakeCall() 72 self.fake = FakeCall()
73 self.tempdir = tempfile.mkdtemp() 73 self.tempdir = tempfile.mkdtemp()
74 self.old_urlopen = getattr(urllib, 'urlopen') 74 self.old_urlopen = getattr(urllib2, 'urlopen')
75 self.old_call = getattr(gsutil, 'call') 75 self.old_call = getattr(gsutil, 'call')
76 setattr(urllib, 'urlopen', self.fake) 76 setattr(urllib2, 'urlopen', self.fake)
77 setattr(gsutil, 'call', self.fake) 77 setattr(gsutil, 'call', self.fake)
78 78
79 def tearDown(self): 79 def tearDown(self):
80 self.assertEqual(self.fake.expectations, []) 80 self.assertEqual(self.fake.expectations, [])
81 shutil.rmtree(self.tempdir) 81 shutil.rmtree(self.tempdir)
82 setattr(urllib, 'urlopen', self.old_urlopen) 82 setattr(urllib2, 'urlopen', self.old_urlopen)
83 setattr(gsutil, 'call', self.old_call) 83 setattr(gsutil, 'call', self.old_call)
84 84
85 def test_download_gsutil(self): 85 def test_download_gsutil(self):
86 version = '4.2' 86 version = '4.2'
87 filename = 'gsutil_%s.zip' % version 87 filename = 'gsutil_%s.zip' % version
88 full_filename = os.path.join(self.tempdir, filename) 88 full_filename = os.path.join(self.tempdir, filename)
89 fake_file = 'This is gsutil.zip' 89 fake_file = 'This is gsutil.zip'
90 fake_file2 = 'This is other gsutil.zip' 90 fake_file2 = 'This is other gsutil.zip'
91 url = '%s%s' % (gsutil.GSUTIL_URL, filename) 91 url = '%s%s' % (gsutil.GSUTIL_URL, filename)
92 self.fake.add_expectation(url, _returns=Buffer(fake_file)) 92 self.fake.add_expectation(url, _returns=Buffer(fake_file))
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 self.fake.add_expectation( 162 self.fake.add_expectation(
163 [sys.executable, gsutil_bin, 'version'], verbose=False, _returns=True) 163 [sys.executable, gsutil_bin, 'version'], verbose=False, _returns=True)
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), gsutil_bin)
169 169
170 if __name__ == '__main__': 170 if __name__ == '__main__':
171 unittest.main() 171 unittest.main()
OLDNEW
« 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