def test_render_str(): """Render string cast.""" root = anytree.Node("root") s0 = anytree.Node("sub0", parent=root) anytree.Node("sub0B", parent=s0) anytree.Node("sub0A", parent=s0) anytree.Node("sub1", parent=root) r = anytree.RenderTree(root) expected = u"\n".join([ u"Node('/root')", u"├── Node('/root/sub0')", u"│ ├── Node('/root/sub0/sub0B')", u"│ └── Node('/root/sub0/sub0A')", u"└── Node('/root/sub1')", ]) eq_str(str(r), expected) r = anytree.RenderTree( root, childiter=lambda nodes: [n for n in nodes if len(n.name) < 5]) expected = u"\n".join([ u"Node('/root')", u"├── Node('/root/sub0')", u"└── Node('/root/sub1')", ]) eq_str(str(r), expected)
def test_dict_importer_node(): """Dict Importer.""" importer = DictImporter(Node) exporter = DictExporter() refdata = { 'name': 'root', 'children': [{ 'name': 'sub0', 'children': [{ 'name': 'sub0B' }, { 'name': 'sub0A' }] }, { 'name': 'sub1', 'children': [{ 'name': 'sub1A' }, { 'name': 'sub1B' }, { 'name': 'sub1C', 'children': [{ 'name': 'sub1Ca' }] }] }] } data = deepcopy(refdata) root = importer.import_(data) eq_(data, refdata) eq_(exporter.export(root), data) r = RenderTree(root) expected = u"\n".join([ u"Node('/root')", u"├── Node('/root/sub0')", u"│ ├── Node('/root/sub0/sub0B')", u"│ └── Node('/root/sub0/sub0A')", u"└── Node('/root/sub1')", u" ├── Node('/root/sub1/sub1A')", u" ├── Node('/root/sub1/sub1B')", u" └── Node('/root/sub1/sub1C')", u" └── Node('/root/sub1/sub1C/sub1Ca')", ]) eq_str(str(r), expected)
def test_render_str(): """Render string cast.""" root = anytree.Node("root") s0 = anytree.Node("sub0", parent=root) anytree.Node("sub0B", parent=s0) anytree.Node("sub0A", parent=s0) anytree.Node("sub1", parent=root) r = anytree.RenderTree(root) expected = u"\n".join([ u"Node('/root')", u"├── Node('/root/sub0')", u"│ ├── Node('/root/sub0/sub0B')", u"│ └── Node('/root/sub0/sub0A')", u"└── Node('/root/sub1')", ]) eq_str(str(r), expected)