Added PluginTestCase.{getMsg,assertNoResponse} and a timeout option to some commands.

This commit is contained in:
Jeremy Fincher 2003-08-25 05:12:43 +00:00
parent 7851f3a502
commit 6cc3103656

View File

@ -115,14 +115,19 @@ class PluginTestCase(unittest.TestCase):
self.irc.die() self.irc.die()
gc.collect() gc.collect()
def _feedMsg(self, query): def _feedMsg(self, query, timeout=None):
if timeout is None:
timeout = self.timeout
self.irc.feedMsg(ircmsgs.privmsg(self.nick, query, prefix=self.prefix)) self.irc.feedMsg(ircmsgs.privmsg(self.nick, query, prefix=self.prefix))
fed = time.time() fed = time.time()
response = self.irc.takeMsg() response = self.irc.takeMsg()
while response is None and time.time() - fed < self.timeout: while response is None and time.time() - fed < timeout:
response = self.irc.takeMsg() response = self.irc.takeMsg()
return response return response
def getMsg(self, query, timeout=None):
return self._feedMsg(query)
def feedMsg(self, query): def feedMsg(self, query):
"""Just feeds it a message, that's all.""" """Just feeds it a message, that's all."""
self.irc.feedMsg(ircmsgs.privmsg(self.nick, query, prefix=self.prefix)) self.irc.feedMsg(ircmsgs.privmsg(self.nick, query, prefix=self.prefix))
@ -143,6 +148,10 @@ class PluginTestCase(unittest.TestCase):
self.failIf(m.args[1].startswith('Error:'), self.failIf(m.args[1].startswith('Error:'),
'%r errored: %s' % (query, m.args[1])) '%r errored: %s' % (query, m.args[1]))
def assertNoResponse(self, query, timeout=None):
m = self._feedMsg(query, timeout)
self.failIf(m)
def assertResponse(self, query, expectedResponse): def assertResponse(self, query, expectedResponse):
m = self._feedMsg(query) m = self._feedMsg(query)
self.failUnless(m) self.failUnless(m)