Skip to content

Commit c652ed2

Browse files
author
Joan Martinez
committed
test: test fixes
1 parent a07919d commit c652ed2

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

tests/integrations/externals/test_fastapi.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from docarray.base_doc import DocArrayResponse
1010
from docarray.documents import ImageDoc, TextDoc
1111
from docarray.typing import NdArray
12+
from docarray.utils._internal.pydantic import is_pydantic_v2
1213

1314

1415
@pytest.mark.asyncio
@@ -112,6 +113,7 @@ async def create_item(doc: InputDoc) -> OutputDoc:
112113

113114

114115
@pytest.mark.asyncio
116+
@pytest.mark.skipif(is_pydantic_v2)
115117
async def test_docarray():
116118
doc = ImageDoc(tensor=np.zeros((3, 224, 224)))
117119
docs = DocList[ImageDoc]([doc, doc])
@@ -135,3 +137,29 @@ async def func(fastapi_docs: List[ImageDoc]) -> List[ImageDoc]:
135137
docs = DocList[ImageDoc].from_json(response.content.decode())
136138
assert len(docs) == 2
137139
assert docs[0].tensor.shape == (3, 224, 224)
140+
141+
142+
@pytest.mark.asyncio
143+
@pytest.mark.skipif(is_pydantic_v2)
144+
async def test_doclist_directly():
145+
doc = ImageDoc(tensor=np.zeros((3, 224, 224)))
146+
docs = DocList[ImageDoc]([doc, doc])
147+
148+
app = FastAPI()
149+
150+
@app.post("/doc/", response_class=DocArrayResponse)
151+
async def func(fastapi_docs: DocList[ImageDoc]) -> DocList[ImageDoc]:
152+
return fastapi_docs
153+
154+
async with AsyncClient(app=app, base_url="http://test") as ac:
155+
response = await ac.post("/doc/", data=docs.to_json())
156+
resp_doc = await ac.get("/docs")
157+
resp_redoc = await ac.get("/redoc")
158+
159+
assert response.status_code == 200
160+
assert resp_doc.status_code == 200
161+
assert resp_redoc.status_code == 200
162+
163+
docs = DocList[ImageDoc].from_json(response.content.decode())
164+
assert len(docs) == 2
165+
assert docs[0].tensor.shape == (3, 224, 224)

tests/units/array/test_array.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,8 @@ def test_validate_list_dict():
486486
dict(url=f'http://url.com/foo_{i}.png', tensor=NdArray(i)) for i in [2, 0, 1]
487487
]
488488

489+
# docs = DocList[Image]([Image(url=image['url'], tensor=image['tensor']) for image in images])
490+
489491
docs = parse_obj_as(DocList[Image], images)
490492

491493
assert docs.url == [

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy