From 19a684ddedf9259bd389267071f19c1c65b2e836 Mon Sep 17 00:00:00 2001 From: Luong Anh Tuan Date: Mon, 12 Sep 2016 15:49:38 +0700 Subject: [PATCH] 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 --- test/unit/container/test_backend.py | 12 ++++++------ test/unit/proxy/test_server.py | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/test/unit/container/test_backend.py b/test/unit/container/test_backend.py index 4300b9bd28..abdb373650 100644 --- a/test/unit/container/test_backend.py +++ b/test/unit/container/test_backend.py @@ -795,8 +795,8 @@ class TestContainerBroker(unittest.TestCase): if isinstance(self, ContainerBrokerMigrationMixin): real_storage_policy_index = \ broker.get_info()['storage_policy_index'] - policy = filter(lambda p: p.idx == real_storage_policy_index, - POLICIES)[0] + policy = [p for p in POLICIES + if p.idx == real_storage_policy_index][0] broker.put_object('correct_o', next(ts), 123, 'text/plain', '5af83e3196bf99f440f31f2e1a6c9afe', storage_policy_index=policy.idx) @@ -823,8 +823,8 @@ class TestContainerBroker(unittest.TestCase): if isinstance(self, ContainerBrokerMigrationMixin): real_storage_policy_index = \ broker.get_info()['storage_policy_index'] - policy = filter(lambda p: p.idx == real_storage_policy_index, - POLICIES)[0] + policy = [p for p in POLICIES + if p.idx == real_storage_policy_index][0] broker.put_object('correct_o', next(ts), 123, 'text/plain', '5af83e3196bf99f440f31f2e1a6c9afe', storage_policy_index=policy.idx) @@ -847,8 +847,8 @@ class TestContainerBroker(unittest.TestCase): if isinstance(self, ContainerBrokerMigrationMixin): real_storage_policy_index = \ broker.get_info()['storage_policy_index'] - policy = filter(lambda p: p.idx == real_storage_policy_index, - POLICIES)[0] + policy = [p for p in POLICIES + if p.idx == real_storage_policy_index][0] policy_stats = broker.get_policy_stats() expected = {policy.idx: {'bytes_used': 0, 'object_count': 0}} self.assertEqual(policy_stats, expected) diff --git a/test/unit/proxy/test_server.py b/test/unit/proxy/test_server.py index 9e1a4b0213..f4af90af64 100644 --- a/test/unit/proxy/test_server.py +++ b/test/unit/proxy/test_server.py @@ -4945,7 +4945,7 @@ class TestObjectController(unittest.TestCase): expected) # check that no coro was left waiting to write 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( missing_exits, 'Failed to exit all ChunkWriteTimeouts.\n' + ''.join(['No exit from ChunkWriteTimeout entered at:\n' +