How to use iter_leaves method in avocado

Best Python code snippet using avocado_python

print-two-nwk.py

Source:print-two-nwk.py Github

copy

Full Screen

...55 clades = dict()56 for node in t1.traverse():57 if not node.is_leaf():58 # Get leaf names for a "node"59 names = map(lambda n: n.name, node.iter_leaves())60 names.sort()61 cladename = ",".join(names)62 if cladename in clades:63 clades[cladename] += 164 else:65 clades[cladename] = 166 for node in t2.traverse():67 if not node.is_leaf():68 # Get leaf names for a "node"69 names = map(lambda n: n.name, node.iter_leaves())70 names.sort()71 cladename = ",".join(names)72 if cladename in clades:73 clades[cladename] += 174 else:75 clades[cladename] = 176 for node in t1.traverse():77 if not node.is_leaf():78 # Get leaf names for a "node"79 names = map(lambda n: n.name, node.iter_leaves())80 names.sort()81 cladename = ",".join(names)82 if clades[cladename] == 2:83 node.set_style(ns2)84 else:85 node.set_style(ns1)86 else:87 node.set_style(ns2)88 for node in t2.traverse():89 if not node.is_leaf():90 # Get leaf names for a "node"91 names = map(lambda n: n.name, node.iter_leaves())92 names.sort()93 cladename = ",".join(names)94 if clades[cladename] == 2:95 node.set_style(ns2)96 else:97 node.set_style(ns1)98 else:99 node.set_style(ns2)100 # print final tree101 t1.render(outputfile1 + ".svg", tree_style=ts)102 t2.render(outputfile2 + ".svg", tree_style=ts)103# print outgroup, minimal104if __name__ == "__main__":105 main(sys.argv[1:])

Full Screen

Full Screen

__init__.py

Source:__init__.py Github

copy

Full Screen

1from typing import Any, Collection, Dict, Iterator, Tuple2from collections import abc3def iter_leaves(node: Any, prefix: Collection[Any] = ()) -> Iterator[Tuple[Any, Any]]:4 """5 Iterate over the leaf nodes in a tree structure, paired with the path to reach them.6 Instances of abc.Mapping and abc.Collection (excepting strings) are interpreted as7 branches, and all other values are treated as leaves.8 """9 if isinstance(node, abc.Mapping):10 for key, value in node.items():11 yield from iter_leaves(value, prefix + (key,))12 elif isinstance(node, abc.Collection) and not isinstance(13 node, (str, bytes, bytearray)14 ):15 for key, value in enumerate(node):16 yield from iter_leaves(value, prefix + (key,))17 else:18 yield prefix, node19def flatten(obj: Any, separator: str = "/") -> Dict[str, Any]:20 """21 Iterate over the leaf nodes in a tree structure, producing a single flat dictionary22 with string keys and atomic values.23 """...

Full Screen

Full Screen

test_shape.py

Source:test_shape.py Github

copy

Full Screen

...6 "d": [3, 4],7}8def test_iter_leaves_on_singletons():9 for singleton in [1, False, None, "a", b"b"]:10 assert list(iter_leaves(singleton)) == [((), singleton)]11def test_iter_leaves_on_examples():12 assert list(iter_leaves(example_list)) == [13 ((0,), 1),14 ((1, "b"), 2),15 ((2, 0), 3),16 ((2, 1, "d"), 4),17 ]18 assert list(iter_leaves(example_dict)) == [19 (("a",), 1),20 (("b", "c"), 2),21 (("d", 0), 3),22 (("d", 1), 4),23 ]24def test_flatten():25 assert flatten(example_list) == {"0": 1, "1/b": 2, "2/0": 3, "2/1/d": 4}...

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