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

    return_value = OrderedDict([(
        "/dev1234/demods/0/impedance",
        {
            "timestamp": array("q", [3880906635]),
            "value": array("l", [123]),
        },
    )])
    connection.get.side_effect = [TypeError(), return_value]
    assert tree.demods()[tree.demods[0].impedance] == 123

    connection.get.side_effect = [TypeError(), RuntimeError(), return_value]
    assert tree.demods()[tree.demods[0].impedance] == 123

    connection.get.side_effect = [RuntimeError(), return_value]
    assert tree.demods()[tree.demods[0].impedance] == 123
Exemplo n.º 2
0
def test_get_wildcard(connection):
    tree = NodeTree(connection, "DEV1234")

    connection.get.return_value = OrderedDict([(
        "/dev1234/demods/0/impedance",
        {
            "timestamp": array("q", [3880906635]),
            "value": array("l", [123]),
        },
    )])
    result = tree.demods()
    assert result[tree.demods[0].impedance] == 123
    connection.get.assert_called_with("/dev1234/demods",
                                      settingsonly=False,
                                      flat=True)

    # deep includes the timestamp
    result = tree.demods(deep=True)
    assert result[tree.demods[0].impedance] == (3880906635, 123)

    # nested dict
    result = tree.demods(flat=False)
    assert isinstance(result, OrderedDict)

    # nested dict
    result = tree.demods["*"].impedance(flat=False)
    assert isinstance(result, OrderedDict)

    # invalid node
    with pytest.raises(KeyError) as e_info:
        tree.invalid()

    # HF2 support
    connection.get.return_value = OrderedDict([("/dev1234/demods/0/impedance",
                                                nparray([125]))])
    result = tree.demods()
    assert result[tree.demods[0].impedance] == 125
    connection.get.assert_called_with("/dev1234/demods",
                                      settingsonly=False,
                                      flat=True)

    result = tree.demods(deep=True)
    assert result[tree.demods[0].impedance] == (None, 125)

    connection.get.return_value = OrderedDict([(
        "/dev1234/demods/0/impedance",
        {
            "timestamp": array("q", [3880906635]),
            "x": array("l", [123]),
            "y": array("l", [123]),
        },
    )])
    result = tree.demods()
    assert (result[tree.demods[0].impedance] ==
            connection.get.return_value["/dev1234/demods/0/impedance"])
    connection.get.assert_called_with("/dev1234/demods",
                                      settingsonly=False,
                                      flat=True)