mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-23 18:44:04 +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:
|
else:
|
||||||
channel = None
|
channel = None
|
||||||
if channel:
|
if channel:
|
||||||
text = _randomnickRe.sub('anyone', text)
|
|
||||||
else:
|
|
||||||
user = random.choice(list(irc.state.channels[channel].users))
|
user = random.choice(list(irc.state.channels[channel].users))
|
||||||
text = _randomnickRe.sub(user, text)
|
text = _randomnickRe.sub(user, text)
|
||||||
|
else:
|
||||||
|
text = _randomnickRe.sub('anyone', text)
|
||||||
t = pow(2,30)*random.random()+time.time()/4.0
|
t = pow(2,30)*random.random()+time.time()/4.0
|
||||||
text = _randomdateRe.sub(time.ctime(t), text)
|
text = _randomdateRe.sub(time.ctime(t), text)
|
||||||
text = _randomintRe.sub(str(random.randint(-1000, 1000)), text)
|
text = _randomintRe.sub(str(random.randint(-1000, 1000)), text)
|
||||||
|
@ -90,12 +90,14 @@ class ToggleDictionaryTestCase(unittest.TestCase):
|
|||||||
'(bar: Off; foo: Off)')
|
'(bar: Off; foo: Off)')
|
||||||
|
|
||||||
|
|
||||||
|
class holder:
|
||||||
|
users = sets.Set(['foo', 'bar', 'baz'])
|
||||||
|
|
||||||
class FunctionsTestCase(unittest.TestCase):
|
class FunctionsTestCase(unittest.TestCase):
|
||||||
class irc:
|
class irc:
|
||||||
class state:
|
class state:
|
||||||
users = sets.Set(['foo', 'bar', 'baz'])
|
channels = {'#foo': holder()}
|
||||||
nick = 'foobar'
|
nick = 'foobar'
|
||||||
pass
|
|
||||||
def testStandardSubstitute(self):
|
def testStandardSubstitute(self):
|
||||||
msg = ircmsgs.privmsg('#foo', 'filler', prefix='biff!quux@xyzzy')
|
msg = ircmsgs.privmsg('#foo', 'filler', prefix='biff!quux@xyzzy')
|
||||||
s = plugins.standardSubstitute(self.irc, msg, '$randomint')
|
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, '$randomdate'))
|
||||||
self.assert_(plugins.standardSubstitute(self.irc, msg, '$today'))
|
self.assert_(plugins.standardSubstitute(self.irc, msg, '$today'))
|
||||||
self.assert_(plugins.standardSubstitute(self.irc, msg, '$now'))
|
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