From 3f004e6a9fd52fb2aa0b34946a4c1b4aabb71570 Mon Sep 17 00:00:00 2001 From: Dirk Mueller Date: Tue, 23 Jun 2020 14:19:29 +0200 Subject: [PATCH] Switch from unittest2 compat methods to Python 3.x methods With the removal of Python 2.x we can remove the unittest2 compat wrappers and switch to assertCountEqual instead of assertItemsEqual We have been able to use them since then, because testtools required unittest2, which still included it. With testtools removing Python 2.7 support [3][4], we will lose support for assertItemsEqual, so we should switch to use assertCountEqual. [1] - https://bugs.python.org/issue17866 [2] - https://hg.python.org/cpython/rev/d9921cb6e3cd [3] - testing-cabal/testtools#286 [4] - testing-cabal/testtools#277 Change-Id: Ic0d8c9e1025cd05f4042f1c5ba440cc03a0b5834 --- .../unit/service/edp/binary_retrievers/test_manila.py | 6 +++--- .../service/edp/job_binaries/manila/test_manila_type.py | 6 +++--- sahara/tests/unit/service/edp/test_job_utils.py | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/sahara/tests/unit/service/edp/binary_retrievers/test_manila.py b/sahara/tests/unit/service/edp/binary_retrievers/test_manila.py index 1f35f2cd6c..2d61533d53 100644 --- a/sahara/tests/unit/service/edp/binary_retrievers/test_manila.py +++ b/sahara/tests/unit/service/edp/binary_retrievers/test_manila.py @@ -53,14 +53,14 @@ class TestManilaShare(base.SaharaTestCase): remote.instance.node_group.shares = ng_shares info = ms.get_file_info(job_binary, remote) - self.assertItemsEqual({'path': '/mnt/mymountpoint/the_path', + self.assertCountEqual({'path': '/mnt/mymountpoint/the_path', 'type': 'path'}, info) self.assertEqual(0, mount_shares.call_count) self.assertEqual(0, cluster_update.call_count) job_binary.url = 'manila://123456/the_path' info = ms.get_file_info(job_binary, remote) - self.assertItemsEqual({'path': '/mnt/themountpoint/the_path', + self.assertCountEqual({'path': '/mnt/themountpoint/the_path', 'type': 'path'}, info) self.assertEqual(0, mount_shares.call_count) self.assertEqual(0, cluster_update.call_count) @@ -74,7 +74,7 @@ class TestManilaShare(base.SaharaTestCase): job_binary.url = 'manila://missing_id/the_path' info = ms.get_file_info(job_binary, remote) - self.assertItemsEqual({'path': '/mnt/missing_id/the_path', + self.assertCountEqual({'path': '/mnt/missing_id/the_path', 'type': 'path'}, info) self.assertEqual(1, mount_shares.call_count) self.assertEqual(1, cluster_update.call_count) diff --git a/sahara/tests/unit/service/edp/job_binaries/manila/test_manila_type.py b/sahara/tests/unit/service/edp/job_binaries/manila/test_manila_type.py index 049ebe3547..19d500222f 100644 --- a/sahara/tests/unit/service/edp/job_binaries/manila/test_manila_type.py +++ b/sahara/tests/unit/service/edp/job_binaries/manila/test_manila_type.py @@ -75,12 +75,12 @@ class TestManilaType(base.SaharaTestCase): info = self.manila_type.copy_binary_to_cluster(job_binary, remote=remote) - self.assertItemsEqual('/mnt/mymountpoint/the_path', info) + self.assertCountEqual('/mnt/mymountpoint/the_path', info) job_binary.url = 'manila://123456/the_path' info = self.manila_type.copy_binary_to_cluster(job_binary, remote=remote) - self.assertItemsEqual('/mnt/themountpoint/the_path', info) + self.assertCountEqual('/mnt/themountpoint/the_path', info) # missing id default_mount.return_value = '/mnt/missing_id' @@ -89,7 +89,7 @@ class TestManilaType(base.SaharaTestCase): info = self.manila_type.copy_binary_to_cluster(job_binary, remote=remote) - self.assertItemsEqual('/mnt/missing_id/the_path', info) + self.assertCountEqual('/mnt/missing_id/the_path', info) @mock.patch('sahara.utils.openstack.manila.client') @mock.patch('sahara.conductor.API.cluster_update') diff --git a/sahara/tests/unit/service/edp/test_job_utils.py b/sahara/tests/unit/service/edp/test_job_utils.py index 497b611734..c6ef7f5b66 100644 --- a/sahara/tests/unit/service/edp/test_job_utils.py +++ b/sahara/tests/unit/service/edp/test_job_utils.py @@ -106,7 +106,7 @@ class JobUtilsTestCase(testtools.TestCase): job_configs = {'args': [name_ref, name_ref2, id], 'configs': {'config': name_ref}, 'params': {'param': name_ref}} - self.assertItemsEqual( + self.assertCountEqual( ['name', 'name2'], job_utils.find_possible_data_source_refs_by_name(job_configs)) @@ -152,7 +152,7 @@ class JobUtilsTestCase(testtools.TestCase): job_configs = {'args': [id, id2, name_ref], 'configs': {'config': id}, 'params': {'param': id}} - self.assertItemsEqual([id, id2], + self.assertCountEqual([id, id2], job_utils.find_possible_data_source_refs_by_uuid( job_configs)) @@ -231,11 +231,11 @@ class JobUtilsTestCase(testtools.TestCase): def test_to_url_dict(self): data_source_urls = {'1': ('1_native', '1_runtime'), '2': ('2_native', '2_runtime')} - self.assertItemsEqual({'1': '1_native', + self.assertCountEqual({'1': '1_native', '2': '2_native'}, job_utils.to_url_dict(data_source_urls)) - self.assertItemsEqual({'1': '1_runtime', + self.assertCountEqual({'1': '1_runtime', '2': '2_runtime'}, job_utils.to_url_dict(data_source_urls, runtime=True))