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

Side by Side Diff: boto/tests/cb_test_harnass.py

Issue 8386013: Merging in latest boto. (Closed) Base URL: svn://svn.chromium.org/boto
Patch Set: Redoing vendor drop by deleting and then merging. Created 9 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « boto/tests/__init__.py ('k') | boto/tests/devpay_s3.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # Copyright 2010 Google Inc.
2 #
3 # Permission is hereby granted, free of charge, to any person obtaining a
4 # copy of this software and associated documentation files (the
5 # "Software"), to deal in the Software without restriction, including
6 # without limitation the rights to use, copy, modify, merge, publish, dis-
7 # tribute, sublicense, and/or sell copies of the Software, and to permit
8 # persons to whom the Software is furnished to do so, subject to the fol-
9 # lowing conditions:
10 #
11 # The above copyright notice and this permission notice shall be included
12 # in all copies or substantial portions of the Software.
13 #
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
16 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
17 # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20 # IN THE SOFTWARE.
21
22 """
23 Test harnass that allows us to raise exceptions, change file content,
24 and record the byte transfer callback sequence, to test various resumable
25 upload and download cases. The 'call' method of this harnass can be passed
26 as the 'cb' parameter to boto.s3.Key.send_file() and boto.s3.Key.get_file(),
27 allowing testing of various file upload/download conditions.
28 """
29
30 import socket
31
32
33 class CallbackTestHarnass(object):
34
35 def __init__(self, fail_after_n_bytes=0, num_times_to_fail=1,
36 exception=socket.error('mock socket error', 0),
37 fp_to_change=None, fp_change_pos=None):
38 self.fail_after_n_bytes = fail_after_n_bytes
39 self.num_times_to_fail = num_times_to_fail
40 self.exception = exception
41 # If fp_to_change and fp_change_pos are specified, 3 bytes will be
42 # written at that position just before the first exception is thrown.
43 self.fp_to_change = fp_to_change
44 self.fp_change_pos = fp_change_pos
45 self.num_failures = 0
46 self.transferred_seq_before_first_failure = []
47 self.transferred_seq_after_first_failure = []
48
49 def call(self, total_bytes_transferred, unused_total_size):
50 """
51 To use this test harnass, pass the 'call' method of the instantiated
52 object as the cb param to the set_contents_from_file() or
53 get_contents_to_file() call.
54 """
55 # Record transfer sequence to allow verification.
56 if self.num_failures:
57 self.transferred_seq_after_first_failure.append(
58 total_bytes_transferred)
59 else:
60 self.transferred_seq_before_first_failure.append(
61 total_bytes_transferred)
62 if (total_bytes_transferred >= self.fail_after_n_bytes and
63 self.num_failures < self.num_times_to_fail):
64 self.num_failures += 1
65 if self.fp_to_change and self.fp_change_pos is not None:
66 cur_pos = self.fp_to_change.tell()
67 self.fp_to_change.seek(self.fp_change_pos)
68 self.fp_to_change.write('abc')
69 self.fp_to_change.seek(cur_pos)
70 self.called = True
71 raise self.exception
OLDNEW
« no previous file with comments | « boto/tests/__init__.py ('k') | boto/tests/devpay_s3.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698