Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update repr of important classes with module name and recommended "< … #3001

Merged
merged 3 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update tests which examine repr
  • Loading branch information
kristjanvalur committed Oct 12, 2023
commit d24bbd69d68f9af9c67dc45e9c6c65cb045b20d0
37 changes: 15 additions & 22 deletions tests/test_asyncio/test_connection_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,23 +180,17 @@ async def test_repr_contains_db_info_tcp(self):
async with self.get_pool(
connection_kwargs=connection_kwargs, connection_class=redis.Connection
) as pool:
expected = (
"ConnectionPool<Connection<"
"host=localhost,port=6379,db=1,client_name=test-client>>"
)
assert repr(pool) == expected
expected = "host=localhost,port=6379,db=1,client_name=test-client"
assert expected in repr(pool)

async def test_repr_contains_db_info_unix(self):
connection_kwargs = {"path": "/abc", "db": 1, "client_name": "test-client"}
async with self.get_pool(
connection_kwargs=connection_kwargs,
connection_class=redis.UnixDomainSocketConnection,
) as pool:
expected = (
"ConnectionPool<UnixDomainSocketConnection<"
"path=/abc,db=1,client_name=test-client>>"
)
assert repr(pool) == expected
expected = "path=/abc,db=1,client_name=test-client"
assert expected in repr(pool)


class TestBlockingConnectionPool:
Expand Down Expand Up @@ -293,23 +287,17 @@ def test_repr_contains_db_info_tcp(self):
pool = redis.ConnectionPool(
host="localhost", port=6379, client_name="test-client"
)
expected = (
"ConnectionPool<Connection<"
"host=localhost,port=6379,db=0,client_name=test-client>>"
)
assert repr(pool) == expected
expected = "host=localhost,port=6379,db=0,client_name=test-client"
assert expected in repr(pool)

def test_repr_contains_db_info_unix(self):
pool = redis.ConnectionPool(
connection_class=redis.UnixDomainSocketConnection,
path="abc",
client_name="test-client",
)
expected = (
"ConnectionPool<UnixDomainSocketConnection<"
"path=abc,db=0,client_name=test-client>>"
)
assert repr(pool) == expected
expected = "path=abc,db=0,client_name=test-client"
assert expected in repr(pool)


class TestConnectionPoolURLParsing:
Expand Down Expand Up @@ -634,7 +622,10 @@ def test_connect_from_url_tcp(self):
connection = redis.Redis.from_url("redis://localhost")
pool = connection.connection_pool

assert re.match("(.*)<(.*)<(.*)>>", repr(pool)).groups() == (
print(repr(pool))
assert re.match(
r"< .*?([^\.]+) \( < .*?([^\.]+) \( (.+) \) > \) >", repr(pool), re.VERBOSE
).groups() == (
"ConnectionPool",
"Connection",
"host=localhost,port=6379,db=0",
Expand All @@ -644,7 +635,9 @@ def test_connect_from_url_unix(self):
connection = redis.Redis.from_url("unix:///path/to/socket")
pool = connection.connection_pool

assert re.match("(.*)<(.*)<(.*)>>", repr(pool)).groups() == (
assert re.match(
r"< .*?([^\.]+) \( < .*?([^\.]+) \( (.+) \) > \) >", repr(pool), re.VERBOSE
).groups() == (
"ConnectionPool",
"UnixDomainSocketConnection",
"path=/path/to/socket,db=0",
Expand Down
36 changes: 14 additions & 22 deletions tests/test_connection_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,23 +95,17 @@ def test_repr_contains_db_info_tcp(self):
pool = self.get_pool(
connection_kwargs=connection_kwargs, connection_class=redis.Connection
)
expected = (
"ConnectionPool<Connection<"
"host=localhost,port=6379,db=1,client_name=test-client>>"
)
assert repr(pool) == expected
expected = "host=localhost,port=6379,db=1,client_name=test-client"
assert expected in repr(pool)

def test_repr_contains_db_info_unix(self):
connection_kwargs = {"path": "/abc", "db": 1, "client_name": "test-client"}
pool = self.get_pool(
connection_kwargs=connection_kwargs,
connection_class=redis.UnixDomainSocketConnection,
)
expected = (
"ConnectionPool<UnixDomainSocketConnection<"
"path=/abc,db=1,client_name=test-client>>"
)
assert repr(pool) == expected
expected = "path=/abc,db=1,client_name=test-client"
assert expected in repr(pool)


class TestBlockingConnectionPool:
Expand Down Expand Up @@ -190,23 +184,17 @@ def test_repr_contains_db_info_tcp(self):
pool = redis.ConnectionPool(
host="localhost", port=6379, client_name="test-client"
)
expected = (
"ConnectionPool<Connection<"
"host=localhost,port=6379,db=0,client_name=test-client>>"
)
assert repr(pool) == expected
expected = "host=localhost,port=6379,db=0,client_name=test-client"
assert expected in repr(pool)

def test_repr_contains_db_info_unix(self):
pool = redis.ConnectionPool(
connection_class=redis.UnixDomainSocketConnection,
path="abc",
client_name="test-client",
)
expected = (
"ConnectionPool<UnixDomainSocketConnection<"
"path=abc,db=0,client_name=test-client>>"
)
assert repr(pool) == expected
expected = "path=abc,db=0,client_name=test-client"
assert expected in repr(pool)


class TestConnectionPoolURLParsing:
Expand Down Expand Up @@ -554,7 +542,9 @@ def test_connect_from_url_tcp(self):
connection = redis.Redis.from_url("redis://localhost")
pool = connection.connection_pool

assert re.match("(.*)<(.*)<(.*)>>", repr(pool)).groups() == (
assert re.match(
r"< .*?([^\.]+) \( < .*?([^\.]+) \( (.+) \) > \) >", repr(pool), re.VERBOSE
).groups() == (
"ConnectionPool",
"Connection",
"host=localhost,port=6379,db=0",
Expand All @@ -564,7 +554,9 @@ def test_connect_from_url_unix(self):
connection = redis.Redis.from_url("unix:///path/to/socket")
pool = connection.connection_pool

assert re.match("(.*)<(.*)<(.*)>>", repr(pool)).groups() == (
assert re.match(
r"< .*?([^\.]+) \( < .*?([^\.]+) \( (.+) \) > \) >", repr(pool), re.VERBOSE
).groups() == (
"ConnectionPool",
"UnixDomainSocketConnection",
"path=/path/to/socket,db=0",
Expand Down
Loading