Skip to content

Commit 5a9c628

Browse files
committed
chore: update mismatch repr
The mismatches are simple enough that the representation can be made Python-parseable. Signed-off-by: JP-Ellis <[email protected]>
1 parent ad2da2b commit 5a9c628

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

src/pact/error.py

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,9 @@ def __repr__(self) -> str:
191191
"""
192192
Information-rich string representation of the GenericMismatch.
193193
"""
194-
return f"<GenericMismatch: {self.type!r}>"
194+
return "GenericMismatch({})".format(
195+
", ".join(f"{key}={value!r}" for key, value in self._data.items())
196+
)
195197

196198
def __str__(self) -> str:
197199
"""
@@ -255,7 +257,7 @@ def __repr__(self) -> str:
255257
"""
256258
Information-rich string representation of the MissingRequest.
257259
"""
258-
return "<MissingRequest: {}>".format(
260+
return "MissingRequest({})".format(
259261
", ".join([
260262
f"method={self.method!r}",
261263
f"path={self.path!r}",
@@ -328,7 +330,7 @@ def __repr__(self) -> str:
328330
"""
329331
Information-rich string representation of the RequestNotFound.
330332
"""
331-
return "<RequestNotFound: {}>".format(
333+
return "RequestNotFound({})".format(
332334
", ".join([
333335
f"method={self.method!r}",
334336
f"path={self.path!r}",
@@ -403,7 +405,7 @@ def __repr__(self) -> str:
403405
"""
404406
Information-rich string representation of the RequestMismatch.
405407
"""
406-
return "<RequestMismatch: {}>".format(
408+
return "RequestMismatch({})".format(
407409
", ".join([
408410
f"method={self.method!r}",
409411
f"path={self.path!r}",
@@ -465,7 +467,12 @@ def __repr__(self) -> str:
465467
"""
466468
Information-rich string representation of the MethodMismatch.
467469
"""
468-
return f"<MethodMismatch: expected={self.expected!r}, actual={self.actual!r}>"
470+
return "MethodMismatch({})".format(
471+
", ".join([
472+
f"expected={self.expected!r}",
473+
f"actual={self.actual!r}",
474+
])
475+
)
469476

470477
def __str__(self) -> str:
471478
"""
@@ -529,7 +536,7 @@ def __repr__(self) -> str:
529536
"""
530537
Information-rich string representation of the PathMismatch.
531538
"""
532-
return "<PathMismatch: {}>".format(
539+
return "PathMismatch({})".format(
533540
", ".join([
534541
f"expected={self.expected!r}",
535542
f"actual={self.actual!r}",
@@ -603,7 +610,7 @@ def __repr__(self) -> str:
603610
"""
604611
Information-rich string representation of the StatusMismatch.
605612
"""
606-
return "<StatusMismatch: {}>".format(
613+
return "StatusMismatch({})".format(
607614
", ".join([
608615
f"expected={self.expected!r}",
609616
f"actual={self.actual!r}",
@@ -694,7 +701,7 @@ def __repr__(self) -> str:
694701
"""
695702
Information-rich string representation of the QueryMismatch.
696703
"""
697-
return "<QueryMismatch: {}>".format(
704+
return "QueryMismatch({})".format(
698705
", ".join([
699706
f"parameter={self.parameter!r}",
700707
f"expected={self.expected!r}",
@@ -776,7 +783,7 @@ def __repr__(self) -> str:
776783
"""
777784
Information-rich string representation of the HeaderMismatch.
778785
"""
779-
return "<HeaderMismatch: {}>".format(
786+
return "HeaderMismatch({})".format(
780787
", ".join([
781788
f"key={self.key!r}",
782789
f"expected={self.expected!r}",
@@ -884,7 +891,7 @@ def __repr__(self) -> str:
884891
"""
885892
Information-rich string representation of the BodyTypeMismatch.
886893
"""
887-
return "<BodyTypeMismatch: {}>".format(
894+
return "BodyTypeMismatch({})".format(
888895
", ".join([
889896
f"expected={self.expected!r}",
890897
f"actual={self.actual!r}",
@@ -973,7 +980,7 @@ def __repr__(self) -> str:
973980
"""
974981
Information-rich string representation of the BodyMismatch.
975982
"""
976-
return "<BodyMismatch: {}>".format(
983+
return "BodyMismatch({})".format(
977984
", ".join([
978985
f"path={self.path!r}",
979986
f"expected={self.expected!r}",
@@ -1055,7 +1062,7 @@ def __repr__(self) -> str:
10551062
"""
10561063
Information-rich string representation of the MetadataMismatch.
10571064
"""
1058-
return "<MetadataMismatch: {}>".format(
1065+
return "MetadataMismatch({})".format(
10591066
", ".join([
10601067
f"key={self.key!r}",
10611068
f"expected={self.expected!r}",
@@ -1104,8 +1111,8 @@ def __repr__(self) -> str:
11041111
"""
11051112
Information-rich string representation of the MismatchesError.
11061113
"""
1107-
return "<MismatchesError: {}>".format(
1108-
[f"{m!r}" for m in self._mismatches],
1114+
return "MismatchesError({})".format(
1115+
", ".join(f"{m!r}" for m in self._mismatches)
11091116
)
11101117

11111118
def __str__(self) -> str:

0 commit comments

Comments
 (0)