当前位置: 首页>>代码示例>>Python>>正文


Python anytree.NodeMixin方法代码示例

本文整理汇总了Python中anytree.NodeMixin方法的典型用法代码示例。如果您正苦于以下问题:Python anytree.NodeMixin方法的具体用法?Python anytree.NodeMixin怎么用?Python anytree.NodeMixin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在anytree的用法示例。


在下文中一共展示了anytree.NodeMixin方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_dict_exporter_mixin

# 需要导入模块: import anytree [as 别名]
# 或者: from anytree import NodeMixin [as 别名]
def test_dict_exporter_mixin():
    """Dict Exporter."""
    class MyClass(NodeMixin):

        def __init__(self, foo, parent=None):
            super(MyClass, self).__init__()
            self.foo = foo
            self.parent = parent

    root = MyClass('root')
    s0 = MyClass('s0', parent=root)
    s0b = MyClass('s0b', parent=s0)
    s0a = MyClass('s0a', parent=s0)
    s1 = MyClass('s1', parent=root)
    s1a = MyClass('s1a', parent=s1)
    s1b = MyClass('s1b', parent=s1)
    s1c = MyClass('s1c', parent=s1)
    s1ca = MyClass('s1ca', parent=s1c)

    exporter = DictExporter()
    eq_(exporter.export(root),
        {'foo': 'root', 'children': [
            {'foo': 's0', 'children': [
                {'foo': 's0b'},
                {'foo': 's0a'}
            ]},
            {
                'foo': 's1', 'children': [
                    {'foo': 's1a'},
                    {'foo': 's1b'},
                    {'foo': 's1c', 'children': [
                        {'foo': 's1ca'}
                    ]}
                ]}
        ]}
        ) 
开发者ID:c0fec0de,项目名称:anytree,代码行数:38,代码来源:test_dictexporter.py

示例2: test_node_parent_error

# 需要导入模块: import anytree [as 别名]
# 或者: from anytree import NodeMixin [as 别名]
def test_node_parent_error():
    """Node Parent Error."""
    with assert_raises(TreeError, "Parent node 'parent' is not of type 'NodeMixin'."):
        Node("root", "parent") 
开发者ID:c0fec0de,项目名称:anytree,代码行数:6,代码来源:test_node.py

示例3: test_node_children_type

# 需要导入模块: import anytree [as 别名]
# 或者: from anytree import NodeMixin [as 别名]
def test_node_children_type():

    root = Node("root")
    with assert_raises(TreeError, "Cannot add non-node object 'string'. It is not a subclass of 'NodeMixin'."):
        root.children = ["string"] 
开发者ID:c0fec0de,项目名称:anytree,代码行数:7,代码来源:test_node.py

示例4: test_parent

# 需要导入模块: import anytree [as 别名]
# 或者: from anytree import NodeMixin [as 别名]
def test_parent():
    """Parent attribute."""
    foo = NodeMixin()
    assert foo.parent is None 
开发者ID:c0fec0de,项目名称:anytree,代码行数:6,代码来源:test_node.py

示例5: test_any_node_parent_error

# 需要导入模块: import anytree [as 别名]
# 或者: from anytree import NodeMixin [as 别名]
def test_any_node_parent_error():
    """Any Node Parent Error."""

    with assert_raises(TreeError, "Parent node 'r' is not of type 'NodeMixin'."):
        AnyNode("r") 
开发者ID:c0fec0de,项目名称:anytree,代码行数:7,代码来源:test_node.py

示例6: test_tuple

# 需要导入模块: import anytree [as 别名]
# 或者: from anytree import NodeMixin [as 别名]
def test_tuple():
    """Tuple as parent."""
    with assert_raises(TreeError, "Parent node (1, 0, 3) is not of type 'NodeMixin'."):
        Node((0, 1, 2), parent=(1, 0, 3)) 
开发者ID:c0fec0de,项目名称:anytree,代码行数:6,代码来源:test_node.py

示例7: test_tuple_as_children

# 需要导入模块: import anytree [as 别名]
# 或者: from anytree import NodeMixin [as 别名]
def test_tuple_as_children():
    """Tuple as children."""
    n = Node('foo')
    with assert_raises(TreeError, "Cannot add non-node object (0, 1, 2). It is not a subclass of 'NodeMixin'."):
        n.children = [(0, 1, 2)] 
开发者ID:c0fec0de,项目名称:anytree,代码行数:7,代码来源:test_node.py

示例8: __new__

# 需要导入模块: import anytree [as 别名]
# 或者: from anytree import NodeMixin [as 别名]
def __new__(cls, *args, **kwargs):
        for attr in SPECIAL_METHODS:
            setattr(cls, attr, functools.partial(prevent_access, attr))
        instance = super(NodeMixin, cls).__new__(cls)
        return instance 
开发者ID:c0fec0de,项目名称:anytree,代码行数:7,代码来源:test_special_methods_access.py


注:本文中的anytree.NodeMixin方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。