mirror of
https://github.com/jlu5/PyLink.git
synced 2025-01-23 18:54:05 +01:00
Remove awfully maintained test cases
This commit is contained in:
parent
0b9691c3c6
commit
58e3c6626c
26
runtests
26
runtests
@ -1,26 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
|
|
||||||
import unittest
|
|
||||||
import glob
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
|
|
||||||
runner = unittest.TextTestRunner(verbosity=2)
|
|
||||||
fails = []
|
|
||||||
suites = []
|
|
||||||
|
|
||||||
# Yay, import hacks!
|
|
||||||
sys.path.append(os.path.join(os.getcwd(), 'tests'))
|
|
||||||
|
|
||||||
query = sys.argv[1:] or glob.glob('tests/test_*.py')
|
|
||||||
|
|
||||||
for testfile in query:
|
|
||||||
# Strip the tests/ and .py extension: tests/test_whatever.py => test_whatever
|
|
||||||
module = testfile.replace('.py', '').replace('tests/', '')
|
|
||||||
module = __import__(module)
|
|
||||||
suites.append(unittest.defaultTestLoader.loadTestsFromModule(module))
|
|
||||||
|
|
||||||
testsuite = unittest.TestSuite(suites)
|
|
||||||
runner.run(testsuite)
|
|
@ -1,36 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
|
|
||||||
import unittest
|
|
||||||
|
|
||||||
import world
|
|
||||||
import coreplugin
|
|
||||||
import utils
|
|
||||||
import tests_common
|
|
||||||
|
|
||||||
inspircd = utils.getProtocolModule('inspircd')
|
|
||||||
world.testing = True
|
|
||||||
|
|
||||||
class CorePluginTestCase(tests_common.PluginTestCase):
|
|
||||||
@unittest.skip("Test doesn't work yet.")
|
|
||||||
def testKillRespawn(self):
|
|
||||||
self.irc.run(':9PY KILL {u} :test'.format(u=self.u))
|
|
||||||
hooks = self.irc.takeHooks()
|
|
||||||
|
|
||||||
# Make sure we're respawning our PseudoClient when its killed
|
|
||||||
print(hooks)
|
|
||||||
spmain = [h for h in hooks if h[1] == 'PYLINK_SPAWNMAIN']
|
|
||||||
self.assertTrue(spmain, 'PYLINK_SPAWNMAIN hook was never sent!')
|
|
||||||
|
|
||||||
msgs = self.irc.takeMsgs()
|
|
||||||
commands = self.irc.takeCommands(msgs)
|
|
||||||
self.assertIn('UID', commands)
|
|
||||||
self.assertIn('FJOIN', commands)
|
|
||||||
|
|
||||||
# Also make sure that we're updating the irc.pseudoclient field
|
|
||||||
self.assertNotEqual(self.irc.pseudoclient.uid, spmain[0]['olduser'])
|
|
||||||
|
|
||||||
def testKickRejoin(self):
|
|
||||||
self.proto.kick(self.u, '#pylink', self.u, 'test')
|
|
||||||
msgs = self.irc.takeMsgs()
|
|
||||||
commands = self.irc.takeCommands(msgs)
|
|
||||||
self.assertIn('FJOIN', commands)
|
|
@ -1,30 +0,0 @@
|
|||||||
import sys
|
|
||||||
import os
|
|
||||||
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
||||||
|
|
||||||
import classes
|
|
||||||
import unittest
|
|
||||||
import conf
|
|
||||||
|
|
||||||
class TestFakeIRC(unittest.TestCase):
|
|
||||||
def setUp(self):
|
|
||||||
self.irc = classes.FakeIRC('unittest', classes.FakeProto, conf.testconf)
|
|
||||||
|
|
||||||
def testFakeIRC(self):
|
|
||||||
self.irc.run('this should do nothing')
|
|
||||||
self.irc.send('ADD this message')
|
|
||||||
self.irc.send(':add THIS message too')
|
|
||||||
msgs = self.irc.takeMsgs()
|
|
||||||
self.assertEqual(['ADD this message', ':add THIS message too'],
|
|
||||||
msgs)
|
|
||||||
# takeMsgs() clears cached messages queue, so the next call should
|
|
||||||
# return an empty list.
|
|
||||||
msgs = self.irc.takeMsgs()
|
|
||||||
self.assertEqual([], msgs)
|
|
||||||
|
|
||||||
def testFakeIRCtakeCommands(self):
|
|
||||||
msgs = ['ADD this message', ':9PY THIS message too']
|
|
||||||
self.assertEqual(['ADD', 'THIS'], self.irc.takeCommands(msgs))
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
unittest.main()
|
|
@ -1,46 +0,0 @@
|
|||||||
import sys
|
|
||||||
import os
|
|
||||||
cwd = os.getcwd()
|
|
||||||
sys.path += [cwd, os.path.join(cwd, 'plugins')]
|
|
||||||
import unittest
|
|
||||||
|
|
||||||
import classes
|
|
||||||
import relay
|
|
||||||
import conf
|
|
||||||
|
|
||||||
def dummyf():
|
|
||||||
pass
|
|
||||||
|
|
||||||
class TestRelay(unittest.TestCase):
|
|
||||||
def setUp(self):
|
|
||||||
self.irc = classes.FakeIRC('fakeirc', classes.FakeProto, conf.testconf)
|
|
||||||
self.irc.maxnicklen = 20
|
|
||||||
self.f = lambda nick: relay.normalizeNick(self.irc, 'unittest', nick)
|
|
||||||
# Fake our protocol name to something that supports slashes in nicks.
|
|
||||||
# relay uses a whitelist for this to prevent accidentally introducing
|
|
||||||
# bad nicks:
|
|
||||||
self.irc.protoname = "inspircd"
|
|
||||||
|
|
||||||
def testNormalizeNick(self):
|
|
||||||
# Second argument simply states the suffix.
|
|
||||||
self.assertEqual(self.f('helloworld'), 'helloworld/unittest')
|
|
||||||
self.assertEqual(self.f('ObnoxiouslyLongNick'), 'Obnoxiously/unittest')
|
|
||||||
self.assertEqual(self.f('10XAAAAAA'), '_10XAAAAAA/unittest')
|
|
||||||
|
|
||||||
def testNormalizeNickConflict(self):
|
|
||||||
self.assertEqual(self.f('helloworld'), 'helloworld/unittest')
|
|
||||||
self.irc.users['10XAAAAAA'] = classes.IrcUser('helloworld/unittest', 1234, '10XAAAAAA')
|
|
||||||
# Increase amount of /'s by one
|
|
||||||
self.assertEqual(self.f('helloworld'), 'helloworld//unittest')
|
|
||||||
self.irc.users['10XAAAAAB'] = classes.IrcUser('helloworld//unittest', 1234, '10XAAAAAB')
|
|
||||||
# Cut off the nick, not the suffix if the result is too long.
|
|
||||||
self.assertEqual(self.f('helloworld'), 'helloworl///unittest')
|
|
||||||
|
|
||||||
def testNormalizeNickRemovesSlashes(self):
|
|
||||||
self.irc.protoname = "charybdis"
|
|
||||||
try:
|
|
||||||
self.assertEqual(self.f('helloworld'), 'helloworld|unittest')
|
|
||||||
self.assertEqual(self.f('abcde/eJanus'), 'abcde|eJanu|unittest')
|
|
||||||
self.assertEqual(self.f('ObnoxiouslyLongNick'), 'Obnoxiously|unittest')
|
|
||||||
finally:
|
|
||||||
self.irc.protoname = "inspircd"
|
|
@ -1,155 +0,0 @@
|
|||||||
import sys
|
|
||||||
import os
|
|
||||||
sys.path.append(os.getcwd())
|
|
||||||
import unittest
|
|
||||||
import itertools
|
|
||||||
from copy import deepcopy
|
|
||||||
|
|
||||||
import utils
|
|
||||||
import classes
|
|
||||||
import conf
|
|
||||||
import world
|
|
||||||
|
|
||||||
def dummyf():
|
|
||||||
pass
|
|
||||||
|
|
||||||
class TestUtils(unittest.TestCase):
|
|
||||||
def setUp(self):
|
|
||||||
self.irc = classes.FakeIRC('fakeirc', classes.FakeProto, conf.testconf)
|
|
||||||
|
|
||||||
def testTS6UIDGenerator(self):
|
|
||||||
uidgen = utils.TS6UIDGenerator('9PY')
|
|
||||||
self.assertEqual(uidgen.next_uid(), '9PYAAAAAA')
|
|
||||||
self.assertEqual(uidgen.next_uid(), '9PYAAAAAB')
|
|
||||||
|
|
||||||
def test_add_cmd(self):
|
|
||||||
# Without name specified, add_cmd adds a command with the same name
|
|
||||||
# as the function
|
|
||||||
utils.add_cmd(dummyf)
|
|
||||||
utils.add_cmd(dummyf, 'TEST')
|
|
||||||
# All command names should be automatically lowercased.
|
|
||||||
self.assertIn('dummyf', world.commands)
|
|
||||||
self.assertIn('test', world.commands)
|
|
||||||
self.assertNotIn('TEST', world.commands)
|
|
||||||
|
|
||||||
def test_add_hook(self):
|
|
||||||
utils.add_hook(dummyf, 'join')
|
|
||||||
self.assertIn('JOIN', world.hooks)
|
|
||||||
# Command names stored in uppercase.
|
|
||||||
self.assertNotIn('join', world.hooks)
|
|
||||||
self.assertIn(dummyf, world.hooks['JOIN'])
|
|
||||||
|
|
||||||
def testIsNick(self):
|
|
||||||
self.assertFalse(utils.isNick('abcdefgh', nicklen=3))
|
|
||||||
self.assertTrue(utils.isNick('aBcdefgh', nicklen=30))
|
|
||||||
self.assertTrue(utils.isNick('abcdefgh1'))
|
|
||||||
self.assertTrue(utils.isNick('ABC-def'))
|
|
||||||
self.assertFalse(utils.isNick('-_-'))
|
|
||||||
self.assertFalse(utils.isNick(''))
|
|
||||||
self.assertFalse(utils.isNick(' i lost the game'))
|
|
||||||
self.assertFalse(utils.isNick(':aw4t*9e4t84a3t90$&*6'))
|
|
||||||
self.assertFalse(utils.isNick('9PYAAAAAB'))
|
|
||||||
self.assertTrue(utils.isNick('_9PYAAAAAB\\'))
|
|
||||||
|
|
||||||
def testIsChannel(self):
|
|
||||||
self.assertFalse(utils.isChannel(''))
|
|
||||||
self.assertFalse(utils.isChannel('lol'))
|
|
||||||
self.assertTrue(utils.isChannel('#channel'))
|
|
||||||
self.assertTrue(utils.isChannel('##ABCD'))
|
|
||||||
|
|
||||||
def testIsServerName(self):
|
|
||||||
self.assertFalse(utils.isServerName('Invalid'))
|
|
||||||
self.assertTrue(utils.isServerName('services.'))
|
|
||||||
self.assertFalse(utils.isServerName('.s.s.s'))
|
|
||||||
self.assertTrue(utils.isServerName('Hello.world'))
|
|
||||||
self.assertFalse(utils.isServerName(''))
|
|
||||||
self.assertTrue(utils.isServerName('pylink.somenet.local'))
|
|
||||||
self.assertFalse(utils.isServerName(' i lost th.e game'))
|
|
||||||
|
|
||||||
def testJoinModes(self):
|
|
||||||
res = utils.joinModes({('+l', '50'), ('+n', None), ('+t', None)})
|
|
||||||
# Sets are orderless, so the end mode could be scrambled in a number of ways.
|
|
||||||
# Basically, we're looking for a string that looks like '+ntl 50' or '+lnt 50'.
|
|
||||||
possible = ['+%s 50' % ''.join(x) for x in itertools.permutations('lnt', 3)]
|
|
||||||
self.assertIn(res, possible)
|
|
||||||
|
|
||||||
# Without any arguments, make sure there is no trailing space.
|
|
||||||
self.assertEqual(utils.joinModes({('+t', None)}), '+t')
|
|
||||||
|
|
||||||
# The +/- in the mode is not required; if it doesn't exist, assume we're
|
|
||||||
# adding modes always.
|
|
||||||
self.assertEqual(utils.joinModes([('t', None), ('n', None)]), '+tn')
|
|
||||||
|
|
||||||
# An empty query should return just '+'
|
|
||||||
self.assertEqual(utils.joinModes(set()), '+')
|
|
||||||
|
|
||||||
# More complex query now with both + and - modes being set
|
|
||||||
res = utils.joinModes([('+l', '50'), ('-n', None)])
|
|
||||||
self.assertEqual(res, '+l-n 50')
|
|
||||||
|
|
||||||
# If one modepair in the list lacks a +/- prefix, just follow the
|
|
||||||
# previous one's.
|
|
||||||
res = utils.joinModes([('+l', '50'), ('-n', None), ('m', None)])
|
|
||||||
self.assertEqual(res, '+l-nm 50')
|
|
||||||
res = utils.joinModes([('+l', '50'), ('m', None)])
|
|
||||||
self.assertEqual(res, '+lm 50')
|
|
||||||
res = utils.joinModes([('l', '50'), ('-m', None)])
|
|
||||||
self.assertEqual(res, '+l-m 50')
|
|
||||||
|
|
||||||
# Rarely in real life will we get a mode string this complex.
|
|
||||||
# Let's make sure it works, just in case.
|
|
||||||
res = utils.joinModes([('-o', '9PYAAAAAA'), ('+l', '50'), ('-n', None),
|
|
||||||
('-m', None), ('+k', 'hello'),
|
|
||||||
('+b', '*!*@*.badisp.net')])
|
|
||||||
self.assertEqual(res, '-o+l-nm+kb 9PYAAAAAA 50 hello *!*@*.badisp.net')
|
|
||||||
|
|
||||||
def _reverseModes(self, query, expected, target='#PyLink', oldobj=None):
|
|
||||||
res = utils.reverseModes(self.irc, target, query, oldobj=oldobj)
|
|
||||||
self.assertEqual(res, expected)
|
|
||||||
|
|
||||||
def testReverseModes(self):
|
|
||||||
# Initialize the channe, first.
|
|
||||||
utils.applyModes(self.irc, '#PyLink', [])
|
|
||||||
# Strings.
|
|
||||||
self._reverseModes("+mk-t test", "-mk+t test")
|
|
||||||
self._reverseModes("ml-n 111", "-ml+n")
|
|
||||||
# Lists.
|
|
||||||
self._reverseModes([('+m', None), ('+r', None), ('+l', '3')],
|
|
||||||
{('-m', None), ('-r', None), ('-l', None)})
|
|
||||||
# Sets.
|
|
||||||
self._reverseModes({('s', None)}, {('-s', None)})
|
|
||||||
# Combining modes with an initial + and those without
|
|
||||||
self._reverseModes({('s', None), ('+R', None)}, {('-s', None), ('-R', None)})
|
|
||||||
|
|
||||||
def testReverseModesUser(self):
|
|
||||||
self._reverseModes({('+i', None), ('l', 'asfasd')}, {('-i', None), ('-l', 'asfasd')},
|
|
||||||
target=self.irc.pseudoclient.uid)
|
|
||||||
|
|
||||||
def testReverseModesExisting(self):
|
|
||||||
utils.applyModes(self.irc, '#PyLink', [('+m', None), ('+l', '50'), ('+k', 'supersecret'),
|
|
||||||
('+o', '9PYAAAAAA')])
|
|
||||||
|
|
||||||
self._reverseModes({('+i', None), ('+l', '3')}, {('-i', None), ('+l', '50')})
|
|
||||||
self._reverseModes('-n', '+n')
|
|
||||||
self._reverseModes('-l', '+l 50')
|
|
||||||
self._reverseModes('+k derp', '+k supersecret')
|
|
||||||
self._reverseModes('-mk *', '+mk supersecret')
|
|
||||||
|
|
||||||
self.irc.proto.spawnClient("tester2")
|
|
||||||
oldobj = deepcopy(self.irc.channels['#PyLink'])
|
|
||||||
|
|
||||||
# Existing modes are ignored.
|
|
||||||
self._reverseModes([('+t', None)], set())
|
|
||||||
self._reverseModes('+n', '+')
|
|
||||||
#self._reverseModes('+oo 9PYAAAAAB 9PYAAAAAA', '-o 9PYAAAAAB', oldobj=oldobj)
|
|
||||||
self._reverseModes('+o 9PYAAAAAA', '+')
|
|
||||||
self._reverseModes('+vM 9PYAAAAAA', '-M')
|
|
||||||
|
|
||||||
# Ignore unsetting prefixmodes/list modes that were never set.
|
|
||||||
self._reverseModes([('-v', '10XAAAAAA')], set())
|
|
||||||
self._reverseModes('-ob 10XAAAAAA derp!*@*', '+')
|
|
||||||
utils.applyModes(self.irc, '#PyLink', [('+b', '*!user@badisp.tk')])
|
|
||||||
self._reverseModes('-bb *!*@* *!user@badisp.tk', '+b *!user@badisp.tk')
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
unittest.main()
|
|
@ -1,101 +0,0 @@
|
|||||||
import sys
|
|
||||||
import os
|
|
||||||
sys.path += [os.getcwd(), os.path.join(os.getcwd(), 'protocols')]
|
|
||||||
import unittest
|
|
||||||
|
|
||||||
import world
|
|
||||||
import utils
|
|
||||||
import classes
|
|
||||||
import conf
|
|
||||||
|
|
||||||
world.started.set()
|
|
||||||
|
|
||||||
class PluginTestCase(unittest.TestCase):
|
|
||||||
def setUp(self):
|
|
||||||
proto = utils.getProtocolModule(world.testing_ircd)
|
|
||||||
self.irc = classes.FakeIRC('unittest', proto, conf.testconf)
|
|
||||||
self.proto = self.irc.proto
|
|
||||||
self.irc.connect()
|
|
||||||
self.sdata = self.irc.serverdata
|
|
||||||
self.u = self.irc.pseudoclient.uid
|
|
||||||
self.maxDiff = None
|
|
||||||
# Dummy servers/users used in tests below.
|
|
||||||
self.proto.spawnServer('whatever.', sid='10X')
|
|
||||||
for x in range(3):
|
|
||||||
self.proto.spawnClient('user%s' % x, server='10X')
|
|
||||||
|
|
||||||
class CommonProtoTestCase(PluginTestCase):
|
|
||||||
def testJoinClient(self):
|
|
||||||
u = self.u
|
|
||||||
self.proto.join(u, '#Channel')
|
|
||||||
self.assertIn(u, self.irc.channels['#channel'].users)
|
|
||||||
# Non-existant user.
|
|
||||||
self.assertRaises(LookupError, self.proto.join, '9PYZZZZZZ', '#test')
|
|
||||||
|
|
||||||
def testKickClient(self):
|
|
||||||
target = self.proto.spawnClient('soccerball', 'soccerball', 'abcd').uid
|
|
||||||
self.proto.join(target, '#pylink')
|
|
||||||
self.assertIn(self.u, self.irc.channels['#pylink'].users)
|
|
||||||
self.assertIn(target, self.irc.channels['#pylink'].users)
|
|
||||||
self.proto.kick(self.u, '#pylink', target, 'Pow!')
|
|
||||||
self.assertNotIn(target, self.irc.channels['#pylink'].users)
|
|
||||||
|
|
||||||
def testModeClient(self):
|
|
||||||
testuser = self.proto.spawnClient('testcakes')
|
|
||||||
self.irc.takeMsgs()
|
|
||||||
self.proto.mode(self.u, testuser.uid, [('+i', None), ('+w', None)])
|
|
||||||
self.assertEqual({('i', None), ('w', None)}, testuser.modes)
|
|
||||||
|
|
||||||
# Default channels start with +nt
|
|
||||||
self.assertEqual({('n', None), ('t', None)}, self.irc.channels['#pylink'].modes)
|
|
||||||
self.proto.mode(self.u, '#pylink', [('+s', None), ('+l', '30')])
|
|
||||||
self.assertEqual({('s', None), ('l', '30'), ('n', None), ('t', None)}, self.irc.channels['#pylink'].modes)
|
|
||||||
|
|
||||||
cmds = self.irc.takeCommands(self.irc.takeMsgs())
|
|
||||||
self.assertEqual(cmds, ['MODE', 'FMODE'])
|
|
||||||
|
|
||||||
def testNickClient(self):
|
|
||||||
self.proto.nick(self.u, 'NotPyLink')
|
|
||||||
self.assertEqual('NotPyLink', self.irc.users[self.u].nick)
|
|
||||||
|
|
||||||
def testPartClient(self):
|
|
||||||
u = self.u
|
|
||||||
self.proto.join(u, '#channel')
|
|
||||||
self.proto.part(u, '#channel')
|
|
||||||
self.assertNotIn(u, self.irc.channels['#channel'].users)
|
|
||||||
|
|
||||||
def testQuitClient(self):
|
|
||||||
u = self.proto.spawnClient('testuser3', 'moo', 'hello.world').uid
|
|
||||||
self.proto.join(u, '#channel')
|
|
||||||
self.assertRaises(LookupError, self.proto.quit, '9PYZZZZZZ', 'quit reason')
|
|
||||||
self.proto.quit(u, 'quit reason')
|
|
||||||
self.assertNotIn(u, self.irc.channels['#channel'].users)
|
|
||||||
self.assertNotIn(u, self.irc.users)
|
|
||||||
self.assertNotIn(u, self.irc.servers[self.irc.sid].users)
|
|
||||||
|
|
||||||
def testSpawnClient(self):
|
|
||||||
u = self.proto.spawnClient('testuser3', 'moo', 'hello.world').uid
|
|
||||||
# Check the server index and the user index
|
|
||||||
self.assertIn(u, self.irc.servers[self.irc.sid].users)
|
|
||||||
self.assertIn(u, self.irc.users)
|
|
||||||
# Raise ValueError when trying to spawn a client on a server that's not ours
|
|
||||||
self.assertRaises(ValueError, self.proto.spawnClient, 'abcd', 'user', 'dummy.user.net', server='44A')
|
|
||||||
# Unfilled args should get placeholder fields and not error.
|
|
||||||
self.proto.spawnClient('testuser4')
|
|
||||||
|
|
||||||
def testSpawnClientOnServer(self):
|
|
||||||
self.proto.spawnServer('subserver.pylink', '34Q')
|
|
||||||
u = self.proto.spawnClient('person1', 'person', 'users.somenet.local', server='34Q')
|
|
||||||
# We're spawning clients on the right server, hopefully...
|
|
||||||
self.assertIn(u.uid, self.irc.servers['34Q'].users)
|
|
||||||
self.assertNotIn(u.uid, self.irc.servers[self.irc.sid].users)
|
|
||||||
|
|
||||||
def testSpawnServer(self):
|
|
||||||
# Incorrect SID length
|
|
||||||
self.assertRaises(Exception, self.proto.spawnServer, 'subserver.pylink', '34Q0')
|
|
||||||
self.proto.spawnServer('subserver.pylink', '34Q')
|
|
||||||
# Duplicate server name
|
|
||||||
self.assertRaises(Exception, self.proto.spawnServer, 'Subserver.PyLink', '34Z')
|
|
||||||
# Duplicate SID
|
|
||||||
self.assertRaises(Exception, self.proto.spawnServer, 'another.Subserver.PyLink', '34Q')
|
|
||||||
self.assertIn('34Q', self.irc.servers)
|
|
Loading…
Reference in New Issue
Block a user