Skip to content

Commit fcbc22f

Browse files
authored
INTPYTHON-412 Add linting of test files (#30)
1 parent 8f2cafe commit fcbc22f

File tree

11 files changed

+56
-32
lines changed

11 files changed

+56
-32
lines changed

.github/workflows/_lint.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ jobs:
9797
${{ env.WORKDIR }}/.mypy_cache_test
9898
key: mypy-test-${{ runner.os }}-${{ runner.arch }}-py${{ matrix.python-version }}-${{ inputs.working-directory }}-${{ hashFiles(format('{0}/poetry.lock', inputs.working-directory)) }}
9999

100-
# - name: Analysing the code with our lint
101-
# working-directory: ${{ inputs.working-directory }}
102-
# run: |
103-
# make lint_tests
100+
- name: Analysing the code with our lint
101+
working-directory: ${{ inputs.working-directory }}
102+
run: |
103+
make lint_tests

libs/langgraph-checkpoint-mongodb/tests/integration_tests/any_str.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def __hash__(self) -> int:
4141

4242

4343
class AnyDict(dict):
44-
def __init__(self, *args, **kwargs) -> None:
44+
def __init__(self, *args: Any, **kwargs: Any) -> None:
4545
super().__init__(*args, **kwargs)
4646

4747
def __eq__(self, other: object) -> bool:

libs/langgraph-checkpoint-mongodb/tests/integration_tests/conftest.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
from __future__ import annotations
2+
13
import os
24
from contextlib import asynccontextmanager
3-
from typing import AsyncIterator, Optional
5+
from typing import Any, AsyncGenerator, Generator, Optional
46
from uuid import UUID
57

68
import pytest
@@ -11,7 +13,6 @@
1113
from langgraph.checkpoint.base import BaseCheckpointSaver
1214
from langgraph.checkpoint.mongodb import MongoDBSaver
1315
from langgraph.checkpoint.mongodb.aio import AsyncMongoDBSaver
14-
from langgraph.store.base import BaseStore
1516
from langgraph.store.memory import InMemoryStore
1617

1718
pytest.register_assert_rewrite("tests.memory_assert")
@@ -25,7 +26,7 @@
2526

2627

2728
@pytest.fixture
28-
def anyio_backend():
29+
def anyio_backend() -> str:
2930
return "asyncio"
3031

3132

@@ -41,14 +42,14 @@ def deterministic_uuids(mocker: MockerFixture) -> MockerFixture:
4142

4243

4344
@pytest.fixture(scope="function")
44-
def checkpointer_memory():
45+
def checkpointer_memory() -> Generator[BaseCheckpointSaver, None]:
4546
from .memory_assert import MemorySaverAssertImmutable
4647

4748
yield MemorySaverAssertImmutable()
4849

4950

5051
@pytest.fixture
51-
def checkpointer_mongodb():
52+
def checkpointer_mongodb() -> Generator[BaseCheckpointSaver, None]:
5253
"""Fresh checkpointer without any memories."""
5354
with MongoDBSaver.from_conn_string(
5455
os.environ.get("MONGODB_URI", "mongodb://localhost:27017"),
@@ -60,7 +61,7 @@ def checkpointer_mongodb():
6061

6162

6263
@asynccontextmanager
63-
async def _checkpointer_mongodb_aio():
64+
async def _checkpointer_mongodb_aio() -> AsyncGenerator[AsyncMongoDBSaver, None]:
6465
async with AsyncMongoDBSaver.from_conn_string(
6566
os.environ.get("MONGODB_URI", "mongodb://localhost:27017"),
6667
os.environ.get("DATABASE_NAME", "langchain_checkpoints_db"),
@@ -73,7 +74,7 @@ async def _checkpointer_mongodb_aio():
7374
@asynccontextmanager
7475
async def awith_checkpointer(
7576
checkpointer_name: Optional[str],
76-
) -> AsyncIterator[BaseCheckpointSaver]:
77+
) -> Any:
7778
if checkpointer_name is None:
7879
yield None
7980
elif checkpointer_name == "memory":
@@ -88,12 +89,12 @@ async def awith_checkpointer(
8889

8990

9091
@pytest.fixture(scope="function")
91-
def store_in_memory():
92+
def store_in_memory() -> Generator[InMemoryStore]:
9293
yield InMemoryStore()
9394

9495

9596
@asynccontextmanager
96-
async def awith_store(store_name: Optional[str]) -> AsyncIterator[BaseStore]:
97+
async def awith_store(store_name: Optional[str]) -> Any:
9798
if store_name is None:
9899
yield None
99100
elif store_name == "in_memory":

libs/langgraph-checkpoint-mongodb/tests/integration_tests/fake_chat.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import re
24
from typing import Any, Iterator, List, Optional, cast
35

@@ -8,11 +10,11 @@
810

911

1012
class FakeChatModel(GenericFakeChatModel):
11-
messages: list[BaseMessage]
13+
messages: list[BaseMessage] # type:ignore[assignment]
1214

1315
i: int = 0
1416

15-
def bind_tools(self, functions: list):
17+
def bind_tools(self, tools: list) -> FakeChatModel: # type:ignore[override]
1618
return self
1719

1820
def _generate(

libs/langgraph-checkpoint-mongodb/tests/integration_tests/memory_assert.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ def __init__(
3838

3939
def put(
4040
self,
41-
config: dict,
41+
config: RunnableConfig,
4242
checkpoint: Checkpoint,
4343
metadata: CheckpointMetadata,
4444
new_versions: ChannelVersions,
45-
) -> None:
45+
) -> RunnableConfig:
4646
if self.put_sleep:
4747
import time
4848

@@ -53,12 +53,12 @@ def put(
5353
if saved := super().get(config):
5454
assert (
5555
self.serde.loads_typed(
56-
self.storage_for_copies[thread_id][checkpoint_ns][saved["id"]]
56+
self.storage_for_copies[thread_id][checkpoint_ns][saved["id"]] # type:ignore[arg-type]
5757
)
5858
== saved
5959
)
6060
self.storage_for_copies[thread_id][checkpoint_ns][checkpoint["id"]] = (
61-
self.serde.dumps_typed(copy_checkpoint(checkpoint))
61+
self.serde.dumps_typed(copy_checkpoint(checkpoint)) # type:ignore[assignment]
6262
)
6363
# call super to write checkpoint
6464
return super().put(config, checkpoint, metadata, new_versions)
@@ -78,7 +78,7 @@ def put(
7878
checkpoint: Checkpoint,
7979
metadata: CheckpointMetadata,
8080
new_versions: ChannelVersions,
81-
) -> None:
81+
) -> RunnableConfig:
8282
"""The implementation of put() merges config["configurable"] (a run's
8383
configurable fields) with the metadata field. The state of the
8484
checkpoint metadata can be asserted to confirm that the run's
@@ -115,7 +115,12 @@ async def aput(
115115
new_versions: ChannelVersions,
116116
) -> RunnableConfig:
117117
return await asyncio.get_running_loop().run_in_executor(
118-
None, self.put, config, checkpoint, metadata, new_versions
118+
None,
119+
self.put,
120+
config,
121+
checkpoint,
122+
metadata,
123+
new_versions,
119124
)
120125

121126

libs/langgraph-checkpoint-mongodb/tests/integration_tests/test_pregel.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@
105105
_AnyIdToolMessage,
106106
)
107107

108+
# mypy: ignore-errors
109+
108110

109111
# define these objects to avoid importing langchain_core.agents
110112
# and therefore avoid relying on core Pydantic version

libs/langgraph-checkpoint-mongodb/tests/integration_tests/test_pregel_async.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@
101101
_AnyIdToolMessage,
102102
)
103103

104+
# mypy: ignore-errors
105+
104106
pytestmark = pytest.mark.anyio
105107

106108

libs/mongodb/langchain_mongodb/cache.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,6 @@ def _wait_until(
303303
return retval
304304

305305
if time.time() - start > timeout:
306-
raise TimeoutError("Didn't ever %s" % success_description)
306+
raise TimeoutError(f"Didn't ever {success_description}")
307307

308308
time.sleep(interval)

libs/mongodb/pyproject.toml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,15 @@ asyncio_mode = "auto"
6363
[tool.mypy]
6464
disallow_untyped_defs = "True"
6565

66-
[tool.ruff.lint]
67-
select = ["E", "F", "I"]
66+
[tool.ruff]
67+
lint.select = [
68+
"E", # pycodestyle
69+
"F", # Pyflakes
70+
"UP", # pyupgrade
71+
"B", # flake8-bugbear
72+
"I", # isort
73+
]
74+
lint.ignore = ["E501", "B008", "UP007", "UP006"]
6875

6976
[tool.coverage.run]
7077
omit = ["tests/*"]

libs/mongodb/tests/integration_tests/test_retrievers.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import os
1+
import os # noqa: I001
22
from typing import Generator, List
33
from time import sleep, time
44

@@ -11,7 +11,7 @@
1111
from langchain_mongodb import MongoDBAtlasVectorSearch
1212
from langchain_mongodb.index import (
1313
create_fulltext_search_index,
14-
create_vector_search_index
14+
create_vector_search_index,
1515
)
1616
from langchain_mongodb.retrievers import (
1717
MongoDBAtlasFullTextSearchRetriever,
@@ -162,14 +162,19 @@ def test_fulltext_retriever(
162162
)
163163

164164
# Wait for the search index to complete.
165-
search_content = dict(index=SEARCH_INDEX_NAME, wildcard=dict(query="*", path=PAGE_CONTENT_FIELD, allowAnalyzedField=True))
165+
search_content = dict(
166+
index=SEARCH_INDEX_NAME,
167+
wildcard=dict(query="*", path=PAGE_CONTENT_FIELD, allowAnalyzedField=True),
168+
)
166169
n_docs = collection.count_documents({})
167170
t0 = time()
168171
while True:
169172
if (time() - t0) > TIMEOUT:
170-
raise TimeoutError(f'Search index {SEARCH_INDEX_NAME} did not complete in {TIMEOUT}')
171-
results = collection.aggregate([{ "$search": search_content }])
172-
if len(list(results)) == n_docs:
173+
raise TimeoutError(
174+
f"Search index {SEARCH_INDEX_NAME} did not complete in {TIMEOUT}"
175+
)
176+
cursor = collection.aggregate([{"$search": search_content}])
177+
if len(list(cursor)) == n_docs:
173178
break
174179
sleep(INTERVAL)
175180

0 commit comments

Comments
 (0)