Skip to content

Commit d57216c

Browse files
authored
feat(core): add ruff rules D to tests except D1 (#32000)
Docs are not required for tests but when there are docstrings, they shall be correctly formatted. See https://docs.astral.sh/ruff/rules/#pydocstyle-d
1 parent 58d4261 commit d57216c

File tree

13 files changed

+61
-34
lines changed

13 files changed

+61
-34
lines changed

β€Žlibs/core/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,5 +124,5 @@ asyncio_default_fixture_loop_scope = "function"
124124
[tool.ruff.lint.per-file-ignores]
125125
"langchain_core/utils/mustache.py" = [ "PLW0603",]
126126
"tests/unit_tests/test_tools.py" = [ "ARG",]
127-
"tests/**" = [ "D", "S", "SLF",]
127+
"tests/**" = [ "D1", "S", "SLF",]
128128
"scripts/**" = [ "INP", "S",]

β€Žlibs/core/tests/unit_tests/embeddings/test_deterministic_embedding.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33

44
def test_deterministic_fake_embeddings() -> None:
5-
"""Test that the deterministic fake embeddings return the same
5+
"""Test that DeterministicFakeEmbedding is deterministic.
6+
7+
Test that the deterministic fake embeddings return the same
68
embedding vector for the same text.
79
"""
810
fake = DeterministicFakeEmbedding(size=10)

β€Žlibs/core/tests/unit_tests/indexing/test_indexing.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,7 @@ async def test_ascoped_full_fails_with_bad_source_ids(
905905
def test_index_empty_doc_scoped_full(
906906
record_manager: InMemoryRecordManager, vector_store: InMemoryVectorStore
907907
) -> None:
908-
"""Test Indexing with scoped_full strategy"""
908+
"""Test Indexing with scoped_full strategy."""
909909
loader = ToyLoader(
910910
documents=[
911911
Document(
@@ -1927,7 +1927,6 @@ def test_incremental_cleanup_with_different_batchsize(
19271927
record_manager: InMemoryRecordManager, vector_store: VectorStore
19281928
) -> None:
19291929
"""Check that we can clean up with different batch size."""
1930-
19311930
docs = [
19321931
Document(
19331932
page_content="This is a test document.",

β€Žlibs/core/tests/unit_tests/language_models/llms/test_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ async def test_async_batch_size() -> None:
9999

100100
async def test_error_callback() -> None:
101101
class FailingLLMError(Exception):
102-
"""FailingLLMError"""
102+
"""FailingLLMError."""
103103

104104
class FailingLLM(LLM):
105105
@property

β€Žlibs/core/tests/unit_tests/output_parsers/test_list_parser.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ def test_single_item() -> None:
2828

2929

3030
def test_multiple_items_with_spaces() -> None:
31-
"""Test that a string with multiple comma-separated items
31+
"""Test multiple items with spaces.
32+
33+
Test that a string with multiple comma-separated items
3234
with spaces is parsed to a list.
3335
"""
3436
parser = CommaSeparatedListOutputParser()
@@ -66,7 +68,9 @@ def test_multiple_items() -> None:
6668

6769

6870
def test_multiple_items_with_comma() -> None:
69-
"""Test that a string with multiple comma-separated items with 1 item containing a
71+
"""Test multiple items with a comma.
72+
73+
Test that a string with multiple comma-separated items with 1 item containing a
7074
comma is parsed to a list.
7175
"""
7276
parser = CommaSeparatedListOutputParser()

β€Žlibs/core/tests/unit_tests/prompts/test_prompt.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,9 @@ def test_prompt_from_file() -> None:
361361

362362

363363
def test_prompt_from_file_with_partial_variables() -> None:
364-
"""Test prompt can be successfully constructed from a file
365-
with partial variables.
364+
"""Test prompt from file with partial variables.
365+
366+
Test prompt can be successfully constructed from a file with partial variables.
366367
"""
367368
# given
368369
template = "This is a {foo} test {bar}."

β€Žlibs/core/tests/unit_tests/runnables/test_runnable.py

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102

103103
class FakeTracer(BaseTracer):
104104
"""Fake tracer that records LangChain execution.
105+
105106
It replaces run ids with deterministic UUIDs for snapshotting.
106107
"""
107108

@@ -4867,7 +4868,9 @@ async def __call__(self, _: AsyncIterator[Any]) -> AsyncIterator[int]:
48674868

48684869

48694870
def test_runnable_gen_context_config() -> None:
4870-
"""Test that a generator can call other runnables with config
4871+
"""Test generator runnable config propagation.
4872+
4873+
Test that a generator can call other runnables with config
48714874
propagated from the context.
48724875
"""
48734876
fake = RunnableLambda(len)
@@ -4942,9 +4945,11 @@ def gen(_: Iterator[Any]) -> Iterator[int]:
49424945
"async tasks in a specific context",
49434946
)
49444947
async def test_runnable_gen_context_config_async() -> None:
4945-
"""Test that a generator can call other runnables with config
4946-
propagated from the context."""
4948+
"""Test generator runnable config propagation.
49474949
4950+
Test that a generator can call other runnables with config
4951+
propagated from the context.
4952+
"""
49484953
fake = RunnableLambda(len)
49494954

49504955
async def agen(_: AsyncIterator[Any]) -> AsyncIterator[int]:
@@ -5010,7 +5015,9 @@ async def agen(_: AsyncIterator[Any]) -> AsyncIterator[int]:
50105015

50115016

50125017
def test_runnable_iter_context_config() -> None:
5013-
"""Test that a generator can call other runnables with config
5018+
"""Test generator runnable config propagation.
5019+
5020+
Test that a generator can call other runnables with config
50145021
propagated from the context.
50155022
"""
50165023
fake = RunnableLambda(len)
@@ -5069,9 +5076,11 @@ def gen(value: str) -> Iterator[int]:
50695076
"async tasks in a specific context",
50705077
)
50715078
async def test_runnable_iter_context_config_async() -> None:
5072-
"""Test that a generator can call other runnables with config
5073-
propagated from the context."""
5079+
"""Test generator runnable config propagation.
50745080
5081+
Test that a generator can call other runnables with config
5082+
propagated from the context.
5083+
"""
50755084
fake = RunnableLambda(len)
50765085

