Merge "Fix exception raising in FakeConn"
This commit is contained in:
commit
f43050d242
@ -606,7 +606,7 @@ def fake_http_connect(*code_iter, **kwargs):
|
||||
def __init__(self, status, etag=None, body='', timestamp='1',
|
||||
headers=None):
|
||||
# connect exception
|
||||
if isinstance(status, Exception):
|
||||
if isinstance(status, (Exception, Timeout)):
|
||||
raise status
|
||||
if isinstance(status, tuple):
|
||||
self.expect_status, self.status = status
|
||||
@ -641,11 +641,11 @@ def fake_http_connect(*code_iter, **kwargs):
|
||||
self._next_sleep = None
|
||||
|
||||
def getresponse(self):
|
||||
if isinstance(self.status, Exception):
|
||||
if isinstance(self.status, (Exception, Timeout)):
|
||||
raise self.status
|
||||
exc = kwargs.get('raise_exc')
|
||||
if exc:
|
||||
if isinstance(exc, Exception):
|
||||
if isinstance(exc, (Exception, Timeout)):
|
||||
raise exc
|
||||
raise Exception('test')
|
||||
if kwargs.get('raise_timeout_exc'):
|
||||
@ -653,7 +653,7 @@ def fake_http_connect(*code_iter, **kwargs):
|
||||
return self
|
||||
|
||||
def getexpect(self):
|
||||
if isinstance(self.expect_status, Exception):
|
||||
if isinstance(self.expect_status, (Exception, Timeout)):
|
||||
raise self.expect_status
|
||||
return FakeConn(self.expect_status)
|
||||
|
||||
|
@ -1601,17 +1601,17 @@ class TestObjectController(unittest.TestCase):
|
||||
self.assertEquals(res.status[:len(expected)], expected)
|
||||
test_status_map((200, 200, 201, 201, -1), 201) # connect exc
|
||||
# connect errors
|
||||
test_status_map((200, 200, 201, 201, Timeout()), 201)
|
||||
test_status_map((200, 200, Timeout(), 201, 201, ), 201)
|
||||
test_status_map((200, 200, 201, 201, Exception()), 201)
|
||||
# expect errors
|
||||
test_status_map((200, 200, 201, 201, (Timeout(), None)), 201)
|
||||
test_status_map((200, 200, 201, 201, (Exception(), None)), 201)
|
||||
test_status_map((200, 200, (Timeout(), None), 201, 201), 201)
|
||||
test_status_map((200, 200, (Exception(), None), 201, 201), 201)
|
||||
# response errors
|
||||
test_status_map((200, 200, 201, 201, (100, Timeout())), 201)
|
||||
test_status_map((200, 200, 201, 201, (100, Exception())), 201)
|
||||
test_status_map((200, 200, 201, 201, 507), 201) # error limited
|
||||
test_status_map((200, 200, 201, -1, -1), 503)
|
||||
test_status_map((200, 200, 503, 503, -1), 503)
|
||||
test_status_map((200, 200, (100, Timeout()), 201, 201), 201)
|
||||
test_status_map((200, 200, (100, Exception()), 201, 201), 201)
|
||||
test_status_map((200, 200, 507, 201, 201), 201) # error limited
|
||||
test_status_map((200, 200, -1, 201, -1), 503)
|
||||
test_status_map((200, 200, 503, -1, 503), 503)
|
||||
|
||||
def test_PUT_send_exceptions(self):
|
||||
with save_globals():
|
||||
|
Loading…
x
Reference in New Issue
Block a user