Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test: test dynamic class creation with doubly nested schemas
Signed-off-by: Alaeddine Abdessalem <[email protected]>
  • Loading branch information
alaeddine-13 committed Aug 10, 2023
commit ba083a3be4d5b6ae52e543288a97b106151681be
9 changes: 9 additions & 0 deletions tests/units/util/test_create_dynamic_code_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@

@pytest.mark.parametrize('transformation', ['proto', 'json'])
def test_create_pydantic_model_from_schema(transformation):
class Nested2Doc(BaseDoc):
value: str

class Nested1Doc(BaseDoc):
nested: Nested2Doc

class CustomDoc(BaseDoc):
tensor: Optional[AnyTensor]
url: ImageUrl
Expand All @@ -26,6 +32,7 @@ class CustomDoc(BaseDoc):
u: Union[str, int]
lu: List[Union[str, int]] = [0, 1, 2]
tags: Optional[Dict[str, Any]] = None
nested: Nested1Doc

CustomDocCopy = create_pure_python_type_model(CustomDoc)
new_custom_doc_model = create_base_doc_from_schema(
Expand All @@ -43,6 +50,7 @@ class CustomDoc(BaseDoc):
single_text=TextDoc(text='single hey ha', embedding=np.zeros(2)),
u='a',
lu=[3, 4],
nested=Nested1Doc(nested=Nested2Doc(value='hello world')),
)
]
)
Expand Down Expand Up @@ -77,6 +85,7 @@ class CustomDoc(BaseDoc):
assert custom_partial_da[0].u == 'a'
assert custom_partial_da[0].single_text.text == 'single hey ha'
assert custom_partial_da[0].single_text.embedding.shape == (2,)
assert original_back[0].nested.nested.value == 'hello world'

assert len(original_back) == 1
assert original_back[0].url == 'photo.jpg'
Expand Down