50775086
@chain
@@ -5135,7 +5144,9 @@ async def agen(value: str) -> AsyncIterator[int]:
51355144

51365145

51375146
def test_runnable_lambda_context_config() -> None:
5138-
"""Test that a function can call other runnables with config
5147+
"""Test function runnable config propagation.
5148+
5149+
Test that a function can call other runnables with config
51395150
propagated from the context.
51405151
"""
51415152
fake = RunnableLambda(len)
@@ -5192,9 +5203,11 @@ def fun(value: str) -> int:
51925203
"async tasks in a specific context",
51935204
)
51945205
async def test_runnable_lambda_context_config_async() -> None:
5195-
"""Test that a function can call other runnables with config
5196-
propagated from the context."""
5206+
"""Test function runnable config propagation.
51975207
5208+
Test that a function can call other runnables with config
5209+
propagated from the context.
5210+
"""
51985211
fake = RunnableLambda(len)
51995212

52005213
@chain
@@ -5295,7 +5308,9 @@ def test_with_config_callbacks() -> None:
52955308

52965309

52975310
async def test_ainvoke_on_returned_runnable() -> None:
5298-
"""Verify that a runnable returned by a sync runnable in the async path will
5311+
"""Test ainvoke on a returned runnable.
5312+
5313+
Verify that a runnable returned by a sync runnable in the async path will
52995314
be runthroughaasync path (issue #13407).
53005315
"""
53015316

@@ -5637,7 +5652,9 @@ class CustomChatModel(RunnableSerializable):
56375652

56385653

56395654
def test_schema_for_prompt_and_chat_model() -> None:
5640-
"""Testing that schema is generated properly when using variable names
5655+
"""Test schema generation for prompt and chat model.
5656+
5657+
Testing that schema is generated properly when using variable names
56415658
that collide with pydantic attributes.
56425659
"""
56435660
prompt = ChatPromptTemplate([("system", "{model_json_schema}, {_private}, {json}")])

β€Žlibs/core/tests/unit_tests/runnables/test_runnable_events_v2.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2797,6 +2797,5 @@ async def foo(x: int) -> int:
27972797

27982798
def test_default_is_v2() -> None:
27992799
"""Test that we default to version="v2"."""
2800-
28012800
signature = inspect.signature(Runnable.astream_events)
28022801
assert signature.parameters["version"].default == "v2"

β€Žlibs/core/tests/unit_tests/test_messages.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ def test_tool_message_serdes() -> None:
940940

941941

942942
class BadObject:
943-
""""""
943+
pass
944944

945945

946946
def test_tool_message_ser_non_serializable() -> None:

β€Žlibs/core/tests/unit_tests/test_pydantic_serde.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
"""A set of tests that verifies that Union discrimination works correctly with
1+
"""Test pydantic SerDe.
2+
3+
A set of tests that verifies that Union discrimination works correctly with
24
the various pydantic base models.
35
46
These tests can uncover issues that will also arise during regular instantiation

0 commit comments

Comments
Β (0)