mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-23 02:24:12 +01:00
Added a test for randomnick and fixed the bug it found.
This commit is contained in:
parent
e46e2483b7
commit
5f55e2b589
@ -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)
|
||||
|
@ -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)
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user