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
async def test_available_port_ref(num_mock_port1): port_expr = MockPortRef(num_mock_port1) expr = various.AvailableFunction([port_expr]) assert await expr.eval() == 1 num_mock_port1.set_last_read_value(16) assert await expr.eval() == 1 port_expr = MockPortRef(None, port_id='some-id') expr = various.AvailableFunction([port_expr]) assert await expr.eval() == 0
async def test_available_literal(literal_three, literal_false): expr = various.AvailableFunction([literal_three]) assert await expr.eval() == 1 expr = various.AvailableFunction([literal_false]) assert await expr.eval() == 1