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

Side by Side Diff: third_party/gsutil/gslib/tests/testcase/unit_testcase.py

Issue 1380943003: Roll version of gsutil to 4.15. (Closed) Base URL: https://github.com/catapult-project/catapult.git@master
Patch Set: rebase Created 5 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
OLDNEW
1 # -*- coding: utf-8 -*- 1 # -*- coding: utf-8 -*-
2 # Copyright 2013 Google Inc. All Rights Reserved. 2 # Copyright 2013 Google Inc. All Rights Reserved.
3 # 3 #
4 # Licensed under the Apache License, Version 2.0 (the "License"); 4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License. 5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at 6 # You may obtain a copy of the License at
7 # 7 #
8 # http://www.apache.org/licenses/LICENSE-2.0 8 # http://www.apache.org/licenses/LICENSE-2.0
9 # 9 #
10 # Unless required by applicable law or agreed to in writing, software 10 # Unless required by applicable law or agreed to in writing, software
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 if self.is_debugging and stderr: 126 if self.is_debugging and stderr:
127 sys.stderr.write('==== stderr %s ====\n' % self.id()) 127 sys.stderr.write('==== stderr %s ====\n' % self.id())
128 sys.stderr.write(stderr) 128 sys.stderr.write(stderr)
129 sys.stderr.write('==== end stderr ====\n') 129 sys.stderr.write('==== end stderr ====\n')
130 if self.is_debugging and log_output: 130 if self.is_debugging and log_output:
131 sys.stderr.write('==== log output %s ====\n' % self.id()) 131 sys.stderr.write('==== log output %s ====\n' % self.id())
132 sys.stderr.write(log_output) 132 sys.stderr.write(log_output)
133 sys.stderr.write('==== end log output ====\n') 133 sys.stderr.write('==== end log output ====\n')
134 134
135 def RunCommand(self, command_name, args=None, headers=None, debug=0, 135 def RunCommand(self, command_name, args=None, headers=None, debug=0,
136 test_method=None, return_stdout=False, return_stderr=False, 136 return_stdout=False, return_stderr=False,
137 return_log_handler=False, cwd=None): 137 return_log_handler=False, cwd=None):
138 """Method for calling gslib.command_runner.CommandRunner. 138 """Method for calling gslib.command_runner.CommandRunner.
139 139
140 Passes parallel_operations=False for all tests, optionally saving/returning 140 Passes parallel_operations=False for all tests, optionally saving/returning
141 stdout output. We run all tests multi-threaded, to exercise those more 141 stdout output. We run all tests multi-threaded, to exercise those more
142 complicated code paths. 142 complicated code paths.
143 TODO: Change to run with parallel_operations=True for all tests. At 143 TODO: Change to run with parallel_operations=True for all tests. At
144 present when you do this it causes many test failures. 144 present when you do this it causes many test failures.
145 145
146 Args: 146 Args:
147 command_name: The name of the command being run. 147 command_name: The name of the command being run.
148 args: Command-line args (arg0 = actual arg, not command name ala bash). 148 args: Command-line args (arg0 = actual arg, not command name ala bash).
149 headers: Dictionary containing optional HTTP headers to pass to boto. 149 headers: Dictionary containing optional HTTP headers to pass to boto.
150 debug: Debug level to pass in to boto connection (range 0..3). 150 debug: Debug level to pass in to boto connection (range 0..3).
151 test_method: Optional general purpose method for testing purposes.
152 Application and semantics of this method will vary by
153 command and test type.
154 return_stdout: If True, will save and return stdout produced by command. 151 return_stdout: If True, will save and return stdout produced by command.
155 return_stderr: If True, will save and return stderr produced by command. 152 return_stderr: If True, will save and return stderr produced by command.
156 return_log_handler: If True, will return a MockLoggingHandler instance 153 return_log_handler: If True, will return a MockLoggingHandler instance
157 that was attached to the command's logger while running. 154 that was attached to the command's logger while running.
158 cwd: The working directory that should be switched to before running the 155 cwd: The working directory that should be switched to before running the
159 command. The working directory will be reset back to its original 156 command. The working directory will be reset back to its original
160 value after running the command. If not specified, the working 157 value after running the command. If not specified, the working
161 directory is left unchanged. 158 directory is left unchanged.
162 159
163 Returns: 160 Returns:
(...skipping 22 matching lines...) Expand all
186 sys.stdout.truncate() 183 sys.stdout.truncate()
187 sys.stderr.truncate() 184 sys.stderr.truncate()
188 185
189 mock_log_handler = MockLoggingHandler() 186 mock_log_handler = MockLoggingHandler()
190 logging.getLogger(command_name).addHandler(mock_log_handler) 187 logging.getLogger(command_name).addHandler(mock_log_handler)
191 188
192 try: 189 try:
193 with WorkingDirectory(cwd): 190 with WorkingDirectory(cwd):
194 self.command_runner.RunNamedCommand( 191 self.command_runner.RunNamedCommand(
195 command_name, args=args, headers=headers, debug=debug, 192 command_name, args=args, headers=headers, debug=debug,
196 parallel_operations=False, test_method=test_method, 193 parallel_operations=False, do_shutdown=False)
197 do_shutdown=False)
198 finally: 194 finally:
199 sys.stdout.seek(0) 195 sys.stdout.seek(0)
200 stdout = sys.stdout.read() 196 stdout = sys.stdout.read()
201 sys.stderr.seek(0) 197 sys.stderr.seek(0)
202 stderr = sys.stderr.read() 198 stderr = sys.stderr.read()
203 logging.getLogger(command_name).removeHandler(mock_log_handler) 199 logging.getLogger(command_name).removeHandler(mock_log_handler)
204 mock_log_handler.close() 200 mock_log_handler.close()
205 201
206 log_output = '\n'.join( 202 log_output = '\n'.join(
207 '%s:\n ' % level + '\n '.join(records) 203 '%s:\n ' % level + '\n '.join(records)
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 355
360 Returns: 356 Returns:
361 A StorageUri for the created object. 357 A StorageUri for the created object.
362 """ 358 """
363 bucket_uri = bucket_uri or self.CreateBucket() 359 bucket_uri = bucket_uri or self.CreateBucket()
364 object_name = object_name or self.MakeTempName('obj') 360 object_name = object_name or self.MakeTempName('obj')
365 key_uri = bucket_uri.clone_replace_name(object_name) 361 key_uri = bucket_uri.clone_replace_name(object_name)
366 if contents is not None: 362 if contents is not None:
367 key_uri.set_contents_from_string(contents) 363 key_uri.set_contents_from_string(contents)
368 return key_uri 364 return key_uri
OLDNEW
« no previous file with comments | « third_party/gsutil/gslib/tests/testcase/integration_testcase.py ('k') | third_party/gsutil/gslib/tests/util.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698