def test_isupport_prefix_undefined(): instance = isupport.ISupport() assert not hasattr(instance, 'PREFIX') with pytest.raises(AttributeError): instance.PREFIX
def test_bot_mixed_mode_types(mockbot, ircfactory): """Ensure mixed argument-required and -not-required modes are handled. Sopel 6.6.6 and older did not behave well. .. seealso:: GitHub issue #1575 (https://github.com/sopel-irc/sopel/pull/1575). """ irc = ircfactory(mockbot) irc.bot._isupport = isupport.ISupport(chanmodes=("be", "", "", "mn", tuple())) irc.channel_joined( '#test', ['Uvoice', 'Uop', 'Uadmin', 'Uvoice2', 'Uop2', 'Uadmin2']) irc.mode_set('#test', '+amovn', ['Uadmin', 'Uop', 'Uvoice']) assert mockbot.channels["#test"].privileges[Identifier("Uadmin")] == ADMIN assert mockbot.channels["#test"].modes["m"] assert mockbot.channels["#test"].privileges[Identifier("Uop")] == OP assert mockbot.channels["#test"].privileges[Identifier("Uvoice")] == VOICE assert mockbot.channels["#test"].modes["n"] irc.mode_set('#test', '+above', ['Uadmin2', 'x!y@z', 'Uop2', 'Uvoice2', 'a!b@c']) assert mockbot.channels["#test"].privileges[Identifier("Uadmin2")] == ADMIN assert "x!y@z" in mockbot.channels["#test"].modes["b"] assert mockbot.channels["#test"].privileges[Identifier("Uop2")] == OP assert mockbot.channels["#test"].privileges[Identifier("Uvoice2")] == VOICE assert "a!b@c" in mockbot.channels["#test"].modes["e"]
def test_bot_mixed_mode_removal(mockbot, ircfactory): """Ensure mixed mode types like ``-h+a`` are handled. Sopel 6.6.6 and older did not handle this correctly. .. seealso:: GitHub issue #1575 (https://github.com/sopel-irc/sopel/pull/1575). """ irc = ircfactory(mockbot) irc.bot._isupport = isupport.ISupport(chanmodes=("b", "", "", "m", tuple())) irc.channel_joined('#test', ['Uvoice', 'Uop']) irc.mode_set('#test', '+qao', ['Uvoice', 'Uvoice', 'Uvoice']) assert mockbot.channels["#test"].privileges[Identifier("Uop")] == 0 assert mockbot.channels["#test"].privileges[Identifier("Uvoice")] == ( ADMIN + OWNER + OP), 'Uvoice got +q, +a, and +o modes' irc.mode_set('#test', '-o+o-qa+v', ['Uvoice', 'Uop', 'Uvoice', 'Uvoice', 'Uvoice']) assert mockbot.channels["#test"].privileges[Identifier("Uop")] == OP, ( 'OP got +o only') assert mockbot.channels["#test"].privileges[Identifier( "Uvoice")] == VOICE, ('Uvoice got -o, -q, -a, then +v')
def test_isupport_chanmodes_undefined(): instance = isupport.ISupport() assert not hasattr(instance, 'CHANMODES') with pytest.raises(AttributeError): instance.CHANMODES
def test_isupport_maxlist_undefined(): instance = isupport.ISupport() assert not hasattr(instance, 'MAXLIST') with pytest.raises(AttributeError): instance.MAXLIST
def test_isupport_chanlimit_undefined(): instance = isupport.ISupport() assert not hasattr(instance, 'CHANLIMIT') with pytest.raises(AttributeError): instance.CHANLIMIT
def test_isupport_targmax_undefined(): instance = isupport.ISupport() assert not hasattr(instance, 'TARGMAX') with pytest.raises(AttributeError): instance.TARGMAX
def test_isupport_getitem_case_insensitive(): """Test access to parameters is case insensitive.""" instance = isupport.ISupport(awaylen=50) assert 'AWAYLEN' in instance assert 'awaylen' in instance assert instance['AWAYLEN'] == 50 assert instance['awaylen'] == 50
def test_isupport_prefix(): instance = isupport.ISupport(prefix=(('o', '@'), ('v', '+'))) assert 'o' in instance.PREFIX assert 'v' in instance.PREFIX assert instance.PREFIX['o'] == '@' assert instance.PREFIX['v'] == '+' with pytest.raises(AttributeError): instance.PREFIX = 'something'
def test_isupport_maxlist(): instance = isupport.ISupport(maxlist=(('Z', 10), ('beI', 25))) assert 'Z' in instance.MAXLIST assert 'beI' in instance.MAXLIST assert instance.MAXLIST['Z'] == 10 assert instance.MAXLIST['beI'] == 25 with pytest.raises(AttributeError): instance.MAXLIST = 'something'
def test_isupport_chanlimit(): instance = isupport.ISupport(chanlimit=(('#', 50), ('$', 10))) assert '#' in instance.CHANLIMIT assert '$' in instance.CHANLIMIT assert instance.CHANLIMIT['#'] == 50 assert instance.CHANLIMIT['$'] == 10 with pytest.raises(AttributeError): instance.CHANLIMIT = 'something'
def test_parse_parameter_prefix_order_property(): """Ensure PREFIX order is maintained in property.""" instance = isupport.ISupport() key, value = isupport.parse_parameter('PREFIX=(qov)~@+') new = instance.apply(prefix=value, ) assert new.PREFIX == OrderedDict((('q', '~'), ('o', '@'), ('v', '+'))) assert tuple(new.PREFIX.keys()) == ('q', 'o', 'v')
def test_isupport_getitem(): """Test basic parameter access.""" instance = isupport.ISupport(AWAYLEN=50) assert 'AWAYLEN' in instance assert 'UNKNOWN' not in instance assert instance['AWAYLEN'] == 50 with pytest.raises(KeyError): instance['UNKNOWN']
def test_isupport_chanmodes(): instance = isupport.ISupport(chanmodes=('b', 'k', 'l', 'imnpst', tuple())) assert 'A' in instance.CHANMODES assert 'B' in instance.CHANMODES assert 'C' in instance.CHANMODES assert 'D' in instance.CHANMODES with pytest.raises(AttributeError): instance.CHANMODES = 'something'
def test_bot_unknown_priv_mode(mockbot, ircfactory): """Ensure modes in `mapping` but not PREFIX are treated as unknown.""" irc = ircfactory(mockbot) irc.bot._isupport = isupport.ISupport(prefix={"o": "@", "v": "+"}) irc.channel_joined("#test", ["Alex", "Bob", "Cheryl"]) irc.mode_set("#test", "+oh", ["Alex", "Bob"]) assert mockbot.channels["#test"].privileges[Identifier("Bob")] == 0 assert mockbot.backend.message_sent == rawlist( "WHO #test" ), "The bot must treat mapped but non-PREFIX modes as unknown."
def test_bot_extra_mode_args(mockbot, ircfactory, caplog): """Test warning on extraneous MODE args.""" irc = ircfactory(mockbot) irc.bot._isupport = isupport.ISupport(chanmodes=("b", "k", "l", "mnt", tuple())) irc.channel_joined("#test", ["Alex", "Bob", "Cheryl"]) mode_msg = ":Sopel!bot@bot MODE #test +m nonsense" mockbot.on_message(mode_msg) assert mockbot.channels["#test"].modes["m"] assert "Too many arguments received for MODE" in caplog.text
def test_isupport_targmax(): instance = isupport.ISupport(targmax=(('JOIN', None), ('PRIVMSG', 3), ('WHOIS', 1))) assert 'JOIN' in instance.TARGMAX assert 'PRIVMSG' in instance.TARGMAX assert 'WHOIS' in instance.TARGMAX assert instance.TARGMAX['JOIN'] is None assert instance.TARGMAX['PRIVMSG'] == 3 assert instance.TARGMAX['WHOIS'] == 1 with pytest.raises(AttributeError): instance.TARGMAX = 'something'
def test_bot_unknown_mode(mockbot, ircfactory): """Ensure modes not in PREFIX or CHANMODES trigger a WHO.""" irc = ircfactory(mockbot) irc.bot._isupport = isupport.ISupport(chanmodes=("b", "", "", "mnt", tuple())) irc.channel_joined("#test", ["Alex", "Bob", "Cheryl"]) irc.mode_set("#test", "+te", ["Alex"]) assert mockbot.channels["#test"].privileges[Identifier("Alex")] == 0 assert mockbot.backend.message_sent == rawlist( "WHO #test" ), "Upon finding an unknown mode, the bot must send a WHO request."
def test_isupport_get(): """Test parameter access through the ``get`` method.""" instance = isupport.ISupport(AWAYLEN=50) assert instance.get('AWAYLEN') == 50 assert instance.get('AWAYLEN', 20) == 50, ( 'Default must be ignored if name exists') assert instance.get('AWAYLEN', default=10) == 50, ( 'Default must be ignored if name exists') assert instance.get('UNKNOWN') is None assert instance.get('UNKNOWN', 20) == 20, ( 'Default must be used if name does not exist') assert instance.get('UNKNOWN', default=10) == 10, ( 'Default must be used if name does not exist')
def test_handle_rpl_channelmodeis_clear(mockbot, ircfactory): """Test RPL_CHANNELMODEIS events clearing previous modes""" irc = ircfactory(mockbot) irc.bot._isupport = isupport.ISupport(chanmodes=("b", "k", "l", "mnt", tuple())) irc.channel_joined("#test", ["Alex", "Bob", "Cheryl"]) rpl_base = ":mercury.libera.chat 324 TestName #test {modes}" mockbot.on_message(rpl_base.format(modes="+knlt hunter2 :1")) mockbot.on_message(rpl_base.format(modes="+kl hunter2 :1")) assert mockbot.channels["#test"].modes["k"] == "hunter2" assert "n" not in mockbot.channels["#test"].modes assert mockbot.channels["#test"].modes["l"] == "1" assert "t" not in mockbot.channels["#test"].modes
def test_isupport_getattr(): """Test using ISUPPORT parameters as read-only attributes.""" instance = isupport.ISupport(awaylen=50) assert hasattr(instance, 'AWAYLEN') assert not hasattr(instance, 'awaylen'), 'attributes are ALL_UPPERCASE' assert not hasattr(instance, 'UNKNOWN') assert instance.AWAYLEN == 50 # you can't set attributes yourself with pytest.raises(AttributeError): instance.AWAYLEN = 20 with pytest.raises(AttributeError): instance.awaylen = 20 with pytest.raises(AttributeError): instance.UNKNOWN = 'not possible'
def test_isupport_apply(): instance = isupport.ISupport() assert 'AWAYLEN' not in instance new = instance.apply(awaylen=50) assert 'AWAYLEN' not in instance assert 'AWAYLEN' in new assert new['AWAYLEN'] == 50 new_removed = new.apply(**{'-AWAYLEN': None, 'NICKLEN': 31}) assert 'AWAYLEN' not in instance assert 'AWAYLEN' in new assert 'AWAYLEN' not in new_removed assert new['AWAYLEN'] == 50, 'original instance must not be modified' assert 'NICKLEN' in new_removed assert new_removed['NICKLEN'] == 31
def test_handle_rpl_channelmodeis(mockbot, ircfactory): """Test handling RPL_CHANNELMODEIS events, response to MODE query.""" rpl_channelmodeis = " ".join([ ":niven.freenode.net", "324", "TestName", "#test", "+knlt", "hunter2", ":1", ]) irc = ircfactory(mockbot) irc.bot._isupport = isupport.ISupport(chanmodes=("b", "k", "l", "mnt", tuple())) irc.channel_joined("#test", ["Alex", "Bob", "Cheryl"]) mockbot.on_message(rpl_channelmodeis) assert mockbot.channels["#test"].modes["k"] == "hunter2" assert mockbot.channels["#test"].modes["n"] assert mockbot.channels["#test"].modes["l"] == "1" assert mockbot.channels["#test"].modes["t"]
def test_isupport_apply_case_insensitive(): """Test removed parameters are case-insensitive.""" instance = isupport.ISupport() new = instance.apply(awaylen=50, NICKLEN=31, channellen=16) new_removed = new.apply(**{ '-awaylen': None, '-NICKLEN': None, 'channellen': 24, }) assert 'AWAYLEN' in new assert 'AWAYLEN' not in new_removed assert 'NICKLEN' in new assert 'NICKLEN' not in new_removed assert 'CHANNELLEN' in new assert 'CHANNELLEN' in new_removed assert new['CHANNELLEN'] == 16 assert new_removed['CHANNELLEN'] == 24 new_removed_ci = new.apply(**{ '-AWAYLEN': None, '-nicklen': None, 'CHANNELLEN': 34, }) assert 'AWAYLEN' in new assert 'AWAYLEN' not in new_removed_ci assert 'NICKLEN' in new assert 'NICKLEN' not in new_removed_ci assert 'CHANNELLEN' in new assert 'CHANNELLEN' in new_removed_ci assert new['CHANNELLEN'] == 16 assert new_removed_ci['CHANNELLEN'] == 34
def test_isupport_setitem(): """Test you can't set a key.""" instance = isupport.ISupport(awaylen=50) with pytest.raises(TypeError): instance['AWAYLEN'] = 10
def test_isupport_chanmodes_undefined(): instance = isupport.ISupport() assert set(instance.CHANMODES.keys()) == set("ABCD") assert set(instance.CHANMODES.values()) == {""}
def test_isupport_removed_parameter(): """Test removed parameters are ignored.""" instance = isupport.ISupport(**{'-AWAYLEN': 50}) assert 'AWAYLEN' not in instance assert '-AWAYLEN' not in instance
def test_isupport_targmax_optional(): instance = isupport.ISupport(targmax=None) assert instance.TARGMAX == {}