Esempio n. 1
0
def test_node_parent():
    root = Node()
    child_1 = Node()

    root.addChild(child_1)

    assert root.parent() == None
    assert child_1.parent() == root
Esempio n. 2
0
def test_node_insertChild():
    root = Node()
    child_1 = Node()
    child_2 = Node()
    child_3 = Node()

    root.addChild(child_1)
    root.addChild(child_3)
    root.insertChild(1, child_2)

    assert child_1 == root.child(0)
    assert child_2 == root.child(1)
    assert child_3 == root.child(2)
Esempio n. 3
0
def test_node_row():
    root = Node()
    child_1 = Node()
    child_2 = Node()
    child_3 = Node()

    root.addChild(child_1)
    root.addChild(child_2)
    root.addChild(child_3)

    assert root.row(
    ) == 0  #FIXME Not sure if we should test this to be 0 or None
    assert child_1.row() == 0
    assert child_2.row() == 1
    assert child_3.row() == 2
Esempio n. 4
0
def test_node_children():
    root = Node()
    child_1 = Node()
    child_2 = Node()
    child_3 = Node()

    root.addChild(child_1)
    root.addChild(child_2)
    root.addChild(child_3)

    children = root.children()

    assert len(children) == 3
    assert children[1] == child_2
    assert root.childCount() == 3
Esempio n. 5
0
def test_node_removeChild():
    root = Node()
    child_1 = Node()
    child_2 = Node()
    child_3 = Node()

    root.addChild(child_1)
    root.addChild(child_2)
    root.addChild(child_3)

    root.removeChild(1)
    assert root.childCount() == 2

    root.removeChild(1)
    assert root.childCount() == 1

    root.removeChild(1)  #There's only a child at position 0
    assert root.childCount() == 1

    root.removeChild(0)
    assert root.childCount() == 0
Esempio n. 6
0
def test_node_asJSON_and_load():
    root = Node()
    child_1 = Node()
    child_2 = Node()

    root.addChild(child_1)
    root.addChild(child_2)

    standard = json.loads('''{
                        "children": [
                            {
                                "children": [],
                                "description": "",
                                "name": "unknown",
                                "type_info": "root"
                            },
                            {
                                "children": [],
                                "description": "",
                                "name": "unknown_new",
                                "type_info": "root"
                            }
                        ],
                        "description": "",
                        "name": "unknown",
                        "type_info": "root"
                    }''')

    new = json.loads('''{
                        "description": "my desc.",
                        "name": "A_name",
                        "type_info": "root"
                    }''')

    assert standard == json.loads(root.asJSON())

    #This will only load the properties for the node, the recursion in in the model
    root.loadAttrs(new)
    assert root.name == "A_name"
    assert root.description == "my desc."
Esempio n. 7
0
def test_node_addChild():
    root = Node()
    child_1 = Node()

    root.addChild(child_1)
    assert child_1 == root.child(0)