Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resolve more warnings in unit tests #752

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 13 additions & 4 deletions tests/unit_tests/test_api_playground.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Test the playground API."""

import httpx
from fastapi import APIRouter, FastAPI
from httpx import AsyncClient
from langchain_core.runnables import RunnableLambda
Expand All @@ -15,7 +16,9 @@ async def test_serve_playground() -> None:
RunnableLambda(lambda foo: "hello"),
)

async with AsyncClient(app=app, base_url="http://localhost:9999") as client:
async with AsyncClient(
base_url="http://localhost:9999", transport=httpx.ASGITransport(app=app)
) as client:
response = await client.get("/playground/index.html")
assert response.status_code == 200
# Test that we can't access files that do not exist.
Expand All @@ -42,7 +45,9 @@ async def test_serve_playground_with_api_router() -> None:

app.include_router(router)

async with AsyncClient(app=app, base_url="http://localhost:9999") as client:
async with AsyncClient(
base_url="http://localhost:9999", transport=httpx.ASGITransport(app=app)
) as client:
response = await client.get("/langserve_runnables/chat/playground/index.html")
assert response.status_code == 200

Expand All @@ -64,7 +69,9 @@ async def test_serve_playground_with_api_router_in_api_router() -> None:
# Now add parent router to the app
app.include_router(parent_router)

async with AsyncClient(app=app, base_url="http://localhost:9999") as client:
async with AsyncClient(
base_url="http://localhost:9999", transport=httpx.ASGITransport(app=app)
) as client:
response = await client.get("/parent/bar/foo/playground/index.html")
assert response.status_code == 200

Expand All @@ -88,7 +95,9 @@ async def test_root_path_on_playground() -> None:
)
app.include_router(router)

async_client = AsyncClient(app=app, base_url="http://localhost:9999")
async_client = AsyncClient(
base_url="http://localhost:9999", transport=httpx.ASGITransport(app=app)
)

response = await async_client.get("/chat/playground/index.html")
assert response.status_code == 200
Expand Down
21 changes: 16 additions & 5 deletions tests/unit_tests/test_server_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,10 @@ async def test_server_astream_events(app: FastAPI) -> None:

async def test_server_bound_async(app_for_config: FastAPI) -> None:
"""Test the server directly via HTTP requests."""
async_client = AsyncClient(app=app_for_config, base_url="http://localhost:9999")
async_client = AsyncClient(
base_url="http://localhost:9999",
transport=httpx.ASGITransport(app=app_for_config),
)
config_hash = LZString.compressToEncodedURIComponent(json.dumps({"tags": ["test"]}))

# Test invoke
Expand Down Expand Up @@ -1105,7 +1108,9 @@ async def add_one(x: int) -> int:
input_type=int,
config_keys=["metadata"],
)
async with AsyncClient(app=app, base_url="http://localhost:9999") as async_client:
async with AsyncClient(
base_url="http://localhost:9999", transport=httpx.ASGITransport(app=app)
) as async_client:
server_runnable_spy = mocker.spy(server_runnable, "ainvoke")
response = await async_client.post(
"/invoke",
Expand Down Expand Up @@ -1289,7 +1294,9 @@ async def add_one(x: int) -> int:
config_keys=["tags"],
)

async with AsyncClient(app=app, base_url="http://localhost:9999") as async_client:
async with AsyncClient(
base_url="http://localhost:9999", transport=httpx.ASGITransport(app=app)
) as async_client:
response = await async_client.get("/openapi.json")
assert response.status_code == 200

Expand Down Expand Up @@ -1423,7 +1430,9 @@ async def add_two(y: int) -> int:
)
add_routes(app, template, path="/prompt_2", config_keys=["tags", "configurable"])

async with AsyncClient(app=app, base_url="http://localhost:9999") as async_client:
async with AsyncClient(
base_url="http://localhost:9999", transport=httpx.ASGITransport(app=app)
) as async_client:
# input schema
response = await async_client.get("/add_one/input_schema")
assert response.json() == {"title": "add_one_input", "type": "integer"}
Expand Down Expand Up @@ -1574,7 +1583,9 @@ async def passthrough_dict(d: Any) -> Any:
app = FastAPI()
add_routes(app, runnable_lambda, input_type=InputType, config_keys=["tags"])

async with AsyncClient(app=app, base_url="http://localhost:9999") as client:
async with AsyncClient(
base_url="http://localhost:9999", transport=httpx.ASGITransport(app=app)
) as client:
res = await client.get("/input_schema")
if PYDANTIC_VERSION < (2, 9):
assert res.json() == {
Expand Down
Loading