lint: Consistently use assertIsInstance
This has been available since py32 and was backported to py27; there is no point in us continuing to carry the old idiom forward. Change-Id: I21f64b8b2970e2dd5f56836f7f513e7895a5dc88
This commit is contained in:
parent
76ca11773e
commit
ce9e56a6d1
@ -40,7 +40,7 @@ class TestS3ApiBucket(S3ApiBaseBoto3):
|
||||
self.assertEqual(len(resp_objects), len(req_objects))
|
||||
for i, obj in enumerate(resp_objects):
|
||||
self.assertEqual(obj['Key'], req_objects[i])
|
||||
self.assertEqual(type(obj['LastModified']), datetime.datetime)
|
||||
self.assertIsInstance(obj['LastModified'], datetime.datetime)
|
||||
self.assertIn('ETag', obj)
|
||||
self.assertIn('Size', obj)
|
||||
self.assertEqual(obj['StorageClass'], 'STANDARD')
|
||||
|
@ -58,7 +58,7 @@ class TestS3ApiEtree(unittest.TestCase):
|
||||
elem = etree.Element('Test')
|
||||
sub = etree.SubElement(elem, 'FOO')
|
||||
sub.text = '\xef\xbc\xa1'
|
||||
self.assertTrue(isinstance(sub.text, str))
|
||||
self.assertIsInstance(sub.text, str)
|
||||
xml_string = etree.tostring(elem)
|
||||
self.assertIsInstance(xml_string, bytes)
|
||||
|
||||
|
@ -228,7 +228,7 @@ class TestS3ApiSubresource(unittest.TestCase):
|
||||
json.dumps(access_control_policy)}
|
||||
acl = decode_acl('container', headers, self.allow_no_owner)
|
||||
|
||||
self.assertEqual(type(acl), ACL)
|
||||
self.assertIsInstance(acl, ACL)
|
||||
self.assertEqual(acl.owner.id, 'test:tester')
|
||||
self.assertEqual(len(acl.grants), 1)
|
||||
self.assertEqual(str(acl.grants[0].grantee), 'test:tester')
|
||||
@ -243,7 +243,7 @@ class TestS3ApiSubresource(unittest.TestCase):
|
||||
json.dumps(access_control_policy)}
|
||||
acl = decode_acl('object', headers, self.allow_no_owner)
|
||||
|
||||
self.assertEqual(type(acl), ACL)
|
||||
self.assertIsInstance(acl, ACL)
|
||||
self.assertEqual(acl.owner.id, 'test:tester')
|
||||
self.assertEqual(len(acl.grants), 1)
|
||||
self.assertEqual(str(acl.grants[0].grantee), 'test:tester')
|
||||
@ -253,14 +253,14 @@ class TestS3ApiSubresource(unittest.TestCase):
|
||||
headers = {}
|
||||
acl = decode_acl('container', headers, self.allow_no_owner)
|
||||
|
||||
self.assertEqual(type(acl), ACL)
|
||||
self.assertIsInstance(acl, ACL)
|
||||
self.assertIsNone(acl.owner.id)
|
||||
self.assertEqual(len(acl.grants), 0)
|
||||
|
||||
def test_decode_acl_empty_list(self):
|
||||
headers = {sysmeta_header('container', 'acl'): '[]'}
|
||||
acl = decode_acl('container', headers, self.allow_no_owner)
|
||||
self.assertEqual(type(acl), ACL)
|
||||
self.assertIsInstance(acl, ACL)
|
||||
self.assertIsNone(acl.owner.id)
|
||||
self.assertEqual(len(acl.grants), 0)
|
||||
|
||||
@ -333,8 +333,7 @@ class TestS3ApiSubresource(unittest.TestCase):
|
||||
for (expected_permission, expected_grantee), \
|
||||
(permission, grantee) in assertions:
|
||||
self.assertEqual(expected_permission, permission)
|
||||
self.assertTrue(
|
||||
isinstance(grantee, expected_grantee.__class__))
|
||||
self.assertIsInstance(grantee, expected_grantee.__class__)
|
||||
if isinstance(grantee, User):
|
||||
self.assertEqual(expected_grantee.id, grantee.id)
|
||||
self.assertEqual(expected_grantee.display_name,
|
||||
|
@ -46,7 +46,7 @@ class TestCacheMiddleware(unittest.TestCase):
|
||||
req = Request.blank('/something', environ={'REQUEST_METHOD': 'GET'})
|
||||
resp = self.app(req.environ, start_response)
|
||||
self.assertTrue('swift.cache' in resp)
|
||||
self.assertTrue(isinstance(resp['swift.cache'], MemcacheRing))
|
||||
self.assertIsInstance(resp['swift.cache'], MemcacheRing)
|
||||
|
||||
def test_filter_factory(self):
|
||||
factory = memcache.filter_factory({'max_connections': '3'},
|
||||
|
@ -59,7 +59,7 @@ class TestDaemon(unittest.TestCase):
|
||||
def test_create(self):
|
||||
d = daemon.Daemon({})
|
||||
self.assertEqual(d.conf, {})
|
||||
self.assertTrue(isinstance(d.logger, utils.LogAdapter))
|
||||
self.assertIsInstance(d.logger, utils.LogAdapter)
|
||||
|
||||
def test_stubs(self):
|
||||
d = daemon.Daemon({})
|
||||
|
@ -1514,11 +1514,11 @@ class TestDBReplicator(unittest.TestCase):
|
||||
mount_check=False)
|
||||
with unit.mock_check_drive(isdir=True):
|
||||
resp = rpc.complete_rsync(drive, db_file, args)
|
||||
self.assertTrue(isinstance(resp, HTTPException))
|
||||
self.assertIsInstance(resp, HTTPException)
|
||||
self.assertEqual(404, resp.status_int)
|
||||
with unit.mock_check_drive(isdir=True):
|
||||
resp = rpc.complete_rsync(drive, 'new_db_file', args)
|
||||
self.assertTrue(isinstance(resp, HTTPException))
|
||||
self.assertIsInstance(resp, HTTPException)
|
||||
self.assertEqual(404, resp.status_int)
|
||||
|
||||
def test_complete_rsync(self):
|
||||
|
@ -27,7 +27,7 @@ class TestExceptions(unittest.TestCase):
|
||||
|
||||
def test_replication_lock_timeout(self):
|
||||
with exceptions.ReplicationLockTimeout(15, 'test') as exc:
|
||||
self.assertTrue(isinstance(exc, exceptions.MessageTimeout))
|
||||
self.assertIsInstance(exc, exceptions.MessageTimeout)
|
||||
|
||||
def test_client_exception(self):
|
||||
strerror = 'test: HTTP://random:888/randompath?foo=1 666 reason: ' \
|
||||
|
@ -2036,7 +2036,7 @@ class TestSimpleClient(unittest.TestCase):
|
||||
self.assertEqual(1, len(args))
|
||||
self.assertEqual(1, len(kwargs))
|
||||
self.assertEqual(0.1, kwargs['timeout'])
|
||||
self.assertTrue(isinstance(args[0], urllib2.Request))
|
||||
self.assertIsInstance(args[0], urllib2.Request)
|
||||
self.assertEqual(proxy_host, args[0].host)
|
||||
if six.PY2:
|
||||
self.assertEqual(scheme, args[0].type)
|
||||
@ -2061,7 +2061,7 @@ class TestSimpleClient(unittest.TestCase):
|
||||
self.assertEqual(1, len(args))
|
||||
self.assertEqual(1, len(kwargs))
|
||||
self.assertEqual(0.1, kwargs['timeout'])
|
||||
self.assertTrue(isinstance(args[0], urllib2.Request))
|
||||
self.assertIsInstance(args[0], urllib2.Request)
|
||||
self.assertEqual(proxy_host, args[0].host)
|
||||
if six.PY2:
|
||||
self.assertEqual(scheme, args[0].type)
|
||||
|
@ -1660,7 +1660,7 @@ class TestManager(unittest.TestCase):
|
||||
m = manager.Manager(['test'])
|
||||
self.assertEqual(len(m.servers), 1)
|
||||
server = m.servers.pop()
|
||||
self.assertTrue(isinstance(server, manager.Server))
|
||||
self.assertIsInstance(server, manager.Server)
|
||||
self.assertEqual(server.server, 'test-server')
|
||||
# test multi-server and simple dedupe
|
||||
servers = ['object-replicator', 'object-auditor',
|
||||
|
@ -1140,7 +1140,7 @@ class TestStoragePolicies(unittest.TestCase):
|
||||
ring = policies.get_object_ring(int(policy), '/path/not/used')
|
||||
self.assertEqual(ring.ring_name, policy.ring_name)
|
||||
self.assertTrue(policy.object_ring)
|
||||
self.assertTrue(isinstance(policy.object_ring, NamedFakeRing))
|
||||
self.assertIsInstance(policy.object_ring, NamedFakeRing)
|
||||
|
||||
def blow_up(*args, **kwargs):
|
||||
raise Exception('kaboom!')
|
||||
|
@ -835,7 +835,7 @@ class TestRequest(unittest.TestCase):
|
||||
req = swob.Request.blank('/hi/there', body='hi')
|
||||
|
||||
req.if_unmodified_since = 0
|
||||
self.assertTrue(isinstance(req.if_unmodified_since, datetime.datetime))
|
||||
self.assertIsInstance(req.if_unmodified_since, datetime.datetime)
|
||||
if_unmodified_since = req.if_unmodified_since
|
||||
req.if_unmodified_since = if_unmodified_since
|
||||
self.assertEqual(if_unmodified_since, req.if_unmodified_since)
|
||||
|
@ -2024,10 +2024,8 @@ log_name = %(yarr)s'''
|
||||
utils.capture_stdio(logger)
|
||||
self.assertTrue(utils.sys.excepthook is not None)
|
||||
self.assertEqual(utils.os.closed_fds, utils.sys.stdio_fds)
|
||||
self.assertTrue(
|
||||
isinstance(utils.sys.stdout, utils.LoggerFileObject))
|
||||
self.assertTrue(
|
||||
isinstance(utils.sys.stderr, utils.LoggerFileObject))
|
||||
self.assertIsInstance(utils.sys.stdout, utils.LoggerFileObject)
|
||||
self.assertIsInstance(utils.sys.stderr, utils.LoggerFileObject)
|
||||
|
||||
# reset; test same args, but exc when trying to close stdio
|
||||
utils.os = MockOs(raise_funcs=('dup2',))
|
||||
@ -2037,10 +2035,8 @@ log_name = %(yarr)s'''
|
||||
utils.capture_stdio(logger)
|
||||
self.assertTrue(utils.sys.excepthook is not None)
|
||||
self.assertEqual(utils.os.closed_fds, [])
|
||||
self.assertTrue(
|
||||
isinstance(utils.sys.stdout, utils.LoggerFileObject))
|
||||
self.assertTrue(
|
||||
isinstance(utils.sys.stderr, utils.LoggerFileObject))
|
||||
self.assertIsInstance(utils.sys.stdout, utils.LoggerFileObject)
|
||||
self.assertIsInstance(utils.sys.stderr, utils.LoggerFileObject)
|
||||
|
||||
# reset; test some other args
|
||||
utils.os = MockOs()
|
||||
@ -3480,7 +3476,7 @@ cluster_dfw1 = http://dfw1.host/v1/
|
||||
utils.fsync_dir(tempdir)
|
||||
self.assertTrue(_mock_fsync.called)
|
||||
self.assertTrue(_mock_close.called)
|
||||
self.assertTrue(isinstance(_mock_fsync.call_args[0][0], int))
|
||||
self.assertIsInstance(_mock_fsync.call_args[0][0], int)
|
||||
self.assertEqual(_mock_fsync.call_args[0][0],
|
||||
_mock_close.call_args[0][0])
|
||||
|
||||
@ -4728,8 +4724,7 @@ class TestStatsdLogging(unittest.TestCase):
|
||||
logger = utils.get_logger({'log_statsd_host': 'some.host.com'},
|
||||
'some-name', log_route='some-route')
|
||||
# white-box construction validation
|
||||
self.assertTrue(isinstance(logger.logger.statsd_client,
|
||||
utils.StatsdClient))
|
||||
self.assertIsInstance(logger.logger.statsd_client, utils.StatsdClient)
|
||||
self.assertEqual(logger.logger.statsd_client._host, 'some.host.com')
|
||||
self.assertEqual(logger.logger.statsd_client._port, 8125)
|
||||
self.assertEqual(logger.logger.statsd_client._prefix, 'some-name.')
|
||||
|
@ -147,7 +147,6 @@ class TestWSGI(unittest.TestCase, ConfigAssertMixin):
|
||||
f.write(contents)
|
||||
app = wsgi.loadapp(conf_path)
|
||||
self.assertIsInstance(app, obj_server.ObjectController)
|
||||
self.assertTrue(isinstance(app, obj_server.ObjectController))
|
||||
# N.B. paste config loading from *file* is already case-sensitive,
|
||||
# so, CLIENT_TIMEOUT/client_timeout are unique options
|
||||
self.assertEqual(1, app.client_timeout)
|
||||
@ -239,7 +238,7 @@ class TestWSGI(unittest.TestCase, ConfigAssertMixin):
|
||||
client_timeout = 2
|
||||
"""
|
||||
app = wsgi.loadapp(wsgi.ConfigString(conf_body))
|
||||
self.assertTrue(isinstance(app, obj_server.ObjectController))
|
||||
self.assertIsInstance(app, obj_server.ObjectController)
|
||||
self.assertEqual(1, app.client_timeout)
|
||||
self.assertEqual(5, app.conn_timeout)
|
||||
|
||||
@ -433,8 +432,8 @@ class TestWSGI(unittest.TestCase, ConfigAssertMixin):
|
||||
conf_dir, 'proxy-server')
|
||||
# verify pipeline is catch_errors -> proxy-server
|
||||
expected = swift.common.middleware.catch_errors.CatchErrorMiddleware
|
||||
self.assertTrue(isinstance(app, expected))
|
||||
self.assertTrue(isinstance(app.app, swift.proxy.server.Application))
|
||||
self.assertIsInstance(app, expected)
|
||||
self.assertIsInstance(app.app, swift.proxy.server.Application)
|
||||
# config settings applied to app instance
|
||||
self.assertEqual(0.2, app.app.conn_timeout)
|
||||
# appconfig returns values from 'proxy-server' section
|
||||
@ -496,7 +495,7 @@ class TestWSGI(unittest.TestCase, ConfigAssertMixin):
|
||||
# test
|
||||
sock = wsgi.get_socket(conf)
|
||||
# assert
|
||||
self.assertTrue(isinstance(sock, MockSocket))
|
||||
self.assertIsInstance(sock, MockSocket)
|
||||
expected_socket_opts = {
|
||||
socket.SOL_SOCKET: {
|
||||
socket.SO_KEEPALIVE: 1,
|
||||
@ -634,9 +633,9 @@ class TestWSGI(unittest.TestCase, ConfigAssertMixin):
|
||||
args, kwargs = _wsgi.server.call_args
|
||||
server_sock, server_app, server_logger = args
|
||||
self.assertEqual(sock, server_sock)
|
||||
self.assertTrue(isinstance(server_app, swift.proxy.server.Application))
|
||||
self.assertIsInstance(server_app, swift.proxy.server.Application)
|
||||
self.assertEqual(20, server_app.client_timeout)
|
||||
self.assertTrue(isinstance(server_logger, wsgi.NullLogger))
|
||||
self.assertIsInstance(server_logger, wsgi.NullLogger)
|
||||
self.assertTrue('custom_pool' in kwargs)
|
||||
self.assertEqual(1000, kwargs['custom_pool'].size)
|
||||
self.assertEqual(30, kwargs['socket_timeout'])
|
||||
@ -685,9 +684,9 @@ class TestWSGI(unittest.TestCase, ConfigAssertMixin):
|
||||
args, kwargs = _wsgi.server.call_args
|
||||
server_sock, server_app, server_logger = args
|
||||
self.assertEqual(sock, server_sock)
|
||||
self.assertTrue(isinstance(server_app, swift.proxy.server.Application))
|
||||
self.assertIsInstance(server_app, swift.proxy.server.Application)
|
||||
self.assertEqual(2.5, server_app.client_timeout)
|
||||
self.assertTrue(isinstance(server_logger, wsgi.NullLogger))
|
||||
self.assertIsInstance(server_logger, wsgi.NullLogger)
|
||||
self.assertTrue('custom_pool' in kwargs)
|
||||
self.assertEqual(10, kwargs['custom_pool'].size)
|
||||
self.assertEqual(2.5, kwargs['socket_timeout'])
|
||||
@ -773,8 +772,8 @@ class TestWSGI(unittest.TestCase, ConfigAssertMixin):
|
||||
args, kwargs = _wsgi.server.call_args
|
||||
server_sock, server_app, server_logger = args
|
||||
self.assertEqual(sock, server_sock)
|
||||
self.assertTrue(isinstance(server_app, swift.proxy.server.Application))
|
||||
self.assertTrue(isinstance(server_logger, wsgi.NullLogger))
|
||||
self.assertIsInstance(server_app, swift.proxy.server.Application)
|
||||
self.assertIsInstance(server_logger, wsgi.NullLogger)
|
||||
self.assertTrue('custom_pool' in kwargs)
|
||||
self.assertEqual(30, kwargs['socket_timeout'])
|
||||
self.assertTrue('protocol' in kwargs)
|
||||
@ -823,7 +822,7 @@ class TestWSGI(unittest.TestCase, ConfigAssertMixin):
|
||||
args, kwargs = mock_server.call_args
|
||||
server_sock, server_app, server_logger = args
|
||||
self.assertEqual(sock, server_sock)
|
||||
self.assertTrue(isinstance(server_app, swift.proxy.server.Application))
|
||||
self.assertIsInstance(server_app, swift.proxy.server.Application)
|
||||
self.assertEqual(20, server_app.client_timeout)
|
||||
self.assertIsNone(server_logger)
|
||||
self.assertTrue('custom_pool' in kwargs)
|
||||
@ -1829,11 +1828,11 @@ class TestPipelineModification(unittest.TestCase):
|
||||
modify_func):
|
||||
app = wsgi.loadapp(conf_file, global_conf={})
|
||||
exp = swift.common.middleware.catch_errors.CatchErrorMiddleware
|
||||
self.assertTrue(isinstance(app, exp), app)
|
||||
self.assertIsInstance(app, exp)
|
||||
exp = swift.common.middleware.healthcheck.HealthCheckMiddleware
|
||||
self.assertTrue(isinstance(app.app, exp), app.app)
|
||||
self.assertIsInstance(app.app, exp)
|
||||
exp = swift.proxy.server.Application
|
||||
self.assertTrue(isinstance(app.app.app, exp), app.app.app)
|
||||
self.assertIsInstance(app.app.app, exp)
|
||||
# Everybody gets a reference to the final app, too
|
||||
self.assertIs(app.app.app, app._pipeline_final_app)
|
||||
self.assertIs(app.app.app, app._pipeline_request_logging_app)
|
||||
@ -1859,9 +1858,9 @@ class TestPipelineModification(unittest.TestCase):
|
||||
|
||||
# the pipeline was untouched
|
||||
exp = swift.common.middleware.healthcheck.HealthCheckMiddleware
|
||||
self.assertTrue(isinstance(app, exp), app)
|
||||
self.assertIsInstance(app, exp)
|
||||
exp = swift.proxy.server.Application
|
||||
self.assertTrue(isinstance(app.app, exp), app.app)
|
||||
self.assertIsInstance(app.app, exp)
|
||||
|
||||
def test_load_app_request_logging_app(self):
|
||||
config = """
|
||||
@ -2398,7 +2397,7 @@ class TestPipelineModification(unittest.TestCase):
|
||||
with open(conf_path, 'w') as f:
|
||||
f.write(dedent(conf_body))
|
||||
app = wsgi.loadapp(conf_path)
|
||||
self.assertTrue(isinstance(app, controller))
|
||||
self.assertIsInstance(app, controller)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -134,7 +134,7 @@ class TestContainerSync(unittest.TestCase):
|
||||
self.assertTrue(cs.container_ring is cring)
|
||||
self.assertTrue(mock_ic.called)
|
||||
conf_path, name, retry = mock_ic.call_args[0]
|
||||
self.assertTrue(isinstance(conf_path, ConfigString))
|
||||
self.assertIsInstance(conf_path, ConfigString)
|
||||
self.assertEqual(conf_path.contents.getvalue(),
|
||||
dedent(sync.ic_conf_body))
|
||||
self.assertLogMessage('warning', 'internal_client_conf_path')
|
||||
|
@ -1167,9 +1167,9 @@ class TestDiskFileRouter(unittest.TestCase):
|
||||
logger = debug_logger('test-' + self.__class__.__name__)
|
||||
df_router = diskfile.DiskFileRouter(conf, logger)
|
||||
manager_0 = df_router[POLICIES[0]]
|
||||
self.assertTrue(isinstance(manager_0, diskfile.DiskFileManager))
|
||||
self.assertIsInstance(manager_0, diskfile.DiskFileManager)
|
||||
manager_1 = df_router[POLICIES[1]]
|
||||
self.assertTrue(isinstance(manager_1, diskfile.ECDiskFileManager))
|
||||
self.assertIsInstance(manager_1, diskfile.ECDiskFileManager)
|
||||
|
||||
# The DiskFileRouter should not have to load the policy again
|
||||
with mock.patch('swift.common.storage_policy.BaseStoragePolicy.' +
|
||||
@ -1177,7 +1177,7 @@ class TestDiskFileRouter(unittest.TestCase):
|
||||
manager_3 = df_router[POLICIES[0]]
|
||||
mock_load.assert_not_called()
|
||||
self.assertIs(manager_3, manager_0)
|
||||
self.assertTrue(isinstance(manager_3, diskfile.DiskFileManager))
|
||||
self.assertIsInstance(manager_3, diskfile.DiskFileManager)
|
||||
|
||||
def test_invalid_policy_config(self):
|
||||
# verify that invalid policy diskfile configs are detected when the
|
||||
|
@ -1391,7 +1391,7 @@ class TestSender(BaseTest):
|
||||
args, _kwargs = self.sender.send_put.call_args
|
||||
connection, path, df = args
|
||||
self.assertEqual(path, '/a/c/o')
|
||||
self.assertTrue(isinstance(df, diskfile.DiskFile))
|
||||
self.assertIsInstance(df, diskfile.DiskFile)
|
||||
self.assertEqual(expected, df.get_metadata())
|
||||
# note that the put line isn't actually sent since we mock send_put;
|
||||
# send_put is tested separately.
|
||||
@ -1525,7 +1525,7 @@ class TestSender(BaseTest):
|
||||
args, _kwargs = self.sender.send_put.call_args
|
||||
connection, path, df = args
|
||||
self.assertEqual(path, '/a/c/o')
|
||||
self.assertTrue(isinstance(df, diskfile.DiskFile))
|
||||
self.assertIsInstance(df, diskfile.DiskFile)
|
||||
self.assertEqual(expected, df.get_metadata())
|
||||
self.assertEqual(os.path.join(self.tx_testdir, 'dev/objects/9/',
|
||||
object_hash[-3:], object_hash),
|
||||
|
3
tox.ini
3
tox.ini
@ -146,7 +146,6 @@ commands = bandit -c bandit.yaml -r swift -n 5
|
||||
# it's not a bug that we aren't using all of hacking, ignore:
|
||||
# H101: Use TODO(NAME)
|
||||
# H202: assertRaises Exception too broad
|
||||
# H211/H212: Use assert{Is,IsNot}instance
|
||||
# H214: Use assertIn/NotIn ...
|
||||
# H216: The unittest.mock module should be used rather than ...
|
||||
# H301: one import per line
|
||||
@ -162,7 +161,7 @@ commands = bandit -c bandit.yaml -r swift -n 5
|
||||
# Swift team needs to decide if they want to enable either of these:
|
||||
# W503: line break before binary operator
|
||||
# W504: line break after binary operator
|
||||
ignore = H101,H202,H211,H212,H214,H216,H301,H306,H404,H405,H501,W503,W504,E402,E731,E741
|
||||
ignore = H101,H202,H214,H216,H301,H306,H404,H405,H501,W503,W504,E402,E731,E741
|
||||
exclude = .venv,.tox,dist,*egg
|
||||
filename = *.py,bin/*
|
||||
show-source = True
|
||||
|
Loading…
Reference in New Issue
Block a user