def test_servername(self): prefix = IrcMessagePrefix(servername='localhost') self.assertEqual(prefix.servername, 'localhost') self.assertIs(prefix.nick, None) self.assertIs(prefix.user, None) self.assertIs(prefix.host, None) self.assertEqual(prefix, IrcMessagePrefix('localhost'))
def test_nick(self): prefix = IrcMessagePrefix(nick='BotGotsThis') self.assertIs(prefix.servername, None) self.assertEqual(prefix.nick, 'BotGotsThis') self.assertIs(prefix.user, None) self.assertIs(prefix.host, None) self.assertEqual(prefix, IrcMessagePrefix(None, 'BotGotsThis'))
def test_servername_ip_address(self): prefix = IrcMessagePrefix(servername='127.0.0.1') self.assertEqual(prefix.servername, '127.0.0.1') self.assertIs(prefix.nick, None) self.assertIs(prefix.user, None) self.assertIs(prefix.host, None) self.assertEqual(prefix, IrcMessagePrefix('127.0.0.1'))
def test_nick_host(self): prefix = IrcMessagePrefix(nick='MeGotsThis', host='localhost') self.assertIs(prefix.servername, None) self.assertEqual(prefix.nick, 'MeGotsThis') self.assertIsNone(prefix.user) self.assertEqual(prefix.host, 'localhost') self.assertEqual( prefix, IrcMessagePrefix(None, 'MeGotsThis', None, 'localhost'))
def test_parse_prefix_servername_command_params_middle_trailing(self): self.assertEqual( IrcMessage.parse(':tmi.twitch.tv PONG tmi.twitch.tv :botgotsthis'), ParsedMessage(None, IrcMessagePrefix(servername='tmi.twitch.tv'), 'PONG', IrcMessageParams('tmi.twitch.tv', 'botgotsthis')))
def test_from_twitch_privmsg(self): self.assertEqual( IrcMessage.fromMessage( '@badges=broadcaster/1;color=#DAA520;display-name=BotGotsThis;' 'emotes=25:6-10;mod=1;room-id=42553092;subscriber=0;turbo=0;' 'user-id=55612319;user-type=mod ' ':[email protected] ' 'PRIVMSG #botgotsthis :Hello Kappa'), IrcMessage( tags=IrcMessageTagsReadOnly({ 'badges': 'broadcaster/1', 'color': '#DAA520', 'display-name': 'BotGotsThis', 'emotes': '25:6-10', 'mod': '1', 'room-id': '42553092', 'subscriber': '0', 'turbo': '0', 'user-id': '55612319', 'user-type': 'mod' }), prefix=IrcMessagePrefix(nick='botgotsthis', user='******', host='botgotsthis.tmi.twitch.tv'), command='PRIVMSG', params=IrcMessageParams(middle='#botgotsthis', trailing='Hello Kappa')))
def test_from_twitch_001(self): self.assertEqual( IrcMessage.fromMessage( ':tmi.twitch.tv 001 botgotsthis :Welcome, GLHF!'), IrcMessage(prefix=IrcMessagePrefix(servername='tmi.twitch.tv'), command=1, params=IrcMessageParams(middle='botgotsthis', trailing='Welcome, GLHF!')))
def test_parse_multiple_spaces(self): self.assertEqual( IrcMessage.parse('''\ @multiple=spaces :will!be@used HERE to test :if this passes'''), ParsedMessage( IrcMessageTagsReadOnly({'multiple': 'spaces'}), IrcMessagePrefix(nick='will', user='******', host='used'), 'HERE', IrcMessageParams('to test', 'if this passes')))
def test_parse_prefix_command_params_middle(self): self.assertEqual( IrcMessage.parse('''\ :[email protected] JOIN #botgotsthis'''), ParsedMessage(None, IrcMessagePrefix(nick='bot_gots_this', user='******', host='botgotsthis.tmi.twitch.tv'), 'JOIN', IrcMessageParams('#botgotsthis')))
def test_str_magic_prefix_command_params(self): self.assertEqual( str(IrcMessage( prefix=IrcMessagePrefix(nick='botgotsthis', user='******', host='botgotsthis.tmi.twitch.tv'), command='PART', params=IrcMessageParams('#botgotsthis'))), '''\ :[email protected] PART #botgotsthis''')
def test_from_prefix_command_param_middle(self): self.assertEqual( IrcMessage.fromMessage('''\ :[email protected] JOIN #botgotsthis'''), IrcMessage( prefix=IrcMessagePrefix(nick='botgotsthis', user='******', host='botgotsthis.tmi.twitch.tv'), command='JOIN', params=IrcMessageParams(middle='#botgotsthis')))
def test_str_tags_magic_prefix_command_params(self): message = IrcMessage( tags=IrcMessageTagsReadOnly({ 'broadcaster-lang': '', 'emote-only': '0', 'r9k': '0', 'slow': '0', 'subs-only': '0' }), prefix=IrcMessagePrefix(servername='tmi.twitch.tv'), command='ROOMSTATE', params=IrcMessageParams('#botgotsthis')) self.assertEqual( str(message), '@' + str(message.tags) + ' :tmi.twitch.tv ROOMSTATE #botgotsthis')
def test_tags_prefix_command_params(self): message = IrcMessage( tags=IrcMessageTagsReadOnly({ 'broadcaster-lang': '', 'emote-only': '0', 'r9k': '0', 'slow': '0', 'subs-only': '0' }), prefix=IrcMessagePrefix(servername='tmi.twitch.tv'), command='ROOMSTATE', params=IrcMessageParams('#botgotsthis')) self.assertEqual(len(message.tags), 5) self.assertEqual(message.tags['broadcaster-lang'], '') self.assertEqual(message.tags['emote-only'], '0') self.assertEqual(message.tags['r9k'], '0') self.assertEqual(message.tags['slow'], '0') self.assertEqual(message.tags['subs-only'], '0') self.assertEqual(message.prefix.servername, 'tmi.twitch.tv') self.assertIsNone(message.prefix.nick) self.assertIsNone(message.prefix.user) self.assertIsNone(message.prefix.host) self.assertEqual(message.command, 'ROOMSTATE') self.assertIs(message.params.middle, '#botgotsthis') self.assertIs(message.params.trailing, None) self.assertEqual( message, IrcMessage( tags=IrcMessageTagsReadOnly({ 'broadcaster-lang': '', 'emote-only': '0', 'r9k': '0', 'slow': '0', 'subs-only': '0' }), prefix=IrcMessagePrefix(servername='tmi.twitch.tv'), command='ROOMSTATE', params=IrcMessageParams('#botgotsthis')))
def test_prefix_command_params(self): message = IrcMessage( prefix=IrcMessagePrefix( nick='botgotsthis', user='******', host='botgotsthis.tmi.twitch.tv'), command='PART', params=IrcMessageParams('#botgotsthis')) self.assertIsNone(message.prefix.servername) self.assertEqual(message.prefix.nick, 'botgotsthis') self.assertEqual(message.prefix.user, 'botgotsthis') self.assertEqual(message.prefix.host, 'botgotsthis.tmi.twitch.tv') self.assertEqual(message.command, 'PART') self.assertIs(message.params.middle, '#botgotsthis') self.assertIs(message.params.trailing, None) self.assertEqual( message, IrcMessage( prefix=IrcMessagePrefix( nick='botgotsthis', user='******', host='botgotsthis.tmi.twitch.tv'), command='PART', params=IrcMessageParams('#botgotsthis')))
def test_str_magic_nick_user_host(self): prefix = IrcMessagePrefix(nick='MeGotsThis', user='******', host='localhost') self.assertEqual(str(prefix), 'MeGotsThis!BotGotsThis@localhost')
def test_from_nick_user(self): self.assertEqual(IrcMessagePrefix.fromPrefix('Kappa!Keepo'), IrcMessagePrefix(nick='Kappa', user='******'))
def test_str_magic_nick_user(self): prefix = IrcMessagePrefix(nick='MeGotsThis', user='******') self.assertEqual(str(prefix), 'MeGotsThis!BotGotsThis')
def test_str_magic_servername_ip_address(self): prefix = IrcMessagePrefix(servername='127.0.0.1') self.assertEqual(str(prefix), '127.0.0.1')
def test_from_nick(self): self.assertEqual(IrcMessagePrefix.fromPrefix('Kappa'), IrcMessagePrefix(nick='Kappa'))
def test_from_nick_host(self): self.assertEqual(IrcMessagePrefix.fromPrefix('Kappa!Keepo@localhost'), IrcMessagePrefix(nick='Kappa', user='******', host='localhost'))
def test_parse_servername(self): self.assertEqual(IrcMessagePrefix.parse('megotsthis.com'), ParsedPrefix('megotsthis.com', None, None, None))
def test_parse_nick_number_alpha(self): self.assertEqual(IrcMessagePrefix.parse('123abc'), ParsedPrefix(None, '123abc', None, None))
def test_parse_nick(self): self.assertEqual(IrcMessagePrefix.parse('Kappa'), ParsedPrefix(None, 'Kappa', None, None))
def test_parse_servername_ip_addr(self): self.assertEqual(IrcMessagePrefix.parse('127.0.0.1'), ParsedPrefix('127.0.0.1', None, None, None))
def test_str_magic_nick(self): prefix = IrcMessagePrefix(nick='BotGotsThis') self.assertEqual(str(prefix), 'BotGotsThis')
def test_parse_nick_user_host(self): self.assertEqual(IrcMessagePrefix.parse('Kappa!Keepo@localhost'), ParsedPrefix(None, 'Kappa', 'Keepo', 'localhost'))
def test_parse_nick_user_host_2(self): self.assertEqual( IrcMessagePrefix.parse('[email protected]'), ParsedPrefix(None, 'MeGotsThis', 'BotGotsThis', 'megotsthis.com'))
def test_parse_from_twitch(self): self.assertEqual( IrcMessagePrefix.parse('''\ [email protected]'''), ParsedPrefix(None, 'botgotsthis', 'botgotsthis', 'botgotsthis.tmi.twitch.tv'))
def test_parse_nick_user(self): self.assertEqual(IrcMessagePrefix.parse('Kappa!Keepo'), ParsedPrefix(None, 'Kappa', 'Keepo', None))
def test_from_servername(self): self.assertEqual(IrcMessagePrefix.fromPrefix('megotsthis.com'), IrcMessagePrefix(servername='megotsthis.com'))