From bf0dc265aeff216b5af369728b346294bb1562c8 Mon Sep 17 00:00:00 2001 From: melissaml Date: Tue, 7 Jul 2020 11:11:28 +0800 Subject: [PATCH] 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 --- .../block_device/tests/test_config.py | 8 ++++---- diskimage_builder/block_device/tests/test_lvm.py | 2 +- diskimage_builder/tests/test_elementdeps.py | 16 ++++++++-------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/diskimage_builder/block_device/tests/test_config.py b/diskimage_builder/block_device/tests/test_config.py index 42675183e..371df2111 100644 --- a/diskimage_builder/block_device/tests/test_config.py +++ b/diskimage_builder/block_device/tests/test_config.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): diff --git a/diskimage_builder/block_device/tests/test_lvm.py b/diskimage_builder/block_device/tests/test_lvm.py index fd45f1701..7f47b9830 100644 --- a/diskimage_builder/block_device/tests/test_lvm.py +++ b/diskimage_builder/block_device/tests/test_lvm.py @@ -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 diff --git a/diskimage_builder/tests/test_elementdeps.py b/diskimage_builder/tests/test_elementdeps.py index d4ac1748e..6838af6aa 100644 --- a/diskimage_builder/tests/test_elementdeps.py +++ b/diskimage_builder/tests/test_elementdeps.py @@ -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