diff --git a/irctest/cases.py b/irctest/cases.py index 30b1aed..4d14b3a 100644 --- a/irctest/cases.py +++ b/irctest/cases.py @@ -160,6 +160,7 @@ class _IrcTestCase(Generic[TController]): def messageDiffers( self, msg: Message, + command: Union[str, None, patma.Operator] = None, params: Optional[List[Union[str, None, patma.Operator]]] = None, target: Optional[str] = None, tags: Optional[ @@ -186,6 +187,14 @@ class _IrcTestCase(Generic[TController]): msg=msg, ) + if command is not None and not patma.match_string(msg.command, command): + fail_msg = ( + fail_msg or "expected command to match {expects}, got {got}: {msg}" + ) + return fail_msg.format( + *extra_format, got=msg.command, expects=command, msg=msg + ) + if prefix is not None and not patma.match_string(msg.prefix, prefix): fail_msg = ( fail_msg or "expected prefix to match {expects}, got {got}: {msg}" @@ -214,7 +223,7 @@ class _IrcTestCase(Generic[TController]): or "expected nick to be {expects}, got {got} instead: {msg}" ) return fail_msg.format( - *extra_format, got=got_nick, expects=nick, param=key, msg=msg + *extra_format, got=got_nick, expects=nick, msg=msg ) return None diff --git a/irctest/self_tests/cases.py b/irctest/self_tests/cases.py index 428a73c..3613298 100644 --- a/irctest/self_tests/cases.py +++ b/irctest/self_tests/cases.py @@ -173,7 +173,7 @@ MESSAGE_SPECS: List[Tuple[Dict, List[str], List[str], List[str]]] = [ ], # and they each error with: [ - "expected command to be PRIVMSG, got PRIVMG", + "expected command to match PRIVMSG, got PRIVMG", "expected tags to match {'tag1': 'bar', RemainingKeys(ANYSTR): ANYOPTSTR}, got {'tag1': 'value1'}", "expected params to match ['#chan', 'hello'], got ['#chan', 'hello2']", "expected params to match ['#chan', 'hello'], got ['#chan2', 'hello']", @@ -206,7 +206,7 @@ MESSAGE_SPECS: List[Tuple[Dict, List[str], List[str], List[str]]] = [ ], # and they each error with: [ - "expected command to be PRIVMSG, got PRIVMG", + "expected command to match PRIVMSG, got PRIVMG", "expected tags to match {StrRe(r'tag[12]'): 'bar', RemainingKeys(ANYSTR): ANYOPTSTR}, got {'tag1': 'value1'}", "expected params to match ['#chan', 'hello'], got ['#chan', 'hello2']", "expected params to match ['#chan', 'hello'], got ['#chan2', 'hello']", @@ -235,7 +235,7 @@ MESSAGE_SPECS: List[Tuple[Dict, List[str], List[str], List[str]]] = [ ], # and they each error with: [ - "expected command to be PRIVMSG, got PRIVMG", + "expected command to match PRIVMSG, got PRIVMG", "expected tags to match {'tag1': 'bar', RemainingKeys(NotStrRe(r'tag2')): ANYOPTSTR}, got {'tag1': 'value1'}", "expected tags to match {'tag1': 'bar', RemainingKeys(NotStrRe(r'tag2')): ANYOPTSTR}, got {'tag1': 'bar', 'tag2': ''}", "expected tags to match {'tag1': 'bar', RemainingKeys(NotStrRe(r'tag2')): ANYOPTSTR}, got {'tag1': 'bar', 'tag2': 'baz'}", @@ -345,7 +345,7 @@ MESSAGE_SPECS: List[Tuple[Dict, List[str], List[str], List[str]]] = [ ], # and they each error with: [ - "expected command to be PING, got PONG" + "expected command to match PING, got PONG" ] ), ] diff --git a/irctest/server_tests/monitor.py b/irctest/server_tests/monitor.py index f5bd808..aa417ec 100644 --- a/irctest/server_tests/monitor.py +++ b/irctest/server_tests/monitor.py @@ -8,6 +8,7 @@ import pytest from irctest import cases, runner from irctest.client_mock import NoMessageException from irctest.numerics import ( + ERR_ERRONEUSNICKNAME, RPL_ENDOFMONLIST, RPL_MONLIST, RPL_MONOFFLINE, @@ -190,14 +191,15 @@ class MonitorTestCase(_BaseMonitorTestCase): self.check_server_support() self.sendLine(1, "MONITOR + *!username@localhost") self.sendLine(1, "MONITOR + *!username@127.0.0.1") + expected_command = StrRe(f"({RPL_MONOFFLINE}|{ERR_ERRONEUSNICKNAME})") try: m = self.getMessage(1) - self.assertMessageMatch(m, command="731") + self.assertMessageMatch(m, command=expected_command) except NoMessageException: pass else: m = self.getMessage(1) - self.assertMessageMatch(m, command="731") + self.assertMessageMatch(m, command=expected_command) self.connectClient("bar") try: m = self.getMessage(1)