Skip to content

Commit be0b9e4

Browse files
committed
Fix up VerifyMessage repr
1 parent 946f1f4 commit be0b9e4

1 file changed

Lines changed: 23 additions & 8 deletions

File tree

discord/ext/test/verify.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,21 @@
1717
from .utils import embed_eq, activity_eq
1818

1919

20+
def _msg_to_str(msg: discord.Message) -> str:
21+
author = f"author=\"{msg.author.name}\""
22+
out = [author]
23+
if msg.content:
24+
out.append(f"content=\"{msg.content}\"")
25+
if msg.embeds:
26+
embeds = ", ".join(map(lambda e: str(e.to_dict()), msg.embeds))
27+
out.append(f"embeds=[{embeds}]")
28+
if msg.attachments:
29+
attachments = ", ".join(map(lambda a: a.filename, msg.attachments))
30+
out.append(f"attachments=[{attachments}]")
31+
inner = " ".join(out)
32+
return f"Message({inner})"
33+
34+
2035
class _Undef:
2136
_singleton = None
2237

@@ -64,11 +79,11 @@ def __del__(self) -> None:
6479
import warnings
6580
warnings.warn("VerifyMessage dropped without being used, did you forget an `assert`?", RuntimeWarning)
6681

67-
def __str__(self) -> str:
68-
if self._used is not _Undef:
69-
return f"Expected {self._expectation()}, found {self._found}"
82+
def __repr__(self) -> str:
83+
if self._used is not _undefined:
84+
return f"<VerifyMessage expected=[{self._expectation()}] found={_msg_to_str(self._used)}>"
7085
else:
71-
return f"VerifyMessage(expects={self._expectation()})"
86+
return f"<VerifyMessage expects={self._expectation()}>"
7287

7388
def __bool__(self) -> bool:
7489
self._used = None
@@ -94,11 +109,11 @@ def _expectation(self) -> str:
94109
return "no messages"
95110
else:
96111
contains = "contains"
97-
content = f"content={self._content}" if self._content is not _Undef else ""
98-
embed = f"embed={self._embed}" if self._embed is not _Undef else ""
99-
attachment = f"attachment={self._attachment}" if self._attachment is not _Undef else ""
112+
content = f"content=\"{self._content}\"" if self._content is not _undefined else ""
113+
embed = f"embed={str(self._embed.to_dict())}" if self._embed is not _undefined else ""
114+
attachment = f"attachment={self._attachment}" if self._attachment is not _undefined else ""
100115
event = " ".join(filter(lambda x: x, [contains, content, embed, attachment]))
101-
return f"message {event}"
116+
return f"{event}"
102117

103118
def _diff_msg(self) -> str:
104119
if self._nothing:

0 commit comments

Comments
 (0)