Skip to content
Merged
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 @@ -197,6 +197,8 @@ See also https://github.com/neo4j/neo4j-python-driver/wiki for a full changelog.
- `SummaryCounters`: `repr` and `str` to conform with Python's recommendations.
- `Point` and its subclasses: `repr` to conform with Python's recommendations.
- `Duration` and `ClockTime`: `repr` to be more consistent with other temporal driver types.
- `GqlStatusObject`: `repr` to conform with Python's recommendations.
- `SummaryInputPosition`: `repr` 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 @@ -495,6 +495,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 @@ -744,7 +753,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 @@ -753,7 +762,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