未验证 提交 6805d780 编写于 作者: C Cleber Rosa

Merge remote-tracking branch 'clebergnu/selftests_and_misc_fixes_9th_batch_v2'

Signed-off-by: NCleber Rosa <crosa@redhat.com>
......@@ -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.
......
......@@ -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):
......
......@@ -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/*"],'
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册