Skip to content

Commit

Permalink
Replace assertItemsEqual with assertCountEqual
Browse files Browse the repository at this point in the history
assertItemsEqual was removed from Python's unittest.TestCase in
Python 3.3 [1][2]. 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: I095a8aac336e5aa0fbfed64406e33b3b40ff42bc
  • Loading branch information
javierpena committed Mar 4, 2020
1 parent 36380ad commit 6ba111b
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion openstack/tests/unit/cloud/test_caching.py
Expand Up @@ -554,7 +554,7 @@ def test_list_ports_filtered(self):
]}),
])
ports = self.cloud.list_ports(filters={'status': 'DOWN'})
self.assertItemsEqual([down_port], ports)
self.assertCountEqual([down_port], ports)
self.assert_calls()


Expand Down
2 changes: 1 addition & 1 deletion openstack/tests/unit/cloud/test_floating_ip_pool.py
Expand Up @@ -49,7 +49,7 @@ def test_list_floating_ip_pools(self):

floating_ip_pools = self.cloud.list_floating_ip_pools()

self.assertItemsEqual(floating_ip_pools, self.pools)
self.assertCountEqual(floating_ip_pools, self.pools)

self.assert_calls()

Expand Down
4 changes: 2 additions & 2 deletions openstack/tests/unit/cloud/test_port.py
Expand Up @@ -238,7 +238,7 @@ def test_list_ports(self):
json=self.mock_neutron_port_list_rep)
])
ports = self.cloud.list_ports()
self.assertItemsEqual(self.mock_neutron_port_list_rep['ports'], ports)
self.assertCountEqual(self.mock_neutron_port_list_rep['ports'], ports)
self.assert_calls()

def test_list_ports_filtered(self):
Expand All @@ -250,7 +250,7 @@ def test_list_ports_filtered(self):
json=self.mock_neutron_port_list_rep)
])
ports = self.cloud.list_ports(filters={'status': 'DOWN'})
self.assertItemsEqual(self.mock_neutron_port_list_rep['ports'], ports)
self.assertCountEqual(self.mock_neutron_port_list_rep['ports'], ports)
self.assert_calls()

def test_list_ports_exception(self):
Expand Down
4 changes: 2 additions & 2 deletions openstack/tests/unit/config/test_config.py
Expand Up @@ -46,7 +46,7 @@ def test_get_all(self):
cloud for cloud in base.USER_CONF['clouds'].keys()
] + ['_test_cloud_regions', '_test_cloud_regions']
configured_clouds = [cloud.name for cloud in clouds]
self.assertItemsEqual(user_clouds, configured_clouds)
self.assertCountEqual(user_clouds, configured_clouds)

def test_get_all_clouds(self):
# Ensure the alias is in place
Expand All @@ -60,7 +60,7 @@ def test_get_all_clouds(self):
cloud for cloud in base.USER_CONF['clouds'].keys()
] + ['_test_cloud_regions', '_test_cloud_regions']
configured_clouds = [cloud.name for cloud in clouds]
self.assertItemsEqual(user_clouds, configured_clouds)
self.assertCountEqual(user_clouds, configured_clouds)

def test_get_one(self):
c = config.OpenStackConfig(config_files=[self.cloud_yaml],
Expand Down
2 changes: 1 addition & 1 deletion openstack/tests/unit/test_resource.py
Expand Up @@ -314,7 +314,7 @@ def test_delitem(self):
def test_iter(self):
attrs = {"key": "value"}
sot = resource._ComponentManager(attributes=attrs)
self.assertItemsEqual(iter(attrs), sot.__iter__())
self.assertCountEqual(iter(attrs), sot.__iter__())

def test_len(self):
attrs = {"key": "value"}
Expand Down

0 comments on commit 6ba111b

Please sign in to comment.