standard-tests: Ruff autofixes (#31862)

Auto-fixes from ruff with rule ALL
This commit is contained in:
Christophe Bornet
2025-07-07 16:27:39 +02:00
committed by GitHub
parent 2df3fdf40d
commit 9368b92b2c
19 changed files with 120 additions and 178 deletions

View File

@@ -1,6 +1,4 @@
"""
:autodoc-options: autoproperty
"""
""":autodoc-options: autoproperty."""
import inspect
import os
@@ -31,13 +29,13 @@ from langchain_tests.utils.pydantic import PYDANTIC_MAJOR_VERSION
def generate_schema_pydantic_v1_from_2() -> Any:
"""
Use to generate a schema from v1 namespace in pydantic 2.
"""Use to generate a schema from v1 namespace in pydantic 2.
:private:
"""
if PYDANTIC_MAJOR_VERSION != 2:
raise AssertionError("This function is only compatible with Pydantic v2.")
msg = "This function is only compatible with Pydantic v2."
raise AssertionError(msg)
class PersonB(BaseModelV1):
"""Record attributes of a person."""
@@ -49,8 +47,7 @@ def generate_schema_pydantic_v1_from_2() -> Any:
def generate_schema_pydantic() -> Any:
"""
Works with either pydantic 1 or 2
"""Works with either pydantic 1 or 2.
:private:
"""
@@ -74,7 +71,7 @@ class ChatModelTests(BaseStandardTests):
"""Base class for chat model tests.
:private:
""" # noqa: E501
"""
@property
@abstractmethod
@@ -158,13 +155,15 @@ class ChatModelTests(BaseStandardTests):
@property
def supports_image_inputs(self) -> bool:
"""(bool) whether the chat model supports image inputs, defaults to
``False``."""
``False``.
"""
return False
@property
def supports_image_urls(self) -> bool:
"""(bool) whether the chat model supports image inputs from URLs, defaults to
``False``."""
``False``.
"""
return False
@property
@@ -175,19 +174,22 @@ class ChatModelTests(BaseStandardTests):
@property
def supports_audio_inputs(self) -> bool:
"""(bool) whether the chat model supports audio inputs, defaults to
``False``."""
``False``.
"""
return False
@property
def supports_video_inputs(self) -> bool:
"""(bool) whether the chat model supports video inputs, defaults to ``False``.
No current tests are written for this feature."""
No current tests are written for this feature.
"""
return False
@property
def returns_usage_metadata(self) -> bool:
"""(bool) whether the chat model returns usage metadata on invoke and streaming
responses."""
responses.
"""
return True
@property
@@ -198,7 +200,8 @@ class ChatModelTests(BaseStandardTests):
@property
def supports_image_tool_message(self) -> bool:
"""(bool) whether the chat model supports ToolMessages that include image
content."""
content.
"""
return False
@property
@@ -227,7 +230,8 @@ class ChatModelTests(BaseStandardTests):
],
]:
"""(dict) what usage metadata details are emitted in invoke and stream. Only
needs to be overridden if these details are returned by the model."""
needs to be overridden if these details are returned by the model.
"""
return {"invoke": [], "stream": []}
@@ -806,7 +810,8 @@ class ChatModelUnitTests(ChatModelTests):
@property
def init_from_env_params(self) -> tuple[dict, dict, dict]:
"""(tuple) environment variables, additional initialization args, and expected
instance attributes for testing initialization from environment variables."""
instance attributes for testing initialization from environment variables.
"""
return {}, {}, {}
def test_init(self) -> None:
@@ -887,7 +892,7 @@ class ChatModelUnitTests(ChatModelTests):
a utility function that will accommodate most formats: https://python.langchain.com/api_reference/core/utils/langchain_core.utils.function_calling.convert_to_openai_tool.html
See example implementation of ``bind_tools`` here: https://python.langchain.com/api_reference/_modules/langchain_openai/chat_models/base.html#BaseChatOpenAI.bind_tools
""" # noqa: E501
"""
if not self.has_tool_calling:
return
@@ -927,7 +932,7 @@ class ChatModelUnitTests(ChatModelTests):
a utility function that will accommodate most formats: https://python.langchain.com/api_reference/core/utils/langchain_core.utils.function_calling.convert_to_openai_tool.html
See example implementation of ``with_structured_output`` here: https://python.langchain.com/api_reference/_modules/langchain_openai/chat_models/base.html#BaseChatOpenAI.with_structured_output
""" # noqa: E501
"""
if not self.has_structured_output:
return

View File

@@ -10,9 +10,7 @@ from langchain_tests.base import BaseStandardTests
class EmbeddingsTests(BaseStandardTests):
"""
:private:
"""
""":private:"""
@property
@abstractmethod
@@ -88,7 +86,7 @@ class EmbeddingsUnitTests(EmbeddingsTests):
"my_api_key": "api_key",
},
)
""" # noqa: E501
"""
def test_init(self) -> None:
"""Test model initialization.
@@ -106,7 +104,8 @@ class EmbeddingsUnitTests(EmbeddingsTests):
"""This property is used in unit tests to test initialization from environment
variables. It should return a tuple of three dictionaries that specify the
environment variables, additional initialization args, and expected instance
attributes to check."""
attributes to check.
"""
return {}, {}, {}
def test_init_from_env(self) -> None:

View File

@@ -11,8 +11,7 @@ from langchain_tests.base import BaseStandardTests
class ToolsTests(BaseStandardTests):
"""
:private:
""":private:
Base class for testing tools. This won't show in the documentation, but
the docstrings will be inherited by subclasses.
"""
@@ -20,22 +19,17 @@ class ToolsTests(BaseStandardTests):
@property
@abstractmethod
def tool_constructor(self) -> Union[type[BaseTool], BaseTool]:
"""
Returns a class or instance of a tool to be tested.
"""
"""Returns a class or instance of a tool to be tested."""
...
@property
def tool_constructor_params(self) -> dict:
"""
Returns a dictionary of parameters to pass to the tool constructor.
"""
"""Returns a dictionary of parameters to pass to the tool constructor."""
return {}
@property
def tool_invoke_params_example(self) -> dict:
"""
Returns a dictionary representing the "args" of an example tool call.
"""Returns a dictionary representing the "args" of an example tool call.
This should NOT be a ToolCall dict - it should not
have {"name", "id", "args"} keys.
@@ -44,9 +38,7 @@ class ToolsTests(BaseStandardTests):
@pytest.fixture
def tool(self) -> BaseTool:
"""
:private:
"""
""":private:"""
if isinstance(self.tool_constructor, BaseTool):
if self.tool_constructor_params != {}:
msg = (
@@ -59,19 +51,17 @@ class ToolsTests(BaseStandardTests):
class ToolsUnitTests(ToolsTests):
"""
Base class for tools unit tests.
"""
"""Base class for tools unit tests."""
@property
def init_from_env_params(self) -> tuple[dict, dict, dict]:
"""Return env vars, init args, and expected instance attrs for initializing
from env vars."""
from env vars.
"""
return {}, {}, {}
def test_init(self) -> None:
"""
Test that the tool can be initialized with :attr:`tool_constructor` and
"""Test that the tool can be initialized with :attr:`tool_constructor` and
:attr:`tool_constructor_params`. If this fails, check that the
keyword args defined in :attr:`tool_constructor_params` are valid.
"""
@@ -94,16 +84,14 @@ class ToolsUnitTests(ToolsTests):
assert actual == expected
def test_has_name(self, tool: BaseTool) -> None:
"""
Tests that the tool has a name attribute to pass to chat models.
"""Tests that the tool has a name attribute to pass to chat models.
If this fails, add a `name` parameter to your tool.
"""
assert tool.name
def test_has_input_schema(self, tool: BaseTool) -> None:
"""
Tests that the tool has an input schema.
"""Tests that the tool has an input schema.
If this fails, add an `args_schema` to your tool.
@@ -115,8 +103,7 @@ class ToolsUnitTests(ToolsTests):
assert tool.get_input_schema()
def test_input_schema_matches_invoke_params(self, tool: BaseTool) -> None:
"""
Tests that the provided example params match the declared input schema.
"""Tests that the provided example params match the declared input schema.
If this fails, update the `tool_invoke_params_example` attribute to match
the input schema (`args_schema`) of the tool.