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_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. 3
0
def test_node_addChild():
    root = Node()
    child_1 = Node()

    root.addChild(child_1)
    assert child_1 == root.child(0)
Esempio n. 4
0
def test_node_typeInfo():
    node = Node()
    assert node.typeInfo() == 'root'
Esempio n. 5
0
def test_node_attrs():
    node = Node()
    assert node.attrs() == {'description': '', 'name': 'unknown'}
Esempio n. 6
0
def test_node_has_attrs():
    assert Node().attrs() is not None
Esempio n. 7
0
def test_node_setData():
    root = Node()
    root.setData(col.NAME, "my_nam e")  #It should remove the space
    root.setData(col.TYPE_INFO, "typeinfo is hard coded")
    root.setData(col.DESCRIPTION, "my description")

    assert root.data(col.NAME) == "my_name"
    assert root.data(col.TYPE_INFO) == "root"
    assert root.data(col.DESCRIPTION) == "my description"
Esempio n. 8
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. 9
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. 10
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. 11
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)