Esempio n. 1
0
def test_isleaf():
    node = Node("0")
    sub_node = Node("1")
    node.append(sub_node)

    assert not node.isleaf
    assert sub_node.isleaf
Esempio n. 2
0
def test_full_name():
    node = Node("0")
    sub_node = Node("1")
    node.append(sub_node)

    assert node.full_name == "0"
    assert sub_node.full_name == "0/1"
Esempio n. 3
0
def test_attr():
    node = Node("0")
    sub_node = Node("1")
    node.append(sub_node)

    assert node.children[0] is sub_node
    assert sub_node.parent is node
Esempio n. 4
0
def test_isroot():
    node = Node("0")
    sub_node = Node("1")
    node.append(sub_node)

    assert node.isroot
    assert not sub_node.isroot
Esempio n. 5
0
def test_or(simple_node):
    node = Node("0")
    node.append("a")

    result_node = simple_node | node
    assert result_node is simple_node
    assert result_node.children["a"].name == "a"
Esempio n. 6
0
def test_append(simple_node):
    node = Node("1")
    node.append("a")
    assert node.children[0].name == "a"

    simple_node.append(node)
    assert simple_node["1"].children.named_lists[0][-1].name == "a"
Esempio n. 7
0
def test_root():
    node = Node("0")
    sub_node = Node("1")
    node.append(sub_node)

    assert sub_node.root is node
Esempio n. 8
0
def test_init_attr(name):
    node = Node(name)
    assert node.name == name
    assert node.parent is None
    assert len(node.children) == 0
Esempio n. 9
0
def test_merge(simple_node):
    node = Node("0")
    node.append("a")

    simple_node.merge(node)
    assert simple_node.children.named_lists[0][-1].name == "a"
Esempio n. 10
0
def test_from_names():
    node = Node.from_names(["0", "1", "3"])
    leaf = node.leafs[0]
    assert leaf.full_name == "0/1/3"
Esempio n. 11
0
def test_as_node(obj):
    node = Node.as_node(obj)
    assert isinstance(node, Node)
    assert node.name == "0"
Esempio n. 12
0
def test_lt(simple_node):
    node = Node("1")
    node.extend(["3", "4"])
    assert node < simple_node
Esempio n. 13
0
def test_eq(simple_node):
    node = Node("1")
    node.extend(["3", "4"])
    assert node == simple_node["1"]
Esempio n. 14
0
def test_contains(simple_node):
    node = Node("1")
    node.extend(["3", "4"])
    assert node in simple_node
Esempio n. 15
0
def simple_node():
    node = Node("0")
    node.extend(["1", "2"])
    node["1"].extend(["3", "4"])

    return node
Esempio n. 16
0
def test_leafs():
    node = Node("0")
    node.extend(["1", "2"])

    assert len(node.leafs) == 2
Esempio n. 17
0
def test_from_full_names():
    node = Node.from_full_name("0/1/3")
    leaf = node.leafs[0]
    assert leaf.full_name == "0/1/3"
Esempio n. 18
0
    assert node == simple_node["1"]


def test_lt(simple_node):
    node = Node("1")
    node.extend(["3", "4"])
    assert node < simple_node


def test_copy(simple_node):
    node = simple_node.copy()
    assert node is not simple_node
    assert node == simple_node


@pytest.mark.parametrize("obj", [0, "0", Node("0")])
def test_as_node(obj):
    node = Node.as_node(obj)
    assert isinstance(node, Node)
    assert node.name == "0"


def test_from_names():
    node = Node.from_names(["0", "1", "3"])
    leaf = node.leafs[0]
    assert leaf.full_name == "0/1/3"


def test_from_full_names():
    node = Node.from_full_name("0/1/3")
    leaf = node.leafs[0]