-
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.
feat(jaml): add keyword jtype to represent YAML tag (#2044)
* feat(jaml): add keyword jtype to represent YAML tag * feat(parser): add description field * feat(jaml): add keyword jtype to represent YAML tag
- Loading branch information
Showing
4 changed files
with
230 additions
and
9 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
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
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,183 @@ | ||
import pytest | ||
|
||
from jina.executors import BaseExecutor | ||
from jina.jaml import JAML | ||
|
||
|
||
class MyExecutor(BaseExecutor): | ||
pass | ||
|
||
|
||
def test_non_empty_reg_tags(): | ||
assert JAML.registered_tags() | ||
assert 'BaseExecutor' in JAML.registered_tags() | ||
|
||
|
||
@pytest.mark.parametrize('include_unk, expected', [ | ||
(True, ''' | ||
jtype: BaseExecutor {} | ||
jtype: Blah {} | ||
''' | ||
), | ||
(False, ''' | ||
jtype: BaseExecutor {} | ||
!Blah {} | ||
''' | ||
) | ||
]) | ||
def test_include_unknown(include_unk, expected): | ||
y = ''' | ||
!BaseExecutor {} | ||
!Blah {} | ||
''' | ||
assert JAML.escape(y, include_unknown_tags=include_unk).strip() == expected.strip() | ||
|
||
|
||
@pytest.mark.parametrize('original, escaped', | ||
[( | ||
''' | ||
!BaseExecutor {} | ||
!Blah {} | ||
!MyExecutor {} | ||
''', | ||
''' | ||
jtype: BaseExecutor {} | ||
!Blah {} | ||
jtype: MyExecutor {} | ||
''' | ||
), ( | ||
''' | ||
!BaseExecutor | ||
with: | ||
a: 123 | ||
b: BaseExecutor | ||
jtype: unknown-blah | ||
''', | ||
''' | ||
jtype: BaseExecutor | ||
with: | ||
a: 123 | ||
b: BaseExecutor | ||
jtype: unknown-blah | ||
''' | ||
), ( | ||
''' | ||
!CompoundIndexer | ||
components: | ||
- !NumpyIndexer | ||
with: | ||
index_filename: vec.gz | ||
metric: euclidean | ||
metas: | ||
name: vecidx | ||
- !BinaryPbIndexer | ||
with: | ||
index_filename: doc.gz | ||
metas: | ||
name: docidx | ||
metas: | ||
name: indexer | ||
workspace: $JINA_WORKSPACE | ||
''', | ||
''' | ||
jtype: CompoundIndexer | ||
components: | ||
- jtype: NumpyIndexer | ||
with: | ||
index_filename: vec.gz | ||
metric: euclidean | ||
metas: | ||
name: vecidx | ||
- jtype: BinaryPbIndexer | ||
with: | ||
index_filename: doc.gz | ||
metas: | ||
name: docidx | ||
metas: | ||
name: indexer | ||
workspace: $JINA_WORKSPACE | ||
''' | ||
), ( | ||
''' | ||
!CompoundIndexer | ||
metas: | ||
workspace: $TMP_WORKSPACE | ||
components: | ||
- !NumpyIndexer | ||
with: | ||
metric: euclidean | ||
index_filename: vec.gz | ||
metas: | ||
name: vecidx # a customized name | ||
- !BinaryPbIndexer | ||
with: | ||
index_filename: chunk.gz | ||
metas: | ||
name: kvidx # a customized name | ||
requests: | ||
on: | ||
IndexRequest: | ||
- !VectorIndexDriver | ||
with: | ||
executor: NumpyIndexer | ||
filter_by: $FILTER_BY | ||
- !KVIndexDriver | ||
with: | ||
executor: BinaryPbIndexer | ||
filter_by: $FILTER_BY | ||
SearchRequest: | ||
- !VectorSearchDriver | ||
with: | ||
executor: NumpyIndexer | ||
filter_by: $FILTER_BY | ||
- !KVSearchDriver | ||
with: | ||
executor: BinaryPbIndexer | ||
filter_by: $FILTER_BY | ||
''', | ||
''' | ||
jtype: CompoundIndexer | ||
metas: | ||
workspace: $TMP_WORKSPACE | ||
components: | ||
- jtype: NumpyIndexer | ||
with: | ||
metric: euclidean | ||
index_filename: vec.gz | ||
metas: | ||
name: vecidx # a customized name | ||
- jtype: BinaryPbIndexer | ||
with: | ||
index_filename: chunk.gz | ||
metas: | ||
name: kvidx # a customized name | ||
requests: | ||
on: | ||
IndexRequest: | ||
- jtype: VectorIndexDriver | ||
with: | ||
executor: NumpyIndexer | ||
filter_by: $FILTER_BY | ||
- jtype: KVIndexDriver | ||
with: | ||
executor: BinaryPbIndexer | ||
filter_by: $FILTER_BY | ||
SearchRequest: | ||
- jtype: VectorSearchDriver | ||
with: | ||
executor: NumpyIndexer | ||
filter_by: $FILTER_BY | ||
- jtype: KVSearchDriver | ||
with: | ||
executor: BinaryPbIndexer | ||
filter_by: $FILTER_BY | ||
''' | ||
), | ||
]) | ||
def test_escape(original, escaped): | ||
assert JAML.escape(original, include_unknown_tags=False).strip() == escaped.strip() | ||
assert JAML.unescape(JAML.escape(original, include_unknown_tags=False), | ||
include_unknown_tags=False).strip() == original.strip() |
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