diff options
author | Mark Roberts <mark@apsalar> | 2013-11-05 12:35:11 -0800 |
---|---|---|
committer | Mark Roberts <mark@apsalar> | 2013-11-05 12:35:11 -0800 |
commit | 64827106e5233e54ee43c2b1e475c9270534f197 (patch) | |
tree | feea943d116ea7bf7680d55c4ae0e9ddc42bb961 /tests/test_connection_pool.py | |
parent | 3604b5a55bd7923788a1a3ff46afac5e60d78b46 (diff) | |
download | redis-py-64827106e5233e54ee43c2b1e475c9270534f197.tar.gz |
Move repr to Connection and UnixDomainConnection. Add repr support to Redis, ConnectionPool, and BlockingConnectionPool
Diffstat (limited to 'tests/test_connection_pool.py')
-rw-r--r-- | tests/test_connection_pool.py | 59 |
1 files changed, 52 insertions, 7 deletions
diff --git a/tests/test_connection_pool.py b/tests/test_connection_pool.py index 0af1057..80deb64 100644 --- a/tests/test_connection_pool.py +++ b/tests/test_connection_pool.py @@ -3,12 +3,15 @@ import os import pytest import redis import time +import re from threading import Thread from redis._compat import Queue class DummyConnection(object): + description_format = "DummyConnection<>" + def __init__(self, **kwargs): self.kwargs = kwargs self.pid = os.getpid() @@ -48,6 +51,28 @@ class TestConnectionPoolCase(object): c2 = pool.get_connection('_') assert c1 == c2 + def test_repr_contains_db_info_tcp(self): + pool = redis.ConnectionPool(host='localhost', port=6379, db=0) + + assert re.match('(.*)<(.*)<(.*)>>', repr(pool)).groups() == ( + 'ConnectionPool', + 'Connection', + 'host=localhost,port=6379,db=0', + ) + + def test_repr_contains_db_info_unix(self): + pool = redis.ConnectionPool( + connection_class=redis.UnixDomainSocketConnection, + path='abc', + db=0, + ) + + assert re.match('(.*)<(.*)<(.*)>>', repr(pool)).groups() == ( + 'ConnectionPool', + 'UnixDomainSocketConnection', + 'path=abc,db=0', + ) + class TestBlockingConnectionPool(object): def get_pool(self, connection_info=None, max_connections=10, timeout=20): @@ -107,9 +132,35 @@ class TestBlockingConnectionPool(object): c2 = pool.get_connection('_') assert c1 == c2 + def test_repr_contains_db_info_tcp(self): + pool = redis.BlockingConnectionPool( + host='localhost', + port=6379, + db=0, + ) + + assert re.match('(.*)<(.*)<(.*)>>', repr(pool)).groups() == ( + 'BlockingConnectionPool', + 'Connection', + 'host=localhost,port=6379,db=0', + ) + + def test_repr_contains_db_info_unix(self): + pool = redis.BlockingConnectionPool( + connection_class=redis.UnixDomainSocketConnection, + path='abc', + db=0 + ) + + assert re.match('(.*)<(.*)<(.*)>>', repr(pool)).groups() == ( + 'BlockingConnectionPool', + 'UnixDomainSocketConnection', + 'path=abc,db=0', + ) + class TestConnection(object): - def test_on_connect_error(self, r): + def test_on_connect_error(self): """ An error in Connection.on_connect should disconnect from the server see for details: https://github.com/andymccurdy/redis-py/issues/368 @@ -123,9 +174,3 @@ class TestConnection(object): pool = bad_connection.connection_pool assert len(pool._available_connections) == 1 assert not pool._available_connections[0]._sock - - def test_repr_contains_db_info(self, r): - """ - Repr should contain database connection info - """ - assert repr(redis.Redis()) == 'Redis<host=localhost,port=6379,db=0>' |