Added a test for randomnick and fixed the bug it found.

This commit is contained in:
Jeremy Fincher 2003-11-02 18:23:04 +00:00
parent e46e2483b7
commit 5f55e2b589
2 changed files with 8 additions and 4 deletions

View File

@ -323,10 +323,10 @@ def standardSubstitute(irc, msg, text):
else:
channel = None
if channel:
text = _randomnickRe.sub('anyone', text)
else:
user = random.choice(list(irc.state.channels[channel].users))
text = _randomnickRe.sub(user, text)
else:
text = _randomnickRe.sub('anyone', text)
t = pow(2,30)*random.random()+time.time()/4.0
text = _randomdateRe.sub(time.ctime(t), text)
text = _randomintRe.sub(str(random.randint(-1000, 1000)), text)

View File

@ -90,12 +90,14 @@ class ToggleDictionaryTestCase(unittest.TestCase):
'(bar: Off; foo: Off)')
class holder:
users = sets.Set(['foo', 'bar', 'baz'])
class FunctionsTestCase(unittest.TestCase):
class irc:
class state:
users = sets.Set(['foo', 'bar', 'baz'])
channels = {'#foo': holder()}
nick = 'foobar'
pass
def testStandardSubstitute(self):
msg = ircmsgs.privmsg('#foo', 'filler', prefix='biff!quux@xyzzy')
s = plugins.standardSubstitute(self.irc, msg, '$randomint')
@ -115,6 +117,8 @@ class FunctionsTestCase(unittest.TestCase):
self.assert_(plugins.standardSubstitute(self.irc, msg, '$randomdate'))
self.assert_(plugins.standardSubstitute(self.irc, msg, '$today'))
self.assert_(plugins.standardSubstitute(self.irc, msg, '$now'))
n = plugins.standardSubstitute(self.irc, msg, '$randomnick')
self.failUnless(n in self.irc.state.channels['#foo'].users)