Ejemplo n.º 1
0
def test_update_node(connection):
    tree = NodeTree(connection, "DEV1234")

    tree.update_node("demods/0/rate", {"Unit": "test"})
    assert tree.demods[0].rate.node_info.unit == "test"
    tree.update_node("demods/0/rate", {"Test": "test"})
    assert (next(iter(tree.get_node_info("demods/0/rate").values())).get(
        "Test", None) == "test")
    tree.update_node("demods/0/rate", {"Unit": "test2", "Test2": True})
    assert tree.demods[0].rate.node_info.unit == "test2"
    assert next(iter(tree.get_node_info("demods/0/rate").values())).get(
        "Test2", None)

    # new Node
    with pytest.raises(KeyError) as e_info:
        tree.update_node("/test", {"Node": "test"})
    assert e_info.value.args[0] == "/test"

    assert str(tree.test) == "/dev1234/test"
    tree.update_node("/test", {"Node": "test"}, add=True)
    tree.get_node_info(tree.test)
    assert tree.test.node_info["Node"] == "test"

    assert str(tree.demods[0].test) == "/dev1234/demods/0/test"
    tree.update_node("demods/0/test", {"Node": "test"}, add=True)
    assert str(tree.demods[0].test) == "test"

    tree.update_node("demods/0/rate", {"Properties": "Write"})
    with pytest.raises(Exception) as e_info:
        tree.demods[0].rate()
    tree.update_node("demods/0/rate", {"Properties": "Read"})
    with pytest.raises(Exception) as e_info:
        tree.demods[0].rate(12)

    with pytest.raises(RuntimeError) as e_info:
        tree.update_node("hello/*/world", {}, add=True)
Ejemplo n.º 2
0
def test_get_node_info(connection):
    tree = NodeTree(connection, "DEV1234")
    # raw get
    assert tree.get_node_info("demods/0/rate") == tree.get_node_info(
        tree.demods[0].rate)
    assert tree.get_node_info("/dev1234/demods/0/rate") == tree.get_node_info(
        tree.demods[0].rate)
    with pytest.raises(KeyError) as e_info:
        tree.get_node_info("zi/config/open")
    assert tree.get_node_info("/zi/config/open") == tree.get_node_info(
        tree.zi.config.open)
    with pytest.raises(KeyError) as e_info:
        tree.get_node_info("/demods/0/rate")
    assert e_info.value.args[0] == "/demods/0/rate"
    with pytest.raises(KeyError):
        tree.get_node_info("dev1234/demods/0/rate")
    with pytest.raises(KeyError) as e_info:
        tree.get_node_info("no/real/element")
    assert e_info.value.args[0] == "/dev1234/no/real/element"

    # raw get wildcards
    assert tree.get_node_info("demods/*/rate") == tree.get_node_info(
        "demods/?/rate")
    assert len(tree.get_node_info("demods/0/*")) > 1
    with pytest.raises(KeyError) as e_info:
        tree.get_node_info("demods/0/real/*")
    assert e_info.value.args[0] == "/dev1234/demods/0/real/*"
    with pytest.raises(KeyError) as e_info:
        tree.get_node_info("demod/0/*")
    assert e_info.value.args[0] == "/dev1234/demod/0/*"