3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-12-25 04:02:45 +01:00

Unbrick the tests

This commit is contained in:
James Lu 2015-12-26 14:30:14 -08:00
parent 3c51231ce8
commit 9811df3dfc
3 changed files with 17 additions and 10 deletions

View File

@ -6,13 +6,14 @@ import unittest
import classes import classes
import relay import relay
import conf
def dummyf(): def dummyf():
pass pass
class TestRelay(unittest.TestCase): class TestRelay(unittest.TestCase):
def setUp(self): def setUp(self):
self.irc = classes.FakeIRC('fakeirc', classes.FakeProto) self.irc = classes.FakeIRC('fakeirc', classes.FakeProto, conf.testconf)
self.irc.maxnicklen = 20 self.irc.maxnicklen = 20
self.f = lambda nick: relay.normalizeNick(self.irc, 'unittest', nick) self.f = lambda nick: relay.normalizeNick(self.irc, 'unittest', nick)
# Fake our protocol name to something that supports slashes in nicks. # Fake our protocol name to something that supports slashes in nicks.

View File

@ -3,6 +3,7 @@ import os
sys.path.append(os.getcwd()) sys.path.append(os.getcwd())
import unittest import unittest
import itertools import itertools
from copy import deepcopy
import utils import utils
import classes import classes
@ -102,12 +103,13 @@ class TestUtils(unittest.TestCase):
('+b', '*!*@*.badisp.net')]) ('+b', '*!*@*.badisp.net')])
self.assertEqual(res, '-o+l-nm+kb 9PYAAAAAA 50 hello *!*@*.badisp.net') self.assertEqual(res, '-o+l-nm+kb 9PYAAAAAA 50 hello *!*@*.badisp.net')
def _reverseModes(self, query, expected, target='#test'): def _reverseModes(self, query, expected, target='#PyLink', oldobj=None):
res = utils.reverseModes(self.irc, target, query) res = utils.reverseModes(self.irc, target, query, oldobj=oldobj)
self.assertEqual(res, expected) self.assertEqual(res, expected)
def testReverseModes(self): def testReverseModes(self):
test = lambda x, y: self.assertEqual(utils.reverseModes(self.irc, '#test', x), y) # Initialize the channe, first.
utils.applyModes(self.irc, '#PyLink', [])
# Strings. # Strings.
self._reverseModes("+mk-t test", "-mk+t test") self._reverseModes("+mk-t test", "-mk+t test")
self._reverseModes("ml-n 111", "-ml+n") self._reverseModes("ml-n 111", "-ml+n")
@ -124,7 +126,7 @@ class TestUtils(unittest.TestCase):
target=self.irc.pseudoclient.uid) target=self.irc.pseudoclient.uid)
def testReverseModesExisting(self): def testReverseModesExisting(self):
utils.applyModes(self.irc, '#test', [('+m', None), ('+l', '50'), ('+k', 'supersecret'), utils.applyModes(self.irc, '#PyLink', [('+m', None), ('+l', '50'), ('+k', 'supersecret'),
('+o', '9PYAAAAAA')]) ('+o', '9PYAAAAAA')])
self._reverseModes({('+i', None), ('+l', '3')}, {('-i', None), ('+l', '50')}) self._reverseModes({('+i', None), ('+l', '3')}, {('-i', None), ('+l', '50')})
@ -133,18 +135,20 @@ class TestUtils(unittest.TestCase):
self._reverseModes('+k derp', '+k supersecret') self._reverseModes('+k derp', '+k supersecret')
self._reverseModes('-mk *', '+mk supersecret') self._reverseModes('-mk *', '+mk supersecret')
self.irc.proto.spawnClient("tester2")
oldobj = deepcopy(self.irc.channels['#PyLink'])
# Existing modes are ignored. # Existing modes are ignored.
self._reverseModes([('+t', None)], set()) self._reverseModes([('+t', None)], set())
self._reverseModes('+n', '+') self._reverseModes('+n', '+')
self._reverseModes('+oo GLolol 9PYAAAAAA', '-o GLolol') #self._reverseModes('+oo 9PYAAAAAB 9PYAAAAAA', '-o 9PYAAAAAB', oldobj=oldobj)
self._reverseModes('+o 9PYAAAAAA', '+') self._reverseModes('+o 9PYAAAAAA', '+')
self._reverseModes('+vvvvM test abcde atat abcd', '-vvvvM test abcde atat abcd') self._reverseModes('+vM 9PYAAAAAA', '-M')
# Ignore unsetting prefixmodes/list modes that were never set. # Ignore unsetting prefixmodes/list modes that were never set.
self._reverseModes([('-v', '10XAAAAAA')], set()) self._reverseModes([('-v', '10XAAAAAA')], set())
self._reverseModes('-ob 10XAAAAAA derp!*@*', '+') self._reverseModes('-ob 10XAAAAAA derp!*@*', '+')
utils.applyModes(self.irc, '#test', [('+o', 'GLolol'), ('+b', '*!user@badisp.tk')]) utils.applyModes(self.irc, '#PyLink', [('+b', '*!user@badisp.tk')])
self._reverseModes('-voo GLolol GLolol 10XAAAAAA', '+o GLolol')
self._reverseModes('-bb *!*@* *!user@badisp.tk', '+b *!user@badisp.tk') self._reverseModes('-bb *!*@* *!user@badisp.tk', '+b *!user@badisp.tk')
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -4,6 +4,7 @@ sys.path += [os.getcwd(), os.path.join(os.getcwd(), 'protocols')]
import unittest import unittest
import world import world
import utils
import classes import classes
import conf import conf
@ -11,7 +12,8 @@ world.started.set()
class PluginTestCase(unittest.TestCase): class PluginTestCase(unittest.TestCase):
def setUp(self): def setUp(self):
self.irc = classes.FakeIRC('unittest', world.testing_ircd, conf.testconf) proto = utils.getProtocolModule(world.testing_ircd)
self.irc = classes.FakeIRC('unittest', proto, conf.testconf)
self.proto = self.irc.proto self.proto = self.irc.proto
self.irc.connect() self.irc.connect()
self.sdata = self.irc.serverdata self.sdata = self.irc.serverdata