Skip to content

Improve repr string representation of GqlStatusObject #1234

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

Open
wants to merge 1 commit into
base: 6.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ See also https://github.com/neo4j/neo4j-python-driver/wiki for a full changelog.
- The driver incorrectly applied a timeout hint received from the server to both read and write I/O operations.
It is now only applied to read I/O operations.
In turn, a new configuration option `connection_write_timeout` with a default value of `30 seconds` is introduced.
- Adjust `repr` string representation of `GqlStatusObject` to conform with Python's recommendations.
- Adjust `repr` string representation of `SummaryInputPosition` to be more informative.


## Version 5.28
Expand Down
44 changes: 0 additions & 44 deletions src/neo4j/_work/gql_status.py

This file was deleted.

13 changes: 11 additions & 2 deletions src/neo4j/_work/summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,15 @@ def __str__(self) -> str:
f"line: {self.line}, column: {self.column}, offset: {self.offset}"
)

def __repr__(self) -> str:
return (
f"<{self.__class__.__name__} "
f"line={self.line!r}, "
f"column={self.column!r}, "
f"offset={self.offset!r}"
">"
)


# Deprecated alias for :class:`.SummaryInputPosition`.
#
Expand Down Expand Up @@ -718,7 +727,7 @@ def __str__(self) -> str:

def __repr__(self) -> str:
return (
"GqlStatusObject("
f"<{self.__class__.__name__} "
f"gql_status={self.gql_status!r}, "
f"status_description={self.status_description!r}, "
f"position={self.position!r}, "
Expand All @@ -727,7 +736,7 @@ def __repr__(self) -> str:
f"raw_severity={self.raw_severity!r}, "
f"severity={self.severity!r}, "
f"diagnostic_record={self.diagnostic_record!r}"
")"
">"
)

@property
Expand Down
71 changes: 71 additions & 0 deletions tests/unit/common/work/test_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
SummaryCounters,
SummaryInputPosition,
)
from neo4j._work.summary import (
_CLASSIFICATION_LOOKUP,
_SEVERITY_LOOKUP,
)

from ...._deprecated_imports import (
NotificationCategory,
Expand Down Expand Up @@ -388,6 +392,73 @@ def test_non_notification_statuses(raw_status, summary_args_kwargs) -> None:
assert_is_non_notification_status(status)


@pytest.mark.parametrize(
"raw_status",
(
STATUS_SUCCESS,
STATUS_OMITTED_RESULT,
STATUS_NO_DATA,
StatusOrderHelper.make_raw_status(0, "SUCCESS"),
StatusOrderHelper.make_raw_status(0, "OMITTED"),
StatusOrderHelper.make_raw_status(0, "NODATA"),
StatusOrderHelper.make_raw_status(0, "WARNING"),
StatusOrderHelper.make_raw_status(0, "INFORMATION"),
),
)
def test_status_order_helper_repr(raw_status, summary_args_kwargs) -> None:
args, kwargs = summary_args_kwargs
kwargs["metadata"]["statuses"] = [raw_status]

expected_status = raw_status["gql_status"]
expected_description = raw_status["status_description"]
expected_diag_record = raw_status.get("diagnostic_record", {})
expected_position = SummaryInputPosition._from_metadata(
expected_diag_record.get("_position")
)
expected_raw_cls = expected_diag_record.get("_classification")
expected_cls = _CLASSIFICATION_LOOKUP.get(
expected_raw_cls, NotificationClassification.UNKNOWN
)
expected_raw_sev = expected_diag_record.get("_severity")
expected_sev = _SEVERITY_LOOKUP.get(
expected_raw_sev, NotificationSeverity.UNKNOWN
)

expected = (
"<GqlStatusObject "
f"gql_status={expected_status!r}, "
f"status_description={expected_description!r}, "
f"position={expected_position!r}, "
f"raw_classification={expected_raw_cls!r}, "
f"classification={expected_cls!r}, "
f"raw_severity={expected_raw_sev!r}, "
f"severity={expected_sev!r}, "
f"diagnostic_record={expected_diag_record!r}"
">"
)

summary = ResultSummary(*args, **kwargs)
status_objects: t.Sequence[GqlStatusObject] = summary.gql_status_objects

assert len(status_objects) == 1
status = status_objects[0]

assert repr(status) == expected


def test_summary_input_position_repr():
position = SummaryInputPosition._from_metadata(
{
"line": 42,
"column": 1337,
"offset": 666,
}
)
expected = "<SummaryInputPosition line=42, column=1337, offset=666>"

assert repr(position) == expected


@pytest.mark.parametrize(
"types",
(
Expand Down