3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-27 21:19:31 +01:00

reverse_modes: deduplicate reversing modes with arguments

This commit is contained in:
James Lu 2019-08-26 16:07:29 -07:00
parent d93c071446
commit a1f3af9099
2 changed files with 29 additions and 0 deletions

View File

@ -1223,6 +1223,10 @@ class PyLinkNetworkCoreWithUtils(PyLinkNetworkCore):
log.debug("(%s) reverse_modes: skipping reversing '%s %s' with %s since it " log.debug("(%s) reverse_modes: skipping reversing '%s %s' with %s since it "
"wasn't previously set.", self.name, char, arg, mpair) "wasn't previously set.", self.name, char, arg, mpair)
continue continue
elif mpair in newmodes:
# Check the same for regular modes that previously didn't exist
log.debug("(%s) reverse_modes: skipping duplicate reverse mode %s", self.name, mpair)
continue
newmodes.append(mpair) newmodes.append(mpair)
log.debug('(%s) reverse_modes: new modes: %s', self.name, newmodes) log.debug('(%s) reverse_modes: new modes: %s', self.name, newmodes)

View File

@ -761,4 +761,29 @@ class BaseProtocolTest(unittest.TestCase):
out = self.p.reverse_modes('#weirdstuff', '-b+b *!*@* *!*@*') # -+ cycle existing ban out = self.p.reverse_modes('#weirdstuff', '-b+b *!*@* *!*@*') # -+ cycle existing ban
self.assertEqual(out, '-b *!*@*') # Ugly but OK self.assertEqual(out, '-b *!*@*') # Ugly but OK
def test_reverse_modes_cycle_arguments(self):
# All of these cases are ugly, sometimes unsetting modes that don't exist...
c = self.p.channels['#weirdstuff'] = Channel(self.p, name='#weirdstuff')
out = self.p.reverse_modes('#weirdstuff', '+l-l 30')
self.assertEqual(out, '-l')
out = self.p.reverse_modes('#weirdstuff', '-l+l 30')
self.assertEqual(out, '-l')
out = self.p.reverse_modes('#weirdstuff', '+k-k aaaaaaaaaaaa aaaaaaaaaaaa')
self.assertEqual(out, '-k aaaaaaaaaaaa')
out = self.p.reverse_modes('#weirdstuff', '-k+k aaaaaaaaaaaa aaaaaaaaaaaa')
self.assertEqual(out, '-k aaaaaaaaaaaa')
c.modes = {('l', '555'), ('k', 'NO-PLEASE')}
out = self.p.reverse_modes('#weirdstuff', '+l-l 30')
self.assertEqual(out, '+l 555')
out = self.p.reverse_modes('#weirdstuff', '-l+l 30')
self.assertEqual(out, '+l 555')
out = self.p.reverse_modes('#weirdstuff', '+k-k aaaaaaaaaaaa aaaaaaaaaaaa')
self.assertEqual(out, '+k NO-PLEASE')
out = self.p.reverse_modes('#weirdstuff', '-k+k aaaaaaaaaaaa aaaaaaaaaaaa')
self.assertEqual(out, '+k NO-PLEASE')
# TODO: test type coersion if channel or mode targets are ints # TODO: test type coersion if channel or mode targets are ints