How to use _apply_using method in avocado

Best Python code snippet using avocado_python

varianter_yaml_to_mux.py

Source:varianter_yaml_to_mux.py Github

copy

Full Screen

...105 using = using[1:]106 if using[-1] == "/":107 using = using[:-1]108 return using109def _apply_using(name, using, node):110 """111 Create the structure defined by "!using" and return the new root112 :param name: the tag name to have the "!using" applied to113 :type name: str114 :param using: the new location to put the tag into115 :type using: bool116 :param node: the node in which to handle control tags117 :type node: instance of :class:`avocado.core.tree.TreeNode` or similar118 """119 if name != "":120 for name in using.split("/")[::-1]:121 node = mux.MuxTreeNode(name, children=[node])122 else:123 using = using.split("/")[::-1]124 node.name = using.pop()125 while True:126 if not using:127 break128 name = using.pop() # 'using' is list pylint: disable=E1101129 node = mux.MuxTreeNode(name, children=[node])130 node = mux.MuxTreeNode("", children=[node])131 return node132def _node_content_from_node(path, node, values, using):133 """Processes node values into the current node content"""134 for value in values:135 if isinstance(value, mux.MuxTreeNode):136 node.add_child(value)137 elif isinstance(value[0], mux.Control):138 if value[0].code == YAML_USING:139 using = _handle_control_tag_using(path, node.name, using, value[1])140 else:141 _handle_control_tag(path, node, value)142 elif isinstance(value[1], collections.OrderedDict):143 child = _tree_node_from_values(144 path, astring.to_text(value[0]), value[1], using145 )146 node.add_child(child)147 else:148 node.value[value[0]] = value[1]149 return using150def _node_content_from_dict(path, node, values, using):151 """Processes dict values into the current node content"""152 for key, value in values.items():153 if isinstance(key, mux.Control):154 if key.code == YAML_USING:155 using = _handle_control_tag_using(path, node.name, using, value)156 else:157 _handle_control_tag(path, node, [key, value])158 elif isinstance(value, collections.OrderedDict) or value is None:159 node.add_child(_tree_node_from_values(path, key, value, using))160 elif value == "null":161 node.value[key] = None162 else:163 node.value[key] = value164 return using165def _tree_node_from_values(path, name, values, using):166 """Create `name` node and add values"""167 # Initialize the node168 node = mux.MuxTreeNode(astring.to_text(name))169 if not values:170 return node171 using = ""172 # Fill the node content from parsed values173 if isinstance(values, dict):174 using = _node_content_from_dict(path, node, values, using)175 else:176 using = _node_content_from_node(path, node, values, using)177 # Prefix nodes if tag "!using" was used178 if using:179 node = _apply_using(name, using, node)180 return node181def _mapping_to_tree_loader(loader, node, looks_like_node=False):182 """Maps yaml mapping tag to TreeNode structure"""183 _value = []184 for key_node, value_node in node.value:185 # Allow only strings as dict keys186 if key_node.tag.startswith("!"): # reflect tags everywhere187 key = loader.construct_object(key_node)188 else:189 key = loader.construct_scalar(key_node)190 # If we are to keep them, use following, but we lose the control191 # for both, nodes and dicts192 # key = loader.construct_object(key_node)193 if isinstance(key, mux.Control):...

Full Screen

Full Screen

__init__.py

Source:__init__.py Github

copy

Full Screen

...123 using = using[1:]124 if using[-1] == '/':125 using = using[:-1]126 return using127def _apply_using(name, cls_node, using, node):128 """129 Create the structure defined by "!using" and return the new root130 :param name: the tag name to have the "!using" applied to131 :type name: str132 :param cls_node: the class of the node133 :type cls_node: :class:`avocado.core.tree.TreeNode` or similar134 :param using: the new location to put the tag into135 :type using: bool136 :param node: the node in which to handle control tags137 :type node: instance of :class:`avocado.core.tree.TreeNode` or similar138 """139 if name is not '':140 for name in using.split('/')[::-1]:141 node = cls_node(name, children=[node])142 else:143 using = using.split('/')[::-1]144 node.name = using.pop()145 while True:146 if not using:147 break148 name = using.pop() # 'using' is list pylint: disable=E1101149 node = cls_node(name, children=[node])150 node = cls_node('', children=[node])151 return node152def _create_from_yaml(path, cls_node=mux.MuxTreeNode):153 """Create tree structure from yaml stream"""154 def tree_node_from_values(name, values):155 """Create `name` node and add values"""156 def node_content_from_node(node, values, using):157 """Processes node values into the current node content"""158 for value in values:159 if isinstance(value, cls_node):160 node.add_child(value)161 elif isinstance(value[0], mux.Control):162 if value[0].code == YAML_USING:163 using = _handle_control_tag_using(path, name, using, value[1])164 else:165 _handle_control_tag(path, cls_node, node, value)166 elif isinstance(value[1], collections.OrderedDict):167 child = tree_node_from_values(astring.to_text(value[0]),168 value[1])169 node.add_child(child)170 else:171 node.value[value[0]] = value[1]172 return using173 def node_content_from_dict(node, values, using):174 """Processes dict values into the current node content"""175 for key, value in iteritems(values):176 if isinstance(key, mux.Control):177 if key.code == YAML_USING:178 using = _handle_control_tag_using(path, name, using, value)179 else:180 _handle_control_tag(path, cls_node, node, [key, value])181 elif (isinstance(value, collections.OrderedDict) or182 value is None):183 node.add_child(tree_node_from_values(key, value))184 else:185 node.value[key] = value186 return using187 # Initialize the node188 node = cls_node(astring.to_text(name))189 if not values:190 return node191 using = ''192 # Fill the node content from parsed values193 if isinstance(values, dict):194 using = node_content_from_dict(node, values, using)195 else:196 using = node_content_from_node(node, values, using)197 # Prefix nodes if tag "!using" was used198 if using:199 node = _apply_using(name, cls_node, using, node)200 return node201 def mapping_to_tree_loader(loader, node, looks_like_node=False):202 """Maps yaml mapping tag to TreeNode structure"""203 _value = []204 for key_node, value_node in node.value:205 # Allow only strings as dict keys206 if key_node.tag.startswith('!'): # reflect tags everywhere207 key = loader.construct_object(key_node)208 else:209 key = loader.construct_python_str(key_node)210 # If we are to keep them, use following, but we lose the control211 # for both, nodes and dicts212 # key = loader.construct_object(key_node)213 if isinstance(key, mux.Control):...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run avocado automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful