Beispiel #1
0
def test_lookup_node_in():
    node = LookupNode()
    leaf1 = LookupLeaf(id__in=[0, 1])
    leaf2 = LookupLeaf(id__in=[1, 2])
    node.add_child(leaf1)
    node.add_child(leaf2)
    assert len(node.children) == 2

    mock0 = MockId(0)
    mock1 = MockId(1)
    mock2 = MockId(2)
    assert node.op == 'and'
    assert not node.evaluate(mock0)
    assert node.evaluate(mock1)
    assert not node.evaluate(mock2)

    assert not node.negate
    assert (~node).evaluate(mock0)
    assert not (~node).evaluate(mock1)
    assert (~node).evaluate(mock2)

    node.op = 'or'
    assert node.op == 'or'
    assert node.evaluate(mock0)
    assert node.evaluate(mock1)
    assert node.evaluate(mock2)

    assert (~node).negate
    assert (~node).evaluate(mock0)
    assert not (~node).evaluate(mock1)
    assert (~node).evaluate(mock2)
Beispiel #2
0
def test_lookup_leaf_contains():
    leaf = LookupLeaf(str__contains='jina')
    mock0 = MockStr('hey jina how are you')
    assert leaf.evaluate(mock0)
    mock1 = MockStr('not here')
    assert not leaf.evaluate(mock1)
    mock2 = MockStr('hey jInA how are you')
    assert not leaf.evaluate(mock2)
Beispiel #3
0
def test_lookup_leaf_lte():
    leaf = LookupLeaf(id__lte=1)
    mock0 = MockId(0)
    assert leaf.evaluate(mock0)
    mock1 = MockId(1)
    assert leaf.evaluate(mock1)
    mock2 = MockId(2)
    assert not leaf.evaluate(mock2)
Beispiel #4
0
def test_lookup_leaf_regex():
    leaf = LookupLeaf(str__regex='j*na')
    mock0 = MockStr('hey, juna is good')
    assert leaf.evaluate(mock0)
    mock1 = MockStr('hey, Oinja is the neural search solution')
    assert not leaf.evaluate(mock1)
    mock2 = MockStr('how is JiNa')
    assert not leaf.evaluate(mock2)
Beispiel #5
0
def test_lookup_leaf_iendswith():
    leaf = LookupLeaf(str__iendswith='jina')
    mock0 = MockStr('how is jina')
    assert leaf.evaluate(mock0)
    mock1 = MockStr('hey, jina is the neural search solution')
    assert not leaf.evaluate(mock1)
    mock2 = MockStr('how is JiNa')
    assert leaf.evaluate(mock2)
Beispiel #6
0
def test_lookup_leaf_exact_document_tags_complex():
    with Document() as doc:
        doc.tags['key1'] = {'key2': 'jina'}
        leaf = LookupLeaf(tags__key1__key2='jina')
        assert leaf.evaluate(doc)
        leaf = LookupLeaf(tags__key1__key2='not_jina')
        assert not leaf.evaluate(doc)
Beispiel #7
0
def test_lookup_leaf_exact_document_tags():
    with Document() as doc:
        doc.tags['label'] = 'jina'
        leaf = LookupLeaf(tags__label='jina')
        assert leaf.evaluate(doc)
        leaf = LookupLeaf(tags__label='not_jina')
        assert not leaf.evaluate(doc)
Beispiel #8
0
def test_lookup_leaf_neq():
    leaf = LookupLeaf(id__neq=1)
    mock1 = MockId(1)
    assert not leaf.evaluate(mock1)
    mock2 = MockId(2)
    assert leaf.evaluate(mock2)
Beispiel #9
0
def test_lookup_leaf_None():
    leaf = LookupLeaf(id=3)
    mock0 = MockId(3)
    assert leaf.evaluate(mock0)
    mock1 = MockId(4)
    assert not leaf.evaluate(mock1)
Beispiel #10
0
def test_lookup_leaf_in():
    leaf = LookupLeaf(id__in=[0, 1, 2, 3])
    mock0 = MockId(3)
    assert leaf.evaluate(mock0)
    mock1 = MockId(4)
    assert not leaf.evaluate(mock1)