Skip to content

Commit 4d58c0b

Browse files
committed
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: Ied2227a482087f4a2dc4e2d9986f9b3b777aa821
1 parent f1ebc15 commit 4d58c0b

File tree

8 files changed

+19
-19
lines changed

8 files changed

+19
-19
lines changed

nova/tests/functional/db/test_aggregate.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ def test_get_non_matching_by_metadata_keys(self):
587587
value='required')
588588

589589
self.assertEqual(2, len(aggs))
590-
self.assertItemsEqual([2, 3], [a.id for a in aggs])
590+
self.assertCountEqual([2, 3], [a.id for a in aggs])
591591

592592
def test_matching_aggregates_multiple_keys(self):
593593
"""All matching aggregates for multiple keys."""
@@ -641,7 +641,7 @@ def test_get_non_matching_aggregates_multiple_keys(self):
641641
'trait:', value='required')
642642

643643
self.assertEqual(2, len(aggs))
644-
self.assertItemsEqual([2, 5], [a.id for a in aggs])
644+
self.assertCountEqual([2, 5], [a.id for a in aggs])
645645

646646
def test_get_non_matching_by_metadata_keys_empty_keys(self):
647647
"""Test aggregates non matching by metadata with empty keys."""
@@ -669,7 +669,7 @@ def test_get_non_matching_by_metadata_keys_empty_keys(self):
669669
self.context, [], 'trait:', value='required')
670670

671671
self.assertEqual(5, len(aggs))
672-
self.assertItemsEqual([1, 2, 3, 4, 5], [a.id for a in aggs])
672+
self.assertCountEqual([1, 2, 3, 4, 5], [a.id for a in aggs])
673673

674674
def test_get_non_matching_by_metadata_keys_empty_key_prefix(self):
675675
"""Test aggregates non matching by metadata with empty key_prefix."""

nova/tests/functional/libvirt/test_numa_live_migration.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,16 @@ def _assert_instance_pinned_cpus(self, uuid, instance_cpus, host_cpus):
8787
ctxt, uuid)
8888
self.assertEqual(1, len(topology.cells))
8989
# NOTE(artom) DictOfIntegersField has strings as keys, need to convert
90-
self.assertItemsEqual([str(cpu) for cpu in instance_cpus],
90+
self.assertCountEqual([str(cpu) for cpu in instance_cpus],
9191
topology.cells[0].cpu_pinning_raw.keys())
92-
self.assertItemsEqual(host_cpus,
92+
self.assertCountEqual(host_cpus,
9393
topology.cells[0].cpu_pinning_raw.values())
9494

9595
def _assert_host_consumed_cpus(self, host, cpus):
9696
ctxt = context.get_admin_context()
9797
topology = objects.NUMATopology.obj_from_db_obj(
9898
objects.ComputeNode.get_by_nodename(ctxt, host).numa_topology)
99-
self.assertItemsEqual(cpus, topology.cells[0].pinned_cpus)
99+
self.assertCountEqual(cpus, topology.cells[0].pinned_cpus)
100100

101101

102102
class NUMALiveMigrationPositiveBase(NUMALiveMigrationBase):

nova/tests/functional/test_servers_provider_tree.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def setUp(self):
8585
self.expected_fake_driver_capability_traits.union(
8686
# The COMPUTE_NODE trait is always added
8787
[os_traits.COMPUTE_NODE]))
88-
self.assertItemsEqual(self.expected_compute_node_traits,
88+
self.assertCountEqual(self.expected_compute_node_traits,
8989
self._get_provider_traits(self.host_uuid))
9090

9191
def _run_update_available_resource(self, startup):
@@ -151,7 +151,7 @@ def update_provider_tree(prov_tree, nodename):
151151
self.assertIn('CUSTOM_BANDWIDTH', self._get_all_resource_classes())
152152
self.assertIn('CUSTOM_GOLD', self._get_all_traits())
153153
self.assertEqual(inv, self._get_provider_inventory(self.host_uuid))
154-
self.assertItemsEqual(
154+
self.assertCountEqual(
155155
traits.union(self.expected_compute_node_traits),
156156
self._get_provider_traits(self.host_uuid)
157157
)
@@ -373,7 +373,7 @@ def update_provider_tree(prov_tree, nodename, allocations=None):
373373
self._get_provider_inventory(uuids.pf2_2)['SRIOV_NET_VF']['total'])
374374

375375
# Compute don't have any extra traits
376-
self.assertItemsEqual(self.expected_compute_node_traits,
376+
self.assertCountEqual(self.expected_compute_node_traits,
377377
self._get_provider_traits(self.host_uuid))
378378

379379
# NUMAs don't have any traits
@@ -605,7 +605,7 @@ def test_resource_provider_traits(self):
605605
ptree_traits +
606606
[os_traits.COMPUTE_NET_ATTACH_INTERFACE, os_traits.COMPUTE_NODE]
607607
)
608-
self.assertItemsEqual(expected_traits,
608+
self.assertCountEqual(expected_traits,
609609
self._get_provider_traits(rp_uuid))
610610
global_traits = self._get_all_traits()
611611
# CUSTOM_FOO is now a registered trait because the virt driver
@@ -617,7 +617,7 @@ def test_resource_provider_traits(self):
617617
expected_traits.remove(custom_trait)
618618
expected_traits.remove(os_traits.COMPUTE_NET_ATTACH_INTERFACE)
619619
self._set_provider_traits(rp_uuid, list(expected_traits))
620-
self.assertItemsEqual(expected_traits,
620+
self.assertCountEqual(expected_traits,
621621
self._get_provider_traits(rp_uuid))
622622

623623
# The above trait deletions are simulations of an out-of-band
@@ -637,7 +637,7 @@ def test_resource_provider_traits(self):
637637
# placement.
638638
self._run_periodics()
639639

640-
self.assertItemsEqual(expected_traits,
640+
self.assertCountEqual(expected_traits,
641641
self._get_provider_traits(rp_uuid))
642642
global_traits = self._get_all_traits()
643643
self.assertIn(custom_trait, global_traits)

nova/tests/unit/compute/test_compute_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6913,7 +6913,7 @@ def test_validate_and_build_base_options_translate_neutron_secgroup(self):
69136913
# and only for the non-default security group name.
69146914
scget.assert_called_once_with(self.context, 'fake-security-group')
69156915
# Assert we translated the non-default secgroup name to uuid.
6916-
self.assertItemsEqual(['default', uuids.secgroup_uuid],
6916+
self.assertCountEqual(['default', uuids.secgroup_uuid],
69176917
security_groups)
69186918

69196919
@mock.patch('nova.compute.api.API._record_action_start')

nova/tests/unit/network/test_network_info.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ def test_get_events(self):
872872
diff_host = objects.Migration(source_compute='fake-host1',
873873
dest_compute='fake-host2')
874874
# Same-host migrations will have all events be plug-time.
875-
self.assertItemsEqual(
875+
self.assertCountEqual(
876876
[('network-vif-plugged', uuids.normal_vif),
877877
('network-vif-plugged', uuids.hybrid_vif)],
878878
network_info.get_plug_time_events(same_host))

nova/tests/unit/network/test_neutron.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5845,7 +5845,7 @@ def test_create_resource_requests(self, getclient,
58455845
[None, None, None, None, uuids.trusted_port],
58465846
[pci_req.requester_id for pci_req in pci_requests.requests])
58475847

5848-
self.assertItemsEqual(
5848+
self.assertCountEqual(
58495849
['physnet1', 'physnet2', 'physnet3', 'physnet4'],
58505850
network_metadata.physnets)
58515851
self.assertTrue(network_metadata.tunneled)

nova/tests/unit/objects/test_request_spec.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,7 +1005,7 @@ def test_compat_requester_and_provider(self):
10051005
self.assertIn('requester_id', primitive)
10061006
self.assertIn('provider_uuids', primitive)
10071007
self.assertIn('required_traits', primitive)
1008-
self.assertItemsEqual(
1008+
self.assertCountEqual(
10091009
primitive['forbidden_aggregates'], set(['agg3', 'agg4']))
10101010
primitive = req_obj.obj_to_primitive(
10111011
target_version='1.2',
@@ -1078,7 +1078,7 @@ def test_obj_make_compatible(self):
10781078
obj_primitive = data(obj.obj_to_primitive(target_version='1.4',
10791079
version_manifest=manifest))
10801080
self.assertIn('forbidden_aggregates', obj_primitive)
1081-
self.assertItemsEqual(obj_primitive['forbidden_aggregates'],
1081+
self.assertCountEqual(obj_primitive['forbidden_aggregates'],
10821082
set(['agg3', 'agg4']))
10831083
self.assertIn('aggregates', obj_primitive)
10841084

nova/tests/unit/scheduler/test_request_filter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def test_isolate_aggregates(self, mock_getnotmd):
131131
reqspec = objects.RequestSpec(flavor=fake_flavor, image=fake_image)
132132
result = request_filter.isolate_aggregates(self.context, reqspec)
133133
self.assertTrue(result)
134-
self.assertItemsEqual(
134+
self.assertCountEqual(
135135
set([uuids.agg1, uuids.agg2, uuids.agg4]),
136136
reqspec.requested_destination.forbidden_aggregates)
137137
mock_getnotmd.assert_called_once_with(
@@ -322,7 +322,7 @@ def test_with_tenant_and_az_and_traits(self, mock_getmd, mock_getnotmd):
322322
','.join(sorted([uuids.agg4])),
323323
','.join(sorted(
324324
reqspec.requested_destination.aggregates[1].split(','))))
325-
self.assertItemsEqual(
325+
self.assertCountEqual(
326326
set([uuids.agg1, uuids.agg2, uuids.agg3]),
327327
reqspec.requested_destination.forbidden_aggregates)
328328
mock_getmd.assert_has_calls([

0 commit comments

Comments
 (0)