Skip to content

Commit 2f88e92

Browse files
Fix linting issues
- Fix import order in cluster.py to resolve I001 linting error - Remove trailing whitespace in MaxConnectionsError class in exceptions.py - Fix whitespace issues in test_max_connections_error.py
1 parent a7cd993 commit 2f88e92

File tree

3 files changed

+16
-17
lines changed

3 files changed

+16
-17
lines changed

redis/cluster.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@
3737
ConnectionError,
3838
CrossSlotTransactionError,
3939
DataError,
40-
MaxConnectionsError,
4140
ExecAbortError,
4241
InvalidPipelineStack,
42+
MaxConnectionsError,
4343
MovedError,
4444
RedisClusterException,
4545
RedisError,

redis/exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ class MaxConnectionsError(ConnectionError):
225225
Raised when a connection pool has reached its max_connections limit.
226226
This indicates pool exhaustion rather than an actual connection failure.
227227
"""
228-
228+
229229
pass
230230

231231

tests/test_max_connections_error.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ class DummyConnection(ConnectionInterface):
88
"""A dummy connection class for testing that doesn't actually connect to Redis"""
99
def __init__(self, *args, **kwargs):
1010
self.connected = False
11-
11+
1212
def connect(self):
1313
self.connected = True
14-
14+
1515
def disconnect(self):
1616
self.connected = False
17-
17+
1818
def register_connect_callback(self, callback): pass
1919
def deregister_connect_callback(self, callback): pass
2020
def set_parser(self, parser_class): pass
@@ -31,15 +31,14 @@ def read_response(self, disable_decoding=False, **kwargs): return "PONG"
3131
def test_max_connections_error_inheritance():
3232
"""Test that MaxConnectionsError is a subclass of ConnectionError"""
3333
assert issubclass(redis.MaxConnectionsError, redis.ConnectionError)
34-
3534

3635
@pytest.mark.onlynoncluster
3736
def test_connection_pool_raises_max_connections_error():
3837
"""Test that ConnectionPool raises MaxConnectionsError and not ConnectionError"""
3938
# Use a dummy connection class that doesn't try to connect to a real Redis server
4039
pool = redis.ConnectionPool(max_connections=1, connection_class=DummyConnection)
4140
pool.get_connection()
42-
41+
4342
with pytest.raises(redis.MaxConnectionsError):
4443
pool.get_connection()
4544

@@ -55,34 +54,34 @@ def test_cluster_handles_max_connections_error():
5554
cluster.RedisClusterRequestTTL = 3 # Set the TTL to avoid infinite loops
5655
cluster.nodes_manager = mock.MagicMock()
5756
node = mock.MagicMock()
58-
57+
5958
# Mock get_redis_connection to return a mock Redis client
6059
redis_conn = mock.MagicMock()
6160
cluster.get_redis_connection.return_value = redis_conn
62-
61+
6362
# Setup get_connection to be called and return a connection that will raise
6463
connection = mock.MagicMock()
65-
64+
6665
# Patch the get_connection function in the cluster module
67-
with mock.patch('redis.cluster.get_connection', return_value=connection) as mock_get_conn:
66+
with mock.patch('redis.cluster.get_connection', return_value=connection):
6867
# Test MaxConnectionsError
6968
connection.send_command.side_effect = redis.MaxConnectionsError("Too many connections")
70-
69+
7170
# Call the method and check that the exception is raised
7271
with pytest.raises(redis.MaxConnectionsError):
7372
redis.RedisCluster._execute_command(cluster, node, "GET", "key")
74-
73+
7574
# Verify nodes_manager.initialize was NOT called
7675
cluster.nodes_manager.initialize.assert_not_called()
77-
76+
7877
# Reset the mock for the next test
7978
cluster.nodes_manager.initialize.reset_mock()
80-
79+
8180
# Now test with regular ConnectionError to ensure it DOES reinitialize
8281
connection.send_command.side_effect = redis.ConnectionError("Connection lost")
83-
82+
8483
with pytest.raises(redis.ConnectionError):
8584
redis.RedisCluster._execute_command(cluster, node, "GET", "key")
86-
85+
8786
# Verify nodes_manager.initialize WAS called
8887
cluster.nodes_manager.initialize.assert_called_once()

0 commit comments

Comments
 (0)