當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。