From 80ae31f46163a5a348c386fa92dc6827f8c90860 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 14 Oct 2015 17:20:16 +0200 Subject: [PATCH] Fix Python 3 issues in dashboard image tests * Use NamedTemporaryFile instead of TemporaryFile because we must have a name which is a text on Python 3. Otherwise, the test fails. On Python 3, TemporaryFile uses an integer for the file name, the file descriptor. * Replace filter() and map() with list comprehensions to get a list on Python 3. * On Python 3, temporary files are open in binary mode so write a byte string instead of a text string. * tox.ini: enable all image tests on Python 3. Partial-Implements: blueprint porting-python3 Change-Id: Ice7f119c040bbddeda10ed45d137bb7851764b8d --- .../project/images/images/tables.py | 2 +- .../dashboards/project/images/images/tests.py | 20 +++++++++---------- tox.ini | 3 +-- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/openstack_dashboard/dashboards/project/images/images/tables.py b/openstack_dashboard/dashboards/project/images/images/tables.py index 6ec298d433..e893b30822 100644 --- a/openstack_dashboard/dashboards/project/images/images/tables.py +++ b/openstack_dashboard/dashboards/project/images/images/tables.py @@ -192,7 +192,7 @@ def filter_tenants(): @memoized def filter_tenant_ids(): - return map(lambda ft: ft['tenant'], filter_tenants()) + return [ft['tenant'] for ft in filter_tenants()] class OwnerFilter(tables.FixedFilterAction): diff --git a/openstack_dashboard/dashboards/project/images/images/tests.py b/openstack_dashboard/dashboards/project/images/images/tests.py index d2727dbe64..99261922dd 100644 --- a/openstack_dashboard/dashboards/project/images/images/tests.py +++ b/openstack_dashboard/dashboards/project/images/images/tests.py @@ -212,8 +212,8 @@ class ImageViewTests(test.TestCase): @test.create_stubs({api.glance: ('image_create',)}) def test_image_create_post_upload(self): - temp_file = tempfile.TemporaryFile() - temp_file.write('123') + temp_file = tempfile.NamedTemporaryFile() + temp_file.write(b'123') temp_file.flush() temp_file.seek(0) @@ -225,8 +225,8 @@ class ImageViewTests(test.TestCase): @test.create_stubs({api.glance: ('image_create',)}) def test_image_create_post_with_kernel_ramdisk(self): - temp_file = tempfile.TemporaryFile() - temp_file.write('123') + temp_file = tempfile.NamedTemporaryFile() + temp_file.write(b'123') temp_file.flush() temp_file.seek(0) @@ -417,12 +417,12 @@ class OwnerFilterTests(test.TestCase): special = map(lambda t: t['tenant'], self.filter_tenants) if filter_string == 'public': - return filter(lambda im: im.is_public, images) + return [im for im in images if im.is_public] if filter_string == 'shared': - return filter(lambda im: (not im.is_public and - im.owner != my_tenant_id and - im.owner not in special), - images) + return [im for im in images + if (not im.is_public and + im.owner != my_tenant_id and + im.owner not in special)] if filter_string == 'project': filter_string = my_tenant_id - return filter(lambda im: im.owner == filter_string, images) + return [im for im in images if im.owner == filter_string] diff --git a/tox.ini b/tox.ini index 10c21d823b..948d1e9774 100644 --- a/tox.ini +++ b/tox.ini @@ -33,8 +33,7 @@ commands = 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 \ - openstack_dashboard.dashboards.project.images.tests.ImagesAndSnapshotsUtilsTests \ + openstack_dashboard.dashboards.project.images \ openstack_dashboard.dashboards.project.instances \ openstack_dashboard.dashboards.project.network_topology \ openstack_dashboard.dashboards.project.networks.tests \