Added assertError, assertRegexp, and assertRegexps to PluginTestCase

This commit is contained in:
Jeremy Fincher 2003-08-15 06:24:44 +00:00
parent a5baf0eb41
commit bbf0f711bf

View File

@ -107,7 +107,15 @@ class PluginTestCase(unittest.TestCase):
self.failUnless(response) self.failUnless(response)
return response return response
def assertNoError(self, query): # These assertError/assertNoError are somewhat fragile. The proper way to
# do them would be to use a proxy for the irc object and intercept .error.
# But that would be hard, so I don't bother. When this breaks, it'll get
# fixed, but not until then.
def assertError(self, query):
msg = self._feedMsg(query)
self.failUnless(msg.args[1].startswith('Error:'))
def assertNotError(self, query):
msg = self._feedMsg(query) msg = self._feedMsg(query)
self.failIf(msg.args[1].startswith('Error:')) self.failIf(msg.args[1].startswith('Error:'))
@ -115,9 +123,23 @@ class PluginTestCase(unittest.TestCase):
msg = self._feedMsg(query) msg = self._feedMsg(query)
self.assertEqual(msg.args[1], expectedResponse) self.assertEqual(msg.args[1], expectedResponse)
def assertRegexp(self, query, regexp):
msg = self._feedMsg(query)
self.failUnless(re.search(regexp, msg.args[1]))
def assertRegexps(self, query, regexps):
started = time.time()
total = len(expectedResponses)*self.timeout
while expectedResponses and time.time() - started < total:
msg = self._feedMsg(query)
self.failUnless(re.search(expectedResponses.pop(0), msg.args[1]))
self.failIf(time.time() - started > total)
def assertResponses(self, query, expectedResponses): def assertResponses(self, query, expectedResponses):
responses = [] responses = []
while len(responses) < len(expectedResponses): started = time.time()
while len(responses) < len(expectedResponses) and \
time.time() - started > len(expectedResponses)*self.timeout:
msg = self._feedMsg(query) msg = self._feedMsg(query)
self.failUnless(msg) self.failUnless(msg)
responses.append(msg) responses.append(msg)