diff --git a/avocado/core/tree.py b/avocado/core/tree.py index a84b0b941e069b7826c868c7d259ebd7b5cfadac..079c39f9199f5b2e86db2587556f057f17229825 100644 --- a/avocado/core/tree.py +++ b/avocado/core/tree.py @@ -200,6 +200,21 @@ class TreeNode(object): """ Inverted eq """ return not self == other + def __hash__(self): + values = [] + for item in self.value: + try: + values.append(hash(item)) + except TypeError: + values.append(hash(str(item))) + children = [] + for item in self.children: + try: + children.append(hash(item)) + except TypeError: + children.append(hash(str(item))) + return hash((self.name, ) + tuple(values) + tuple(children)) + def fingerprint(self): """ Reports string which represents the value of this node. diff --git a/optional_plugins/varianter_yaml_to_mux/tests/test_mux.py b/optional_plugins/varianter_yaml_to_mux/tests/test_mux.py index 16ba83248c59c5d0809c05beccaddcf9d5888b8c..f8c102b9957996594eb81428107a99d213f8676b 100644 --- a/optional_plugins/varianter_yaml_to_mux/tests/test_mux.py +++ b/optional_plugins/varianter_yaml_to_mux/tests/test_mux.py @@ -228,9 +228,18 @@ class TestMuxTree(unittest.TestCase): variant1 = next(iter(mux1)) variant2 = next(iter(mux2)) self.assertNotEqual(variant1, variant2) - self.assertEqual(str(variant1), "{'paths': '', 'variant': " - "[TreeNode(name='child1'), TreeNode(name=" - "'child2')], 'variant_id': 'child1-child2-9154'}") + str_variant = str(variant1) + variant_list = [] + for item in variant1: + variant_list.append("'%s': '%s'" % (item, variant1[item])) + expected_items = ["'paths': ''", + "'variant': '[TreeNode(name='child1'), " + "TreeNode(name='child2')]'", + "'variant_id': 'child1-child2-9154'"] + for item in expected_items: + self.assertIn(item, variant_list) + variant_list.remove(item) + self.assertFalse(variant_list) class TestMultiplex(unittest.TestCase): diff --git a/selftests/functional/test_json_variants.py b/selftests/functional/test_json_variants.py index f0fdf8d9e492f4c70af1b2840c95f842ea560c2a..50a346d325fa28b1a229b10f506ec1994e2c844e 100644 --- a/selftests/functional/test_json_variants.py +++ b/selftests/functional/test_json_variants.py @@ -21,14 +21,16 @@ class VariantsDumpLoadTests(unittest.TestCase): os.chdir(basedir) def test_variants_dump(self): - content = ('[{"paths": ["/run/*"], ' - '"variant": [["/", []]], ' - '"variant_id": null}]') cmd_line = ('%s variants --json-variants-dump %s' % (AVOCADO, self.variants_file)) process.run(cmd_line) with open(self.variants_file, 'r') as file_obj: - self.assertEqual(file_obj.read(), content) + file_content = file_obj.read() + self.assertEqual(file_content[0:2], '[{') + self.assertIn('"paths": ["/run/*"]', file_content) + self.assertIn('"variant": [["/", []]]', file_content) + self.assertIn('"variant_id": null', file_content) + self.assertEqual(file_content[-2:], '}]') def test_run_load(self): content = ('[{"paths": ["/run/*"],'