Browse Source

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
changes/13/737513/1
Dirk Mueller 2 weeks ago
parent
commit
3f004e6a9f
3 changed files with 10 additions and 10 deletions
  1. +3
    -3
      sahara/tests/unit/service/edp/binary_retrievers/test_manila.py
  2. +3
    -3
      sahara/tests/unit/service/edp/job_binaries/manila/test_manila_type.py
  3. +4
    -4
      sahara/tests/unit/service/edp/test_job_utils.py

+ 3
- 3
sahara/tests/unit/service/edp/binary_retrievers/test_manila.py View File

@@ -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)

+ 3
- 3
sahara/tests/unit/service/edp/job_binaries/manila/test_manila_type.py View File

@@ -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')


+ 4
- 4
sahara/tests/unit/service/edp/test_job_utils.py View File

@@ -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))


Loading…
Cancel
Save