From ccc4db699a1f2bc0003eba4b4b4144e3ef6f1320 Mon Sep 17 00:00:00 2001 From: shenxindi Date: Fri, 17 Jul 2020 10:49:18 +0800 Subject: [PATCH] Use assertEqual instead of assertItemsEqual The assertItemsEqual method has been removed in Python 3.3 [1] but it was kept alive by unittest2, imported by testtools. [1] https://bugs.python.org/issue17866 Change-Id: I410a10d4b57f6d84e2cda623f3969cc14ca0d50e --- .../drivers/netapp/dataontap/client/test_client_cmode.py | 4 ++-- .../netapp/dataontap/cluster_mode/test_performance.py | 5 +++-- manila/tests/share/test_share_types.py | 9 +++++---- manila/tests/share_group/test_share_group_types.py | 4 ++-- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/manila/tests/share/drivers/netapp/dataontap/client/test_client_cmode.py b/manila/tests/share/drivers/netapp/dataontap/client/test_client_cmode.py index 337a9b88cd..948d8d35a8 100644 --- a/manila/tests/share/drivers/netapp/dataontap/client/test_client_cmode.py +++ b/manila/tests/share/drivers/netapp/dataontap/client/test_client_cmode.py @@ -5324,7 +5324,7 @@ class NetAppClientCmodeTestCase(test.TestCase): result = self.client.get_aggregate_disk_types( fake.SHARE_AGGREGATE_NAME) - self.assertItemsEqual(expected, result) + self.assertEqual(sorted(expected), sorted(result)) mock_get_aggregate_disk_types.assert_called_once_with( fake.SHARE_AGGREGATE_NAME) @@ -5352,7 +5352,7 @@ class NetAppClientCmodeTestCase(test.TestCase): fake.SHARE_AGGREGATE_NAME) self.assertIsInstance(result, list) - self.assertItemsEqual(['SATA', 'SSD'], result) + self.assertEqual(sorted(['SATA', 'SSD']), sorted(result)) mock_get_aggregate_disk_types.assert_has_calls([ mock.call(fake.SHARE_AGGREGATE_NAME), mock.call(fake.SHARE_AGGREGATE_NAME, shared=True), diff --git a/manila/tests/share/drivers/netapp/dataontap/cluster_mode/test_performance.py b/manila/tests/share/drivers/netapp/dataontap/cluster_mode/test_performance.py index 906800039b..5ba4ea273d 100644 --- a/manila/tests/share/drivers/netapp/dataontap/cluster_mode/test_performance.py +++ b/manila/tests/share/drivers/netapp/dataontap/cluster_mode/test_performance.py @@ -372,7 +372,7 @@ class PerformanceLibraryTestCase(test.TestCase): self.fake_volumes, self.fake_aggregates) expected_aggregate_names = ['aggr1', 'aggr2', 'aggr3'] - self.assertItemsEqual(expected_aggregate_names, result) + self.assertEqual(sorted(expected_aggregate_names), sorted(result)) def test_get_nodes_for_aggregates(self): @@ -390,7 +390,8 @@ class PerformanceLibraryTestCase(test.TestCase): expected_node_names = ['node1', 'node2'] expected_aggr_node_map = dict(zip(aggregate_names, aggregate_nodes)) - self.assertItemsEqual(expected_node_names, result_node_names) + self.assertEqual(sorted(expected_node_names), + sorted(result_node_names)) self.assertEqual(expected_aggr_node_map, result_aggr_node_map) mock_get_node_for_aggregate.assert_has_calls([ mock.call('aggr1'), mock.call('aggr2'), mock.call('aggr3')]) diff --git a/manila/tests/share/test_share_types.py b/manila/tests/share/test_share_types.py index c426d8994c..e9b1f69974 100644 --- a/manila/tests/share/test_share_types.py +++ b/manila/tests/share/test_share_types.py @@ -170,7 +170,7 @@ class ShareTypesTestCase(test.TestCase): 'share_type_get_all', mock.Mock(return_value=copy.deepcopy(share_type))) returned_type = share_types.get_all_types(self.context) - self.assertItemsEqual(share_type, returned_type) + self.assertEqual(sorted(share_type), sorted(returned_type)) def test_get_all_types_search(self): share_type = self.fake_type_w_extra @@ -183,7 +183,7 @@ class ShareTypesTestCase(test.TestCase): db.share_type_get_all.assert_called_once_with( mock.ANY, 0, filters={'is_public': True}) - self.assertItemsEqual(share_type, returned_type) + self.assertEqual(sorted(share_type), sorted(returned_type)) search_filter = {'extra_specs': {'gold': 'False'}} expected_types = {} returned_types = share_types.get_all_types(self.context, @@ -194,7 +194,7 @@ class ShareTypesTestCase(test.TestCase): search_filter = {'extra_specs': {'gold': 'True'}} returned_type = share_types.get_all_types(self.context, search_opts=search_filter) - self.assertItemsEqual(share_type, returned_type) + self.assertEqual(sorted(share_type), sorted(returned_type)) @ddt.data("nova", "supernova,nova", "supernova", "nova,hypernova,supernova") @@ -268,7 +268,8 @@ class ShareTypesTestCase(test.TestCase): expected_return_types = (['gold', 'silver', 'default'] if len(search_azs.split(',')) < 3 else ['gold', 'default']) - self.assertItemsEqual(expected_return_types, returned_types) + self.assertEqual(sorted(expected_return_types), + sorted(returned_types)) def test_get_share_type_extra_specs(self): share_type = self.fake_type_w_extra['test_with_extra'] diff --git a/manila/tests/share_group/test_share_group_types.py b/manila/tests/share_group/test_share_group_types.py index fbdec420f1..ebb3fea1cf 100644 --- a/manila/tests/share_group/test_share_group_types.py +++ b/manila/tests/share_group/test_share_group_types.py @@ -98,7 +98,7 @@ class ShareGroupTypesTestCase(test.TestCase): returned_type = share_group_types.get_all(self.context) - self.assertItemsEqual(share_group_type, returned_type) + self.assertEqual(sorted(share_group_type), sorted(returned_type)) def test_get_all_types_search(self): share_group_type = self.fake_type_w_extra @@ -112,7 +112,7 @@ class ShareGroupTypesTestCase(test.TestCase): db.share_group_type_get_all.assert_called_once_with( mock.ANY, 0, filters={'is_public': True}) - self.assertItemsEqual(share_group_type, returned_type) + self.assertEqual(sorted(share_group_type), sorted(returned_type)) search_filter = {"group_specs": {"gold": "False"}} returned_type = share_group_types.get_all( self.context, search_opts=search_filter)