Пример #1
0
async def test_available_func(num_mock_port1):
    port_expr = MockPortValue(num_mock_port1)
    acc_expr = MockExpression(13)
    func_expr = various.AccFunction([port_expr, acc_expr])
    expr = various.AvailableFunction([func_expr])
    assert await expr.eval(context={
        'port_values': {
            'nid1': num_mock_port1.get_last_read_value()
        }
    }) == 0

    num_mock_port1.set_last_read_value(16)
    assert await expr.eval(context={
        'port_values': {
            'nid1': num_mock_port1.get_last_read_value()
        }
    }) == 1

    port_expr = MockPortValue(None, port_id='some-id')
    func_expr = various.AccFunction([port_expr, acc_expr])
    expr = various.AvailableFunction([func_expr])
    assert await expr.eval(context={
        'port_values': {
            'nid1': num_mock_port1.get_last_read_value()
        }
    }) == 0
Пример #2
0
async def test_available_port_value(num_mock_port1):
    port_expr = MockPortValue(num_mock_port1)
    expr = various.AvailableFunction([port_expr])
    assert await expr.eval() == 0

    num_mock_port1.set_last_read_value(16)
    assert await expr.eval() == 1

    port_expr = MockPortValue(None, port_id='some-id')
    expr = various.AvailableFunction([port_expr])
    assert await expr.eval() == 0
Пример #3
0
async def test_falling(num_mock_port1):
    port_expr = MockPortValue(num_mock_port1)
    expr = various.FallingFunction([port_expr])

    num_mock_port1.set_last_read_value(13)
    assert await expr.eval(context={
        'port_values': {
            'nid1': num_mock_port1.get_last_read_value()
        }
    }) == 0
    assert await expr.eval(context={
        'port_values': {
            'nid1': num_mock_port1.get_last_read_value()
        }
    }) == 0

    num_mock_port1.set_last_read_value(10)
    assert await expr.eval(context={
        'port_values': {
            'nid1': num_mock_port1.get_last_read_value()
        }
    }) == 1
    assert await expr.eval(context={
        'port_values': {
            'nid1': num_mock_port1.get_last_read_value()
        }
    }) == 0

    num_mock_port1.set_last_read_value(14)
    assert await expr.eval(context={
        'port_values': {
            'nid1': num_mock_port1.get_last_read_value()
        }
    }) == 0
Пример #4
0
async def test_default(num_mock_port1):
    port_expr = MockPortValue(num_mock_port1)
    def_expr = MockExpression(13)
    expr = various.DefaultFunction([port_expr, def_expr])
    assert await expr.eval() == 13

    num_mock_port1.set_last_read_value(16)
    assert await expr.eval() == 16