def test_build_cycle_references(self, testcase_cycle_references_tree_items): items = testcase_cycle_references_tree_items tree = Tree.build(items, 'name', 'parent') print('', tree, sep='\n') with raises(RecursionError): tree.render()
def testcase_simple_tree(self, name_handle, children_handle, render_style, root_item): """Tree with children references: (Tree() object, tree representation string, render style used)""" representation = { 'strict': ''' f └── e ├── a ├── b │ └── c └── d ''', 'smooth': ''' f ╰── e ├── a ├── b │ ╰── c ╰── d ''', 'indent': ''' f e a b c d ''', } tree = Tree.convert(root_item, name_handle, children_handle) return tree, self.strip_indents(representation[render_style], 4), render_style
def get_server_dir_info(): tree = Tree() tree.walk(basedir) return tree.retString
def test_build_multiple_roots(self, testcase_multiple_roots_tree_items): items = testcase_multiple_roots_tree_items with raises( RuntimeError, match='Given collection of items is not a connected graph!'): Tree.build(items, 'name', 'parent')
def test_build_missing_non_leaves_items(self, testcase_missing_tree_items, items_order): items, rendered = testcase_missing_tree_items tree = Tree.build(items, 'name', 'parent') print('', tree, sep='\n') assert tree.render() == rendered
def test_build_chain_layout(self, testcase_chain_layout_tree_items): items, rendered = testcase_chain_layout_tree_items tree = Tree.build(items, 'name', 'parent') print('', tree, sep='\n') assert tree.render() == rendered
def test_build_single_item(self, testcase_single_item_tree_items): items, rendered = testcase_single_item_tree_items tree = Tree.build(items, 'name', 'parent') print('', tree, sep='\n') assert tree.render() == rendered
def test_build_empty(self, testcase_empty_tree_items): items, rendered = testcase_empty_tree_items tree = Tree.build(items, 'name', 'parent') print('', tree.render(empty=rendered), sep='\n') assert tree.render(empty=rendered) == rendered
def test_build_exceptions(self, testcase_exception_tree_items): items, rendered = testcase_exception_tree_items tree = Tree.build(items=items, naming='__name__', parent='__base__') print('', tree, sep='\n') assert tree.render() == rendered
def test_invalid_children_handle(self, name_handle, children_handle, root_item): err_msg = r"children handle returned invalid result: expected List\[Item\], got 0" with raises(RuntimeError, match=err_msg): Tree.convert(root_item, name_handle, children_handle)
def testcase_single_item_tree(self, name_handle, children_handle): """Tree of with 1 single node: (Tree() object, rendered tree string)""" item = self.Item('item', None) return Tree.convert(item, name_handle, children_handle), 'item'
def testcase_empty_tree(self, empty_arg): """Tree with an empty root: (Tree() object, empty tree representation string, 'empty' argument)""" result = empty_arg return Tree(None), result, empty_arg