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: I870286a2557e41099597c22dc9747743e1077615
changes/45/739645/1
melissaml 2 years ago
parent dba1d390da
commit bf0dc265ae
  1. 8
      diskimage_builder/block_device/tests/test_config.py
  2. 2
      diskimage_builder/block_device/tests/test_lvm.py
  3. 16
      diskimage_builder/tests/test_elementdeps.py

@ -65,21 +65,21 @@ class TestConfigParsing(TestConfig):
def test_graph(self):
graph = self.load_config_file('simple_graph.yaml')
parsed_graph = config_tree_to_graph(graph)
self.assertItemsEqual(parsed_graph, graph)
self.assertCountEqual(parsed_graph, graph)
# equivalence of simple tree to graph
def test_simple_tree(self):
tree = self.load_config_file('simple_tree.yaml')
graph = self.load_config_file('simple_graph.yaml')
parsed_graph = config_tree_to_graph(tree)
self.assertItemsEqual(parsed_graph, graph)
self.assertCountEqual(parsed_graph, graph)
# equivalence of a deeper tree to graph
def test_deep_tree(self):
tree = self.load_config_file('deep_tree.yaml')
graph = self.load_config_file('deep_graph.yaml')
parsed_graph = config_tree_to_graph(tree)
self.assertItemsEqual(parsed_graph, graph)
self.assertCountEqual(parsed_graph, graph)
# equivalence of a complicated multi-partition tree to graph
def test_multipart_tree(self):
@ -87,7 +87,7 @@ class TestConfigParsing(TestConfig):
graph = self.load_config_file('multiple_partitions_graph.yaml')
parsed_graph = config_tree_to_graph(tree)
logger.debug(parsed_graph)
self.assertItemsEqual(parsed_graph, graph)
self.assertCountEqual(parsed_graph, graph)
class TestCreateGraph(TestGraphGeneration):

@ -38,7 +38,7 @@ class TestLVM(tc.TestGraphGeneration):
tree = self.load_config_file('lvm_tree.yaml')
graph = self.load_config_file('lvm_graph.yaml')
parsed_graph = config_tree_to_graph(tree)
self.assertItemsEqual(parsed_graph, graph)
self.assertCountEqual(parsed_graph, graph)
def test_lvm_invalid_config(self):
# test some invalid config paths

@ -109,7 +109,7 @@ class TestElementDeps(testtools.TestCase):
def test_non_transitive_deps(self):
result = element_dependencies.get_elements(['requires-foo'],
self.element_dirs)
self.assertItemsEqual([self._e('foo'), self._e('requires-foo')],
self.assertCountEqual([self._e('foo'), self._e('requires-foo')],
result)
def test_missing_deps(self):
@ -131,7 +131,7 @@ class TestElementDeps(testtools.TestCase):
result = element_dependencies.get_elements(
['requires-requires-foo'], self.element_dirs)
self.assertItemsEqual([self._e('requires-requires-foo'),
self.assertCountEqual([self._e('requires-requires-foo'),
self._e('requires-foo'),
self._e('foo')], result)
@ -142,20 +142,20 @@ class TestElementDeps(testtools.TestCase):
def test_self(self):
result = element_dependencies.get_elements(['self', 'foo'],
self.element_dirs)
self.assertItemsEqual([self._e('self'),
self.assertCountEqual([self._e('self'),
self._e('foo')], result)
def test_circular(self):
result = element_dependencies.get_elements(['circular1'],
self.element_dirs)
self.assertItemsEqual([self._e('circular1'),
self.assertCountEqual([self._e('circular1'),
self._e('circular2')], result)
def test_provide(self):
result = element_dependencies.get_elements(
['provides_virtual', 'requires_virtual'],
self.element_dirs)
self.assertItemsEqual([self._e('requires_virtual'),
self.assertCountEqual([self._e('requires_virtual'),
self._e('provides_virtual')], result)
def test_provide_conflict(self):
@ -168,7 +168,7 @@ class TestElementDeps(testtools.TestCase):
result = element_dependencies.get_elements(
['requires_new_virtual', 'provides_new_virtual'],
self.element_dirs)
self.assertItemsEqual(
self.assertCountEqual(
[self._e('requires_new_virtual'),
self._e('provides_new_virtual')], result)
@ -202,7 +202,7 @@ class TestElementDeps(testtools.TestCase):
# not the base dir
result = element_dependencies.get_elements(['override_element', 'foo'],
self.element_dirs)
self.assertItemsEqual([self._e('foo'),
self.assertCountEqual([self._e('foo'),
self._eo('override_element')],
result)
@ -210,7 +210,7 @@ class TestElementDeps(testtools.TestCase):
# test the deprecated expand_dependencies call
result = element_dependencies.expand_dependencies(
['foo', 'requires-foo'], self.element_dirs)
self.assertItemsEqual(['foo', 'requires-foo'], result)
self.assertCountEqual(['foo', 'requires-foo'], result)
def test_output_sanity(self):
# very basic output sanity test

Loading…
Cancel
Save