3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-01 01:09:22 +01:00

classes: fixes for the test API

- fakeirc: drop dummyhook, call hooks in run() - the protocol module doesn't do this for us anymore
- Irc: don't thread if we're in test mode (temp. hack for now)
This commit is contained in:
James Lu 2015-08-29 10:09:56 -07:00
parent 973aba6de7
commit adb9ef13a6

View File

@ -70,8 +70,12 @@ class Irc():
self.initVars() self.initVars()
self.connection_thread = threading.Thread(target = self.connect) if world.testing:
self.connection_thread.start() # HACK: Don't thread if we're running tests.
self.connect()
else:
self.connection_thread = threading.Thread(target = self.connect)
self.connection_thread.start()
self.pingTimer = None self.pingTimer = None
def connect(self): def connect(self):
@ -327,7 +331,10 @@ class FakeIRC(Irc):
def run(self, data): def run(self, data):
"""Queues a message to the fake IRC server.""" """Queues a message to the fake IRC server."""
log.debug('<- ' + data) log.debug('<- ' + data)
self.proto.handle_events(self, data) hook_args = self.proto.handle_events(self, data)
if hook_args is not None:
self.hookmsgs.append(hook_args)
self.callHooks(hook_args)
def send(self, data): def send(self, data):
self.messages.append(data) self.messages.append(data)
@ -359,11 +366,6 @@ class FakeIRC(Irc):
self.hookmsgs = [] self.hookmsgs = []
return hookmsgs return hookmsgs
@staticmethod
def dummyhook(irc, source, command, parsed_args):
"""Dummy function to bind to hooks. This is what allows takeHooks() to work."""
irc.hookmsgs.append(parsed_args)
class FakeProto(): class FakeProto():
"""Dummy protocol module for testing purposes.""" """Dummy protocol module for testing purposes."""
def __init__(self): def __init__(self):