Example #1
0
 def test_eq(self):
     # Copy
     tree2 = copy.deepcopy(self.tree)
     self.assertEqual(self.tree, tree2)
     # Additional node
     child = mux.MuxTreeNode("20", {'name': 'Heisenbug'})
     tree2.children[1].children[1].add_child(child)
     self.assertNotEqual(self.tree, tree2)
     # Should match again
     child.detach()
     self.assertEqual(self.tree, tree2)
     # Missing node
     tree2.children[1].children[1].detach()
     self.assertNotEqual(self.tree, tree2)
     self.assertEqual(self.tree.children[0], tree2.children[0])
     # Different value
     tree2.children[0].children[0].children[0].value = {'something': 'else'}
     self.assertNotEqual(self.tree.children[0], tree2.children[0])
     tree3 = mux.MuxTreeNode()
     self.assertNotEqual(tree3, tree2)
     # Merge
     tree3.merge(tree2)
     self.assertEqual(tree3, tree2)
     # Add_child existing
     tree3.add_child(tree2.children[0])
     self.assertEqual(tree3, tree2)
Example #2
0
 def test_tree_mux_node(self):
     """
     Check the extension of fingerprint in MuxTreeNode
     """
     node1 = tree.TreeNode("node1", {"foo": "bar"})
     node1m = mux.MuxTreeNode("node1", {"foo": "bar"})
     node1m_fingerprint = node1m.fingerprint()
     self.assertNotEqual(node1.fingerprint(), node1m_fingerprint)
     node1mduplicate = mux.MuxTreeNode("node1", {"foo": "bar"})
     self.assertEqual(node1m_fingerprint, node1mduplicate.fingerprint())
     node1mb_ctrl = mux.MuxTreeNode("node1", {"foo": "bar"})
     node1mb_ctrl.ctrl = [mux.Control(0, 0)]
     self.assertNotEqual(node1m_fingerprint, node1mb_ctrl.fingerprint())
Example #3
0
 def test_handle_control_path_remove(self):
     node = mux.MuxTreeNode()
     control = mux.Control(yaml_to_mux.YAML_REMOVE_NODE)
     to_be_removed = "node_to_be_removed"
     # pylint: disable=W0212
     yaml_to_mux._handle_control_tag("fake_path", node, (control, to_be_removed))
     self.assertEqual(control.value, to_be_removed)
     self.assertIn(control, node.ctrl)
Example #4
0
 def test_handle_control_path_include_file_does_not_exist(self):
     with self.assertRaises(ValueError):
         # pylint: disable=W0212
         yaml_to_mux._handle_control_tag(
             "original_fake_file.yaml",
             mux.MuxTreeNode(),
             (mux.Control(yaml_to_mux.YAML_INCLUDE), "unexisting_include.yaml"),
         )
Example #5
0
 def test_empty(self):
     act = tuple(mux.MuxTree(mux.MuxTreeNode()))
     self.assertEqual(
         act,
         (
             [
                 "",
             ],
         ),
     )
Example #6
0
 def test_merge_trees(self):
     tree2 = copy.deepcopy(self.tree)
     tree3 = mux.MuxTreeNode()
     tree3.add_child(mux.MuxTreeNode('hw', {'another_value': 'bbb'}))
     tree3.children[0].add_child(mux.MuxTreeNode('nic'))
     tree3.children[0].children[0].add_child(mux.MuxTreeNode('default'))
     tree3.children[0].children[0].add_child(
         mux.MuxTreeNode('virtio', {'nic': 'virtio'}))
     tree3.children[0].add_child(
         mux.MuxTreeNode('cpu', {'test_value': ['z']}))
     tree2.merge(tree3)
     exp = [
         'intel', 'amd', 'arm', 'scsi', 'virtio', 'default', 'virtio',
         'fedora', '\u0161mint', 'prod'
     ]
     self.assertEqual(exp, tree2.get_leaves())
     self.assertEqual(
         {
             'corruptlist': ['upper_node_list'],
             'another_value': 'bbb'
         }, tree2.children[0].value)
     self.assertEqual({
         'joinlist': ['first_item'],
         'test_value': ['z']
     }, tree2.children[0].children[0].value)
     self.assertFalse(tree2.children[0].children[2].children[0].value)
     self.assertEqual({'nic': 'virtio'},
                      tree2.children[0].children[2].children[1].value)
Example #7
0
 def test_merge_trees(self):
     tree2 = copy.deepcopy(self.tree)
     tree3 = mux.MuxTreeNode()
     tree3.add_child(mux.MuxTreeNode("hw", {"another_value": "bbb"}))
     tree3.children[0].add_child(mux.MuxTreeNode("nic"))
     tree3.children[0].children[0].add_child(mux.MuxTreeNode("default"))
     tree3.children[0].children[0].add_child(
         mux.MuxTreeNode("virtio", {"nic": "virtio"})
     )
     tree3.children[0].add_child(mux.MuxTreeNode("cpu", {"test_value": ["z"]}))
     tree2.merge(tree3)
     exp = [
         "intel",
         "amd",
         "arm",
         "scsi",
         "virtio",
         "default",
         "virtio",
         "fedora",
         "\u0161mint",
         "prod",
     ]
     self.assertEqual(exp, tree2.get_leaves())
     self.assertEqual(
         {"corruptlist": ["upper_node_list"], "another_value": "bbb"},
         tree2.children[0].value,
     )
     self.assertEqual(
         {"joinlist": ["first_item"], "test_value": ["z"]},
         tree2.children[0].children[0].value,
     )
     self.assertFalse(tree2.children[0].children[2].children[0].value)
     self.assertEqual(
         {"nic": "virtio"}, tree2.children[0].children[2].children[1].value
     )
Example #8
0
 def test_apply_using(self):
     # pylint: disable=W0212
     node = yaml_to_mux._apply_using('bar', 'foo', mux.MuxTreeNode())
     self.assertEqual(node.path, '/foo')
Example #9
0
 def test_apply_using(self):
     # pylint: disable=W0212
     node = yaml_to_mux._apply_using("bar", "foo", mux.MuxTreeNode())
     self.assertEqual(node.path, "/foo")