Skip to content

Commit d869505

Browse files
committed
Reclean
1 parent 2c6f4e7 commit d869505

File tree

7 files changed

+35
-33
lines changed

7 files changed

+35
-33
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ repos:
44
hooks:
55
# Run the linter
66
- id: ruff
7-
args: [--fix]
7+
args: [--fix, --unsafe-fixes]
88
# Run the formatter
99
- id: ruff-format
1010

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ target-version = "py312"
2121
# Enable various rules
2222
select = ["E", "F", "B", "I", "N", "UP", "C4", "RET", "SIM", "TID"]
2323
# Exclude COM812 which conflicts with the formatter
24-
ignore = ["COM812"]
24+
ignore = ["COM812", "E501"]
2525

2626
# Allow unused variables when underscore-prefixed
2727
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

tests/conftest.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import asyncio
2+
import contextlib
23
import os
34
from unittest import mock
45
from unittest.mock import AsyncMock, patch
56

67
import pytest
8+
from dotenv import load_dotenv
79
from fastapi import BackgroundTasks, FastAPI
810
from httpx import ASGITransport, AsyncClient
911
from redis import Redis
@@ -20,10 +22,12 @@
2022
from utils import REDIS_INDEX_NAME, Keys, ensure_redisearch_index
2123

2224

25+
load_dotenv()
26+
27+
2328
@pytest.fixture(scope="session")
2429
def event_loop(request):
25-
loop = asyncio.get_event_loop()
26-
return loop
30+
return asyncio.get_event_loop()
2731

2832

2933
@pytest.fixture()
@@ -46,13 +50,11 @@ def memory_messages():
4650
@pytest.fixture()
4751
def mock_openai_client():
4852
"""Create a mock OpenAI client"""
49-
client = AsyncMock(spec=OpenAIClientWrapper)
53+
return AsyncMock(spec=OpenAIClientWrapper)
5054

5155
# We won't set default side effects here, allowing tests to set their own mocks
5256
# This prevents conflicts with tests that need specific return values
5357

54-
return client
55-
5658

5759
@pytest.fixture(autouse=True)
5860
async def search_index(async_redis_client):
@@ -87,10 +89,8 @@ async def search_index(async_redis_client):
8789

8890
# Clean up after tests
8991
await async_redis_client.flushdb()
90-
try:
92+
with contextlib.suppress(Exception):
9193
await async_redis_client.execute_command("FT.DROPINDEX", index_name)
92-
except Exception:
93-
pass
9494

9595

9696
@pytest.fixture()
@@ -169,8 +169,7 @@ def async_redis_client(redis_url):
169169
@pytest.fixture()
170170
def mock_async_redis_client():
171171
"""Create a mock async Redis client"""
172-
client = AsyncMock(spec=AsyncRedis)
173-
return client
172+
return AsyncMock(spec=AsyncRedis)
174173

175174

176175
@pytest.fixture()
@@ -211,7 +210,10 @@ def pytest_collection_modifyitems(
211210

212211
# Otherwise skip all tests requiring an API key
213212
skip_api = pytest.mark.skip(
214-
reason="Skipping test because API keys are not provided. Use --run-api-tests to run these tests."
213+
reason="""
214+
Skipping test because API keys are not provided.
215+
"Use --run-api-tests to run these tests.
216+
"""
215217
)
216218
for item in items:
217219
if item.get_closest_marker("requires_api_keys"):

tests/test_api.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from reducers import handle_compaction
1313

1414

15-
@pytest.fixture()
15+
@pytest.fixture
1616
def mock_openai_client_wrapper():
1717
"""Create a mock OpenAIClientWrapper that doesn't need an API key"""
1818
with patch("models.OpenAIClientWrapper") as mock_wrapper:
@@ -33,7 +33,7 @@ def mock_openai_client_wrapper():
3333

3434

3535
class TestHealthEndpoint:
36-
@pytest.mark.asyncio()
36+
@pytest.mark.asyncio
3737
async def test_health_endpoint(self, client):
3838
"""Test the health endpoint"""
3939
response = await client.get("/health")
@@ -93,8 +93,8 @@ async def test_get_memory(self, client, test_session_setup):
9393
assert data["context"] == "Sample context"
9494
assert int(data["tokens"]) == 150 # Convert string to int for comparison
9595

96-
@pytest.mark.requires_api_keys()
97-
@pytest.mark.asyncio()
96+
@pytest.mark.requires_api_keys
97+
@pytest.mark.asyncio
9898
async def test_post_memory(self, client):
9999
"""Test the post_memory endpoint"""
100100
payload = {
@@ -113,8 +113,8 @@ async def test_post_memory(self, client):
113113
assert "status" in data
114114
assert data["status"] == "ok"
115115

116-
@pytest.mark.requires_api_keys()
117-
@pytest.mark.asyncio()
116+
@pytest.mark.requires_api_keys
117+
@pytest.mark.asyncio
118118
async def test_post_memory_stores_in_long_term_memory(self, client):
119119
"""Test the post_memory endpoint"""
120120
payload = {
@@ -144,8 +144,8 @@ async def test_post_memory_stores_in_long_term_memory(self, client):
144144
assert mock_add_task.call_count == 1
145145
assert mock_add_task.call_args[0][0] == index_messages
146146

147-
@pytest.mark.requires_api_keys()
148-
@pytest.mark.asyncio()
147+
@pytest.mark.requires_api_keys
148+
@pytest.mark.asyncio
149149
async def test_post_memory_compacts_long_conversation(self, client):
150150
"""Test the post_memory endpoint"""
151151
payload = {
@@ -175,7 +175,7 @@ async def test_post_memory_compacts_long_conversation(self, client):
175175
assert mock_add_task.call_count == 1
176176
assert mock_add_task.call_args[0][0] == handle_compaction
177177

178-
@pytest.mark.asyncio()
178+
@pytest.mark.asyncio
179179
async def test_delete_memory(self, client, test_session_setup):
180180
"""Test the delete_memory endpoint"""
181181
session_id = test_session_setup
@@ -201,10 +201,10 @@ async def test_delete_memory(self, client, test_session_setup):
201201
assert len(data["messages"]) == 0
202202

203203

204-
@pytest.mark.requires_api_keys()
204+
@pytest.mark.requires_api_keys
205205
class TestRetrievalEndpoint:
206206
@patch("retrieval.search_messages")
207-
@pytest.mark.asyncio()
207+
@pytest.mark.asyncio
208208
async def test_retrieval(self, mock_search, client):
209209
"""Test the retrieval endpoint"""
210210
mock_search.return_value = SearchResults(

tests/test_long_term_memory.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111

1212
class TestLongTermMemory:
13-
@pytest.mark.asyncio()
13+
@pytest.mark.asyncio
1414
async def test_index_messages(
1515
self, memory_messages, mock_openai_client, mock_async_redis_client
1616
):
@@ -52,7 +52,7 @@ async def test_index_messages(
5252
# Check that the vector is bytes
5353
assert isinstance(mapping["vector"], bytes)
5454

55-
@pytest.mark.asyncio()
55+
@pytest.mark.asyncio
5656
async def test_search_messages(self, mock_openai_client, mock_async_redis_client):
5757
"""Test searching messages"""
5858
# Set up the mock embedding response
@@ -124,9 +124,9 @@ def __init__(self, docs):
124124
assert results.docs[1].dist == 0.75
125125

126126

127-
@pytest.mark.requires_api_keys()
127+
@pytest.mark.requires_api_keys
128128
class TestLongTermMemoryIntegration:
129-
@pytest.mark.asyncio()
129+
@pytest.mark.asyncio
130130
async def test_search_messages(self, memory_messages, async_redis_client):
131131
"""Test searching messages"""
132132

@@ -146,7 +146,7 @@ async def test_search_messages(self, memory_messages, async_redis_client):
146146
assert results.docs[0].role == "user"
147147
assert results.docs[0].content == "What is the capital of France?"
148148

149-
@pytest.mark.asyncio()
149+
@pytest.mark.asyncio
150150
async def test_search_messages_with_distance_threshold(
151151
self, memory_messages, async_redis_client
152152
):

tests/test_models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def test_redisearch_result(self):
8383
assert result.dist == 0.75
8484

8585

86-
@pytest.mark.asyncio()
86+
@pytest.mark.asyncio
8787
class TestOpenAIClientWrapper:
8888
@patch.dict(
8989
os.environ,

tests/test_reducer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from utils import Keys
77

88

9-
@pytest.mark.asyncio()
9+
@pytest.mark.asyncio
1010
class TestIncrementalSummarization:
1111
async def test_incremental_summarization_no_context(self, mock_openai_client):
1212
"""Test incremental summarization without previous context"""
@@ -66,7 +66,7 @@ async def test_incremental_summarization_with_context(self, mock_openai_client):
6666

6767

6868
class TestHandleCompaction:
69-
@pytest.mark.asyncio()
69+
@pytest.mark.asyncio
7070
@patch("reducers._incremental_summary")
7171
async def test_handle_compaction(
7272
self, mock_summarization, mock_openai_client, mock_async_redis_client
@@ -126,7 +126,7 @@ async def test_handle_compaction(
126126
"Message 6",
127127
]
128128

129-
@pytest.mark.asyncio()
129+
@pytest.mark.asyncio
130130
@patch("reducers._incremental_summary")
131131
async def test_handle_compaction_no_messages(
132132
self, mock_summarization, mock_openai_client, mock_async_redis_client

0 commit comments

Comments
 (0)