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.MuxTreeNode(), (mux.Control( yaml_to_mux.YAML_INCLUDE), 'unexisting_include.yaml'))
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)
def test_handle_control_path_remove(self): klass = mux.MuxTreeNode node = klass() control = mux.Control(yaml_to_mux.YAML_REMOVE_NODE) to_be_removed = 'node_to_be_removed' yaml_to_mux._handle_control_tag('fake_path', klass, node, (control, to_be_removed)) self.assertEqual(control.value, to_be_removed) self.assertIn(control, node.ctrl)
def _mux_loader(loader, node): """ Special !mux loader which allows to tag node as 'multiplex = True'. """ if not isinstance(node, yaml.ScalarNode): objects = _mapping_to_tree_loader(loader, node, looks_like_node=True) else: # This means it's empty node. Don't call mapping_to_tree_loader objects = ListOfNodeObjects() objects.append((mux.Control(YAML_MUX), None)) return objects
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())
class _BaseLoader(SafeLoader): """ YAML loader with additional features related to mux """ SafeLoader.add_constructor('!include', lambda *_: mux.Control(YAML_INCLUDE)) SafeLoader.add_constructor('!using', lambda *_: mux.Control(YAML_USING)) SafeLoader.add_constructor('!remove_node', lambda *_: mux.Control(YAML_REMOVE_NODE)) SafeLoader.add_constructor('!remove_value', lambda *_: mux.Control(YAML_REMOVE_VALUE)) SafeLoader.add_constructor('!filter-only', lambda *_: mux.Control(YAML_FILTER_ONLY)) SafeLoader.add_constructor('!filter-out', lambda *_: mux.Control(YAML_FILTER_OUT)) SafeLoader.add_constructor('tag:yaml.org,2002:python/dict', SafeLoader.construct_yaml_map) SafeLoader.add_constructor('!mux', _mux_loader) SafeLoader.add_constructor(yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG, _mapping_to_tree_loader)