-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add tests for batching executors
- Loading branch information
Showing
4 changed files
with
93 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
48 changes: 48 additions & 0 deletions
48
tests/integration/executors_batching/test_craft_executors_batching.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from jina.executors.crafters import BaseCrafter | ||
from jina.executors.decorators import batching, batching_multi_input | ||
from jina import Document | ||
from jina.types.sets import DocumentSet | ||
|
||
|
||
class DummyCrafterText(BaseCrafter): | ||
|
||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
|
||
@batching(batch_size=3) | ||
def craft(self, text, *args, **kwargs): | ||
assert len(text) == 3 | ||
return [{'text': f'{txt}-crafted'} for txt in text] | ||
|
||
|
||
def test_batching_text_single(): | ||
docs = DocumentSet([Document(text=f'text-{i}') for i in range(15)]) | ||
texts, _ = docs._extract_docs('text') | ||
|
||
crafter = DummyCrafterText() | ||
crafted_docs = crafter.craft(texts) | ||
for i, crafted_doc in enumerate(crafted_docs): | ||
assert crafted_doc['text'] == f'text-{i}-crafted' | ||
|
||
|
||
class DummyCrafterTextId(BaseCrafter): | ||
|
||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
|
||
@batching(batch_size=3) | ||
def craft(self, text, id, *args, **kwargs): | ||
assert len(text) == 3 | ||
assert len(id) == 3 | ||
return [{'text': f'{txt}-crafted', 'id': i} for i, txt in zip(id, text)] | ||
|
||
|
||
def test_batching_text_multi(): | ||
docs = DocumentSet([Document(text=f'text-{i}') for i in range(15)]) | ||
text_ids, _ = docs._extract_docs(*['text', 'id']) | ||
|
||
crafter = DummyCrafterTextId() | ||
crafted_docs = crafter.craft(text_ids) | ||
|
||
for i, crafted_doc in enumerate(crafted_docs): | ||
assert crafted_doc['text'] == f'text-{i}-crafted' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters