Skip to content

Commit

Permalink
test: add test to filterql with tags content
Browse files Browse the repository at this point in the history
  • Loading branch information
JoanFM committed Sep 11, 2020
1 parent 6bf09b3 commit 3f0c033
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions tests/unit/drivers/querylang/test_querylang_drivers.py
@@ -1,6 +1,7 @@
from jina.executors.crafters import BaseSegmenter
from jina.flow import Flow
from jina.proto import jina_pb2
from google.protobuf import json_format


def random_docs(num_docs):
Expand All @@ -18,7 +19,7 @@ def random_docs(num_docs):
yield d


def random_docs_with_chunks():
def random_docs_to_chunk():
d1 = jina_pb2.Document()
d1.id = 1
d1.text = 'chunk1 chunk2'
Expand All @@ -29,6 +30,19 @@ def random_docs_with_chunks():
yield d2


def random_docs_with_tags():
d1 = jina_pb2.Document()
d1.id = 1
d1.text = 'a'
d1.tags.update({'id': 1})
yield d1
d2 = jina_pb2.Document()
d2.id = 2
d2.tags.update({'id': 2})
d2.text = 'b'
yield d2


class DummySegmenter(BaseSegmenter):

def craft(self, text, *args, **kwargs):
Expand Down Expand Up @@ -102,6 +116,19 @@ def validate(req):
f.index(random_docs(10), output_fn=validate, callback_on_body=True)


def test_filter_ql_in_tags():
def validate(req):
assert len(req.docs) == 1
assert req.docs[0].id == 2
assert json_format.MessageToDict(req.docs[0].tags)['id'] == 2

f = (Flow().add(
uses='- !FilterQL | {lookups: {tags__id: 2}}'))

with f:
f.index(random_docs_with_tags(), output_fn=validate, callback_on_body=True)


def test_filter_ql_modality_wrong_depth():
def validate(req):
# since no doc has modality mode2 they are all erased from the list of docs
Expand All @@ -112,7 +139,7 @@ def validate(req):
uses='- !FilterQL | {lookups: {modality: mode2}, granularity_range: [0, 1]}'))

with f:
f.index(random_docs_with_chunks(), output_fn=validate, callback_on_body=True)
f.index(random_docs_to_chunk(), output_fn=validate, callback_on_body=True)


def test_filter_ql_modality():
Expand All @@ -127,7 +154,7 @@ def validate(req):
uses='- !FilterQL | {lookups: {modality: mode2}, granularity_range: [1, 2]}'))

with f:
f.index(random_docs_with_chunks(), output_fn=validate, callback_on_body=True)
f.index(random_docs_to_chunk(), output_fn=validate, callback_on_body=True)


def test_filter_compose_ql():
Expand Down

0 comments on commit 3f0c033

Please sign in to comment.