From: Daniele Varrazzo Date: Tue, 10 May 2022 10:10:14 +0000 (+0200) Subject: feat: display the pipeline status in the objects repr X-Git-Tag: 3.1~111 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=66bf06794c3b77dcb65101a3300e940127e4c63a;p=thirdparty%2Fpsycopg.git feat: display the pipeline status in the objects repr --- diff --git a/psycopg/psycopg/pq/misc.py b/psycopg/psycopg/pq/misc.py index 1822d604c..b035f2581 100644 --- a/psycopg/psycopg/pq/misc.py +++ b/psycopg/psycopg/pq/misc.py @@ -7,7 +7,7 @@ Various functionalities to make easier to work with the libpq. from typing import cast, NamedTuple, Optional, Union from .abc import PGconn, PGresult -from ._enums import ConnStatus, TransactionStatus +from ._enums import ConnStatus, TransactionStatus, PipelineStatus from .._encodings import pgconn_encoding @@ -88,8 +88,12 @@ def connection_summary(pgconn: PGconn) -> str: """ parts = [] if pgconn.status == ConnStatus.OK: - + # Put together the [STATUS] status = TransactionStatus(pgconn.transaction_status).name + if pgconn.pipeline_status: + status += f", pipeline={PipelineStatus(pgconn.pipeline_status).name}" + + # Put together the (CONNECTION) if not pgconn.host.startswith(b"/"): parts.append(("host", pgconn.host.decode())) if pgconn.port != b"5432": @@ -97,6 +101,7 @@ def connection_summary(pgconn: PGconn) -> str: if pgconn.user != pgconn.db: parts.append(("user", pgconn.user.decode())) parts.append(("database", pgconn.db.decode())) + else: status = ConnStatus(pgconn.status).name diff --git a/tests/test_pipeline.py b/tests/test_pipeline.py index b62e16538..2172c2ff2 100644 --- a/tests/test_pipeline.py +++ b/tests/test_pipeline.py @@ -16,7 +16,7 @@ pytestmark = pytest.mark.libpq(">= 14") def test_repr(conn): with conn.pipeline() as p: assert "psycopg.Pipeline" in repr(p) - assert "[IDLE]" in repr(p) + assert "[IDLE, pipeline=ON]" in repr(p) conn.close() assert "[BAD]" in repr(p) diff --git a/tests/test_pipeline_async.py b/tests/test_pipeline_async.py index 234cc5edc..82a0b5348 100644 --- a/tests/test_pipeline_async.py +++ b/tests/test_pipeline_async.py @@ -19,7 +19,7 @@ pytestmark = [ async def test_repr(aconn): async with aconn.pipeline() as p: assert "psycopg.AsyncPipeline" in repr(p) - assert "[IDLE]" in repr(p) + assert "[IDLE, pipeline=ON]" in repr(p) await aconn.close() assert "[BAD]" in repr(p)