Fix using filter() to meet python2,3

As mentioned in link[1], if we need filter on python3,
Raplace filter(lambda obj: test(obj), data) with:
[obj for obj in data if test(obj)].

[1] https://wiki.openstack.org/wiki/Python3

Change-Id: Ia1ea2ec89e4beb957a4cb358b0d0cef970f23e0a
This commit is contained in:
Luong Anh Tuan 2016-09-12 15:49:38 +07:00
parent dd512a3207
commit 19a684dded
2 changed files with 7 additions and 7 deletions

View File

@ -795,8 +795,8 @@ class TestContainerBroker(unittest.TestCase):
if isinstance(self, ContainerBrokerMigrationMixin): if isinstance(self, ContainerBrokerMigrationMixin):
real_storage_policy_index = \ real_storage_policy_index = \
broker.get_info()['storage_policy_index'] broker.get_info()['storage_policy_index']
policy = filter(lambda p: p.idx == real_storage_policy_index, policy = [p for p in POLICIES
POLICIES)[0] if p.idx == real_storage_policy_index][0]
broker.put_object('correct_o', next(ts), 123, 'text/plain', broker.put_object('correct_o', next(ts), 123, 'text/plain',
'5af83e3196bf99f440f31f2e1a6c9afe', '5af83e3196bf99f440f31f2e1a6c9afe',
storage_policy_index=policy.idx) storage_policy_index=policy.idx)
@ -823,8 +823,8 @@ class TestContainerBroker(unittest.TestCase):
if isinstance(self, ContainerBrokerMigrationMixin): if isinstance(self, ContainerBrokerMigrationMixin):
real_storage_policy_index = \ real_storage_policy_index = \
broker.get_info()['storage_policy_index'] broker.get_info()['storage_policy_index']
policy = filter(lambda p: p.idx == real_storage_policy_index, policy = [p for p in POLICIES
POLICIES)[0] if p.idx == real_storage_policy_index][0]
broker.put_object('correct_o', next(ts), 123, 'text/plain', broker.put_object('correct_o', next(ts), 123, 'text/plain',
'5af83e3196bf99f440f31f2e1a6c9afe', '5af83e3196bf99f440f31f2e1a6c9afe',
storage_policy_index=policy.idx) storage_policy_index=policy.idx)
@ -847,8 +847,8 @@ class TestContainerBroker(unittest.TestCase):
if isinstance(self, ContainerBrokerMigrationMixin): if isinstance(self, ContainerBrokerMigrationMixin):
real_storage_policy_index = \ real_storage_policy_index = \
broker.get_info()['storage_policy_index'] broker.get_info()['storage_policy_index']
policy = filter(lambda p: p.idx == real_storage_policy_index, policy = [p for p in POLICIES
POLICIES)[0] if p.idx == real_storage_policy_index][0]
policy_stats = broker.get_policy_stats() policy_stats = broker.get_policy_stats()
expected = {policy.idx: {'bytes_used': 0, 'object_count': 0}} expected = {policy.idx: {'bytes_used': 0, 'object_count': 0}}
self.assertEqual(policy_stats, expected) self.assertEqual(policy_stats, expected)

View File

@ -4945,7 +4945,7 @@ class TestObjectController(unittest.TestCase):
expected) expected)
# check that no coro was left waiting to write # check that no coro was left waiting to write
self.assertTrue(timeouts) # sanity - WrappedTimeout did get called self.assertTrue(timeouts) # sanity - WrappedTimeout did get called
missing_exits = filter(lambda tb: tb is not None, timeouts.values()) missing_exits = [tb for tb in timeouts.values() if tb is not None]
self.assertFalse( self.assertFalse(
missing_exits, 'Failed to exit all ChunkWriteTimeouts.\n' + missing_exits, 'Failed to exit all ChunkWriteTimeouts.\n' +
''.join(['No exit from ChunkWriteTimeout entered at:\n' + ''.join(['No exit from ChunkWriteTimeout entered at:\n' +