def _mktree(tree): """Given a tree, return a list of (path, opts) tuples with opts applied hiearchically, i.e. opts specified at a node also get applied to subnodes (unless later overridden)""" tps = [tp for tp in treant.paths_preorder(tree)] # construct two parallel lists: paths, and opts of each path paths = [_path(tp) for tp in tps] opts = [_opts(tp) for tp in tps] return zip(paths, opts)
def test_paths_preorder(): nodes = ['/', ['opt', 'framed', 'mcv']] t = tree(nodes) root = get(t, ['/']) opt = get(t, ['/', 'opt']) framed = get(t, ['/', 'opt', 'framed']) mcv = get(t, ['/', 'opt', 'mcv']) paths = [p for p in paths_preorder(t)] eq_(paths, [[root], [root, opt], [root, opt, framed], [root, opt, mcv]])
def paths(tree): # list of tpaths, i.e. list of (list of nodes) tps = [tp for tp in treant.paths_preorder(tree)] return [_path(tp) for tp in tps]