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
This commit is contained in:
Dirk Mueller 2020-06-23 14:19:29 +02:00
parent 81bae85a9a
commit 3f004e6a9f
3 changed files with 10 additions and 10 deletions

View File

@ -53,14 +53,14 @@ class TestManilaShare(base.SaharaTestCase):
remote.instance.node_group.shares = ng_shares remote.instance.node_group.shares = ng_shares
info = ms.get_file_info(job_binary, remote) 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) 'type': 'path'}, info)
self.assertEqual(0, mount_shares.call_count) self.assertEqual(0, mount_shares.call_count)
self.assertEqual(0, cluster_update.call_count) self.assertEqual(0, cluster_update.call_count)
job_binary.url = 'manila://123456/the_path' job_binary.url = 'manila://123456/the_path'
info = ms.get_file_info(job_binary, remote) 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) 'type': 'path'}, info)
self.assertEqual(0, mount_shares.call_count) self.assertEqual(0, mount_shares.call_count)
self.assertEqual(0, cluster_update.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' job_binary.url = 'manila://missing_id/the_path'
info = ms.get_file_info(job_binary, remote) 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) 'type': 'path'}, info)
self.assertEqual(1, mount_shares.call_count) self.assertEqual(1, mount_shares.call_count)
self.assertEqual(1, cluster_update.call_count) self.assertEqual(1, cluster_update.call_count)

View File

@ -75,12 +75,12 @@ class TestManilaType(base.SaharaTestCase):
info = self.manila_type.copy_binary_to_cluster(job_binary, info = self.manila_type.copy_binary_to_cluster(job_binary,
remote=remote) remote=remote)
self.assertItemsEqual('/mnt/mymountpoint/the_path', info) self.assertCountEqual('/mnt/mymountpoint/the_path', info)
job_binary.url = 'manila://123456/the_path' job_binary.url = 'manila://123456/the_path'
info = self.manila_type.copy_binary_to_cluster(job_binary, info = self.manila_type.copy_binary_to_cluster(job_binary,
remote=remote) remote=remote)
self.assertItemsEqual('/mnt/themountpoint/the_path', info) self.assertCountEqual('/mnt/themountpoint/the_path', info)
# missing id # missing id
default_mount.return_value = '/mnt/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, info = self.manila_type.copy_binary_to_cluster(job_binary,
remote=remote) 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.utils.openstack.manila.client')
@mock.patch('sahara.conductor.API.cluster_update') @mock.patch('sahara.conductor.API.cluster_update')

View File

@ -106,7 +106,7 @@ class JobUtilsTestCase(testtools.TestCase):
job_configs = {'args': [name_ref, name_ref2, id], job_configs = {'args': [name_ref, name_ref2, id],
'configs': {'config': name_ref}, 'configs': {'config': name_ref},
'params': {'param': name_ref}} 'params': {'param': name_ref}}
self.assertItemsEqual( self.assertCountEqual(
['name', 'name2'], ['name', 'name2'],
job_utils.find_possible_data_source_refs_by_name(job_configs)) 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], job_configs = {'args': [id, id2, name_ref],
'configs': {'config': id}, 'configs': {'config': id},
'params': {'param': id}} 'params': {'param': id}}
self.assertItemsEqual([id, id2], self.assertCountEqual([id, id2],
job_utils.find_possible_data_source_refs_by_uuid( job_utils.find_possible_data_source_refs_by_uuid(
job_configs)) job_configs))
@ -231,11 +231,11 @@ class JobUtilsTestCase(testtools.TestCase):
def test_to_url_dict(self): def test_to_url_dict(self):
data_source_urls = {'1': ('1_native', '1_runtime'), data_source_urls = {'1': ('1_native', '1_runtime'),
'2': ('2_native', '2_runtime')} '2': ('2_native', '2_runtime')}
self.assertItemsEqual({'1': '1_native', self.assertCountEqual({'1': '1_native',
'2': '2_native'}, '2': '2_native'},
job_utils.to_url_dict(data_source_urls)) job_utils.to_url_dict(data_source_urls))
self.assertItemsEqual({'1': '1_runtime', self.assertCountEqual({'1': '1_runtime',
'2': '2_runtime'}, '2': '2_runtime'},
job_utils.to_url_dict(data_source_urls, job_utils.to_url_dict(data_source_urls,
runtime=True)) runtime=True))