Exemplo n.º 1
0
def test_compile_expression_nxor():
    func = compile_ast(
        parse({
            'nxor': [{
                'has': 'application'
            }, {
                'in': [('weight', ), [1, 2, 3]]
            }]
        }))
    assert not func(node_0)
    assert func(node_1)
    assert func(node_2)
Exemplo n.º 2
0
def test_explain():
    result = explain(
        parse({
            'not': {
                'has': ['group']
            },
            'has': 'application',
            'eq': [('_link', 'other', 'weight'), 2]
        }))
    assert result == {
        'and': [{
            'not': [{
                'has': ['group']
            }]
        }, {
            'has': ['application']
        }, {
            'eq': [('_link', 'other', 'weight'), 2]
        }]
    }
Exemplo n.º 3
0
def test_compile_expression_lte_path():
    func = compile_ast(parse({'lte': [('_link', 'other', 'weight'), 2]}))
    assert func(node_2)
    func = compile_ast(parse({'lte': [('_link', 'other', 'weight'), 3]}))
    assert func(node_2)
Exemplo n.º 4
0
def test_compile_expression_gt_path():
    func = compile_ast(parse({'gt': [('_link', 'other', 'weight'), 1]}))
    assert func(node_2)
    func = compile_ast(parse({'gt': [('_link', 'other', 'weight'), 2]}))
    assert not func(node_2)
Exemplo n.º 5
0
def test_compile_expression_has_path():
    func = compile_ast(parse({'has': [('_link', 'other', 'weight')]}))
    assert not func(node_0)
    assert func(node_2)
Exemplo n.º 6
0
def test_compile_expression_has_dict():
    func = compile_ast(parse({'has': '_link'}))
    assert not func(node_0)
    assert func(node_2)
Exemplo n.º 7
0
def test_compile_expression_contains():
    func = compile_ast(parse({'contains': ['group', 'my']}))
    assert not func(node_0)
    assert func(node_1)
Exemplo n.º 8
0
def test_compile_expression_not_has():
    func = compile_ast(parse({'not': {'has': 'group'}}))
    assert func(node_0)
    assert not func(node_1)
Exemplo n.º 9
0
def test_compile_expression_has():
    func = compile_ast(parse({'has': 'application'}))
    assert func(node_0)
    assert func(node_1)
Exemplo n.º 10
0
def test_parse_raise_unknown_operator():
    with pytest.raises(ParserException):
        parse({'idontexistatall': ['_link', 'other', 'weight']})
Exemplo n.º 11
0
def test_parse_exception():
    with pytest.raises(ParserException):
        parse({'has': ['_link', 'other', 'weight']})
Exemplo n.º 12
0
def test_compile_expression_in_path():
    func = compile_ast(parse({'in': [('_link', 'other', 'weight'), [1, 2,
                                                                    3]]}))
    assert func(node_2)