Files
langchain/libs/langchain_v1/tests/unit_tests/agents/utils.py
Christophe Bornet 9ce73a73f8 test(langchain): activate test_responses_spec tests (#34564)
description by @mdrxy

- Enable `test_responses_spec.py` integration tests that were previously
skipped at module level
- Widen `ToolStrategy.schema` type annotation from `type[SchemaT]` to
`type[SchemaT] | dict[str, Any]` to match actual supported usage (JSON
schema dicts were already handled at runtime)
- Fix type annotations and linting issues in test file (modernize to
`dict`/`list`, add return types, prefix unused `_request` param)
- Improve generic typing in `load_spec` utility with bounded `TypeVar`

Co-authored-by: Mason Daugherty <mason@langchain.dev>
2026-01-09 17:44:33 -05:00

26 lines
622 B
Python

import json
from pathlib import Path
from typing import TypeVar
from pydantic import BaseModel, ConfigDict
from pydantic.alias_generators import to_camel
class BaseSchema(BaseModel):
model_config = ConfigDict(
alias_generator=to_camel,
populate_by_name=True,
from_attributes=True,
)
_T = TypeVar("_T", bound=BaseModel)
def load_spec(spec_name: str, as_model: type[_T]) -> list[_T]:
with (Path(__file__).parent / "specifications" / f"{spec_name}.json").open(
"r", encoding="utf-8"
) as f:
data = json.load(f)
return [as_model(**item) for item in data]