Clean up a couple hand-rolled mocks.

Change-Id: I6582985990e8b5e3a0c65bce5d3bb1e39d58dfb9
This commit is contained in:
Samuel Merritt 2017-10-20 15:31:07 -07:00
parent 1da1bfb381
commit 9c97c80b26
3 changed files with 8 additions and 24 deletions

View File

@ -212,18 +212,10 @@ class TestRing(TestRingBase):
self.assertEqual(self.ring.reload_time, self.intended_reload_time) self.assertEqual(self.ring.reload_time, self.intended_reload_time)
self.assertEqual(self.ring.serialized_path, self.testgz) self.assertEqual(self.ring.serialized_path, self.testgz)
# test invalid endcap # test invalid endcap
_orig_hash_path_suffix = utils.HASH_PATH_SUFFIX with mock.patch.object(utils, 'HASH_PATH_SUFFIX', ''), \
_orig_hash_path_prefix = utils.HASH_PATH_PREFIX mock.patch.object(utils, 'HASH_PATH_PREFIX', ''), \
_orig_swift_conf_file = utils.SWIFT_CONF_FILE mock.patch.object(utils, 'SWIFT_CONF_FILE', ''):
try:
utils.HASH_PATH_SUFFIX = ''
utils.HASH_PATH_PREFIX = ''
utils.SWIFT_CONF_FILE = ''
self.assertRaises(SystemExit, ring.Ring, self.testdir, 'whatever') self.assertRaises(SystemExit, ring.Ring, self.testdir, 'whatever')
finally:
utils.HASH_PATH_SUFFIX = _orig_hash_path_suffix
utils.HASH_PATH_PREFIX = _orig_hash_path_prefix
utils.SWIFT_CONF_FILE = _orig_swift_conf_file
def test_has_changed(self): def test_has_changed(self):
self.assertFalse(self.ring.has_changed()) self.assertFalse(self.ring.has_changed())

View File

@ -98,9 +98,8 @@ class TestBufferedHTTP(unittest.TestCase):
raise Exception(err) raise Exception(err)
def test_nonstr_header_values(self): def test_nonstr_header_values(self):
origHTTPSConnection = bufferedhttp.HTTPSConnection with mock.patch('swift.common.bufferedhttp.HTTPSConnection',
bufferedhttp.HTTPSConnection = MockHTTPSConnection MockHTTPSConnection):
try:
bufferedhttp.http_connect( bufferedhttp.http_connect(
'127.0.0.1', 8080, 'sda', 1, 'GET', '/', '127.0.0.1', 8080, 'sda', 1, 'GET', '/',
headers={'x-one': '1', 'x-two': 2, 'x-three': 3.0, headers={'x-one': '1', 'x-two': 2, 'x-three': 3.0,
@ -109,8 +108,6 @@ class TestBufferedHTTP(unittest.TestCase):
'127.0.0.1', 8080, 'GET', '/', '127.0.0.1', 8080, 'GET', '/',
headers={'x-one': '1', 'x-two': 2, 'x-three': 3.0, headers={'x-one': '1', 'x-two': 2, 'x-three': 3.0,
'x-four': {'crazy': 'value'}}, ssl=True) 'x-four': {'crazy': 'value'}}, ssl=True)
finally:
bufferedhttp.HTTPSConnection = origHTTPSConnection
def test_unicode_values(self): def test_unicode_values(self):
with mock.patch('swift.common.bufferedhttp.HTTPSConnection', with mock.patch('swift.common.bufferedhttp.HTTPSConnection',

View File

@ -1503,8 +1503,8 @@ class TestUtils(unittest.TestCase):
syslog_handler_catcher.LOG_LOCAL0 = orig_sysloghandler.LOG_LOCAL0 syslog_handler_catcher.LOG_LOCAL0 = orig_sysloghandler.LOG_LOCAL0
syslog_handler_catcher.LOG_LOCAL3 = orig_sysloghandler.LOG_LOCAL3 syslog_handler_catcher.LOG_LOCAL3 = orig_sysloghandler.LOG_LOCAL3
try: with mock.patch.object(utils, 'ThreadSafeSysLogHandler',
utils.ThreadSafeSysLogHandler = syslog_handler_catcher syslog_handler_catcher):
utils.get_logger({ utils.get_logger({
'log_facility': 'LOG_LOCAL3', 'log_facility': 'LOG_LOCAL3',
}, 'server', log_route='server') }, 'server', log_route='server')
@ -1553,8 +1553,6 @@ class TestUtils(unittest.TestCase):
((), {'address': ('syslog.funtimes.com', 2123), ((), {'address': ('syslog.funtimes.com', 2123),
'facility': orig_sysloghandler.LOG_LOCAL0})], 'facility': orig_sysloghandler.LOG_LOCAL0})],
syslog_handler_args) syslog_handler_args)
finally:
utils.ThreadSafeSysLogHandler = orig_sysloghandler
@reset_logger_state @reset_logger_state
def test_clean_logger_exception(self): def test_clean_logger_exception(self):
@ -2977,8 +2975,7 @@ cluster_dfw1 = http://dfw1.host/v1/
self.last_call[-1] = self.last_call[-1].value self.last_call[-1] = self.last_call[-1].value
return 0 return 0
orig__sys_fallocate = utils._sys_fallocate with patch.object(utils, '_sys_fallocate', FallocateWrapper()):
try:
utils._sys_fallocate = FallocateWrapper() utils._sys_fallocate = FallocateWrapper()
# Ensure fallocate calls _sys_fallocate even with 0 bytes # Ensure fallocate calls _sys_fallocate even with 0 bytes
utils._sys_fallocate.last_call = None utils._sys_fallocate.last_call = None
@ -3000,8 +2997,6 @@ cluster_dfw1 = http://dfw1.host/v1/
utils.fallocate(1234, 10 * 1024 * 1024 * 1024) utils.fallocate(1234, 10 * 1024 * 1024 * 1024)
self.assertEqual(utils._sys_fallocate.last_call, self.assertEqual(utils._sys_fallocate.last_call,
[1234, 1, 0, 10 * 1024 * 1024 * 1024]) [1234, 1, 0, 10 * 1024 * 1024 * 1024])
finally:
utils._sys_fallocate = orig__sys_fallocate
def test_generate_trans_id(self): def test_generate_trans_id(self):
fake_time = 1366428370.5163341 fake_time = 1366428370.5163341