From 2aecb6b3900c82e9f03c511a17531ae9b5d8bc45 Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Sat, 5 Apr 2003 13:35:45 +0000 Subject: [PATCH] Added more tests --- test/irclib_test.py | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/test/irclib_test.py b/test/irclib_test.py index 9a3079124..985321439 100644 --- a/test/irclib_test.py +++ b/test/irclib_test.py @@ -114,8 +114,13 @@ class IrcStateTestCase(unittest.TestCase): self.assertEqual(len(state.history), conf.maxHistory) self.assertEqual(list(state.history), msgs[len(msgs)-conf.maxHistory:]) conf.maxHistory = oldconfmaxhistory - + """ + def testChannels(self): + channel = + state = irclib.IrcState() + state.addMsg(self.irc, ircmsgs.join('#foo')) + """ class IrcTestCase(unittest.TestCase): irc = irclib.Irc('nick') @@ -150,3 +155,37 @@ class IrcTestCase(unittest.TestCase): msg2 = ircmsgs.IrcMsg('JOIN #sourcereview') self.irc.feedMsg(msg2) self.assertEqual(list(self.irc.state.history), [msg1, msg2]) + + +class IrcCallbackTestCase(unittest.TestCase): + class FakeIrc: + pass + irc = FakeIrc() + def testName(self): + class UnnamedIrcCallback(irclib.IrcCallback): + pass + unnamed = UnnamedIrcCallback() + + class NamedIrcCallback(irclib.IrcCallback): + myName = 'foobar' + def name(self): + return self.myName + named = NamedIrcCallback() + self.assertEqual(unnamed.name(), unnamed.__class__.__name__) + self.assertEqual(named.name(), named.myName) + + def testDoCommand(self): + def makeCommand(msg): + return 'do' + msg.command.capitalize() + class DoCommandCatcher(irclib.IrcCallback): + def __init__(self): + self.L = [] + def __getattr__(self, attr): + self.L.append(attr) + return lambda *args: None + doCommandCatcher = DoCommandCatcher() + for msg in msgs: + doCommandCatcher(self.irc, msg) + commands = map(makeCommand, msgs) + self.assertEqual(doCommandCatcher.L, + list(flatten(zip(commands, commands))))