Best Python code snippet using avocado_python
tree.py
Source:tree.py
...220 else:221 raise ValueError("Path %s does not exists in this tree\n%s"222 % (path, tree_view(self.root)))223 return node224 def iter_children_preorder(self):225 """ Iterate through children """226 queue = collections.deque()227 node = self228 while node is not None:229 yield node230 queue.extendleft(reversed(node.children))231 try:232 node = queue.popleft()233 except IndexError:234 node = None235 def iter_leaves(self):236 """ Iterate through leaf nodes """237 for node in self.iter_children_preorder():238 if node.is_leaf:239 yield node240 def get_leaves(self):241 """ Get list of leaf nodes """242 return list(self.iter_leaves())243 def detach(self):244 """ Detach this node from parent """245 if self.parent:246 self.parent.children.remove(self)247 self.parent = None248 return self249def path_parent(path):250 """251 From a given path, return its parent path.252 :param path: the node path as string.253 :return: the parent path as string.254 """255 parent = path.rpartition('/')[0]256 if not parent:257 return '/'258 return parent259def apply_filters(tree, filter_only=None, filter_out=None):260 """261 Apply a set of filters to the tree.262 The basic filtering is filter only, which includes nodes,263 and the filter out rules, that exclude nodes.264 Note that filter_out is stronger than filter_only, so if you filter out265 something, you could not bypass some nodes by using a filter_only rule.266 :param filter_only: the list of paths which will include nodes.267 :param filter_out: the list of paths which will exclude nodes.268 :return: the original tree minus the nodes filtered by the rules.269 """270 if filter_only is None:271 filter_only = []272 else:273 filter_only = [_.rstrip('/') for _ in filter_only if _]274 if filter_out is None:275 filter_out = []276 else:277 filter_out = [_.rstrip('/') for _ in filter_out if _]278 for node in tree.iter_children_preorder():279 keep_node = True280 for path in filter_only:281 if path == '':282 continue283 if node.path == path:284 keep_node = True285 break286 if node.parent and node.parent.path == path_parent(path):287 keep_node = False288 continue289 for path in filter_out:290 if path == '':291 continue292 if node.path == path:...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!