2
2
Pytest configuration and fixtures for Redis MCP Server tests.
3
3
"""
4
4
5
- import pytest
6
5
from unittest .mock import Mock , patch
6
+
7
+ import pytest
7
8
import redis
8
- from redis .exceptions import RedisError , ConnectionError , TimeoutError
9
+ from redis .exceptions import ConnectionError , RedisError , TimeoutError
9
10
10
11
11
12
@pytest .fixture
@@ -25,7 +26,9 @@ def mock_redis_cluster():
25
26
@pytest .fixture
26
27
def mock_redis_connection_manager ():
27
28
"""Mock the RedisConnectionManager to return a mock Redis connection."""
28
- with patch ('src.common.connection.RedisConnectionManager.get_connection' ) as mock_get_conn :
29
+ with patch (
30
+ "src.common.connection.RedisConnectionManager.get_connection"
31
+ ) as mock_get_conn :
29
32
mock_redis = Mock (spec = redis .Redis )
30
33
mock_get_conn .return_value = mock_redis
31
34
yield mock_redis
@@ -75,7 +78,7 @@ def sample_json_data():
75
78
"name" : "John Doe" ,
76
79
"age" : 30 ,
77
80
"city" : "New York" ,
78
- "hobbies" : ["reading" , "swimming" ]
81
+ "hobbies" : ["reading" , "swimming" ],
79
82
}
80
83
81
84
@@ -87,14 +90,17 @@ def redis_error_scenarios():
87
90
"timeout_error" : TimeoutError ("Operation timed out" ),
88
91
"generic_error" : RedisError ("Generic Redis error" ),
89
92
"auth_error" : RedisError ("NOAUTH Authentication required" ),
90
- "wrong_type" : RedisError ("WRONGTYPE Operation against a key holding the wrong kind of value" ),
93
+ "wrong_type" : RedisError (
94
+ "WRONGTYPE Operation against a key holding the wrong kind of value"
95
+ ),
91
96
}
92
97
93
98
94
99
@pytest .fixture (autouse = True )
95
100
def reset_connection_manager ():
96
101
"""Reset the RedisConnectionManager singleton before each test."""
97
102
from src .common .connection import RedisConnectionManager
103
+
98
104
RedisConnectionManager ._instance = None
99
105
yield
100
106
RedisConnectionManager ._instance = None
@@ -103,15 +109,15 @@ def reset_connection_manager():
103
109
@pytest .fixture
104
110
def mock_numpy_array ():
105
111
"""Mock numpy array for vector testing."""
106
- with patch (' numpy.array' ) as mock_array :
107
- mock_array .return_value .tobytes .return_value = b' mock_binary_data'
112
+ with patch (" numpy.array" ) as mock_array :
113
+ mock_array .return_value .tobytes .return_value = b" mock_binary_data"
108
114
yield mock_array
109
115
110
116
111
117
@pytest .fixture
112
118
def mock_numpy_frombuffer ():
113
119
"""Mock numpy frombuffer for vector testing."""
114
- with patch (' numpy.frombuffer' ) as mock_frombuffer :
120
+ with patch (" numpy.frombuffer" ) as mock_frombuffer :
115
121
mock_frombuffer .return_value .tolist .return_value = [0.1 , 0.2 , 0.3 ]
116
122
yield mock_frombuffer
117
123
@@ -121,6 +127,7 @@ def mock_numpy_frombuffer():
121
127
def event_loop ():
122
128
"""Create an event loop for async tests."""
123
129
import asyncio
130
+
124
131
loop = asyncio .new_event_loop ()
125
132
yield loop
126
133
loop .close ()
0 commit comments