Replace filter() with list-comprehension

Replace filter() with list-comprehension when a list is expected. On
Python 3, filter() returns an iterator, not a list.

tox.ini: add openstack admin volume tests to Python 3.4.

Partial-Implements: blueprint porting-python3
Change-Id: Id99124bf0ef5549c596d94f5d10ab5f88a4e200a
This commit is contained in:
Victor Stinner 2015-10-06 16:34:29 +02:00
parent 8d08abdc9f
commit 2d993b4acc
5 changed files with 9 additions and 8 deletions

View File

@ -64,7 +64,7 @@ class GlobalOverview(usage.UsageView):
exceptions.handle(self.request,
_('Unable to retrieve project list.'))
for instance in data:
project = filter(lambda t: t.id == instance.tenant_id, projects)
project = [t for t in projects if t.id == instance.tenant_id]
# If we could not get the project name, show the tenant_id with
# a 'Deleted' identifier instead.
if project:

View File

@ -89,8 +89,8 @@ class VolumeViewTests(test.BaseAdminViewTests):
'volume_get')})
def test_unmanage_volume(self):
# important - need to get the v2 cinder volume which has host data
volume_list = \
filter(lambda x: x.name == 'v2_volume', self.cinder_volumes.list())
volume_list = [x for x in self.cinder_volumes.list()
if x.name == 'v2_volume']
volume = volume_list[0]
formData = {'volume_name': volume.name,
'host_name': 'host@backend-name#pool',

View File

@ -251,10 +251,10 @@ def check_rule_template(port, ip_proto):
rules_dict = getattr(settings, 'SECURITY_GROUP_RULES', {})
if not rules_dict:
return port
templ_rule = filter(lambda rule: str(port) == rule['from_port']
and str(port) == rule['to_port']
and ip_proto == rule['ip_protocol'],
[rule for rule in rules_dict.values()])
templ_rule = [rule for rule in rules_dict.values()
if (str(port) == rule['from_port']
and str(port) == rule['to_port']
and ip_proto == rule['ip_protocol'])]
if templ_rule:
return u"%(from_port)s (%(name)s)" % templ_rule[0]
return port

View File

@ -314,7 +314,7 @@ def _get_tenant_network_usages(request, usages, disabled_quotas, tenant_id):
networks = []
networks = neutron.network_list(request, shared=False)
if tenant_id:
networks = filter(lambda net: net.tenant_id == tenant_id, networks)
networks = [net for net in networks if net.tenant_id == tenant_id]
usages.tally('networks', len(networks))
if 'subnet' not in disabled_quotas:

View File

@ -34,6 +34,7 @@ commands =
horizon.test.tests.utils \
horizon.test.tests.views
python manage.py test --settings=openstack_dashboard.test.settings \
openstack_dashboard.dashboards.admin.volumes.volumes.tests \
openstack_dashboard.dashboards.identity.users \
openstack_dashboard.dashboards.project.access_and_security.api_access.tests \
openstack_dashboard.dashboards.project.images.images.tests.CreateImageFormTests \