mirror of
https://github.com/jlu5/PyLink.git
synced 2024-11-27 13:09:23 +01:00
reverse_modes: deduplicate reversing modes with arguments
This commit is contained in:
parent
d93c071446
commit
a1f3af9099
@ -1223,6 +1223,10 @@ class PyLinkNetworkCoreWithUtils(PyLinkNetworkCore):
|
||||
log.debug("(%s) reverse_modes: skipping reversing '%s %s' with %s since it "
|
||||
"wasn't previously set.", self.name, char, arg, mpair)
|
||||
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)
|
||||
|
||||
log.debug('(%s) reverse_modes: new modes: %s', self.name, newmodes)
|
||||
|
@ -761,4 +761,29 @@ class BaseProtocolTest(unittest.TestCase):
|
||||
out = self.p.reverse_modes('#weirdstuff', '-b+b *!*@* *!*@*') # -+ cycle existing ban
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user