Replace failUnless/failIf with assertTrue/assertFalse.

The old names are deprecated.
This commit is contained in:
Valentin Lorentz 2020-01-26 11:13:56 +01:00
parent 5efd2afa27
commit 9891b0fca4
31 changed files with 539 additions and 539 deletions

View File

@ -110,7 +110,7 @@ class AliasTestCase(ChannelPluginTestCase):
self.assertResponse('foobar', 'sbbone') self.assertResponse('foobar', 'sbbone')
self.assertRaises(Alias.AliasError, cb.removeAlias, 'foobar') self.assertRaises(Alias.AliasError, cb.removeAlias, 'foobar')
cb.removeAlias('foobar', evenIfLocked=True) cb.removeAlias('foobar', evenIfLocked=True)
self.failIf('foobar' in cb.aliases) self.assertFalse('foobar' in cb.aliases)
self.assertError('foobar') self.assertError('foobar')
self.assertRegexp('alias add abc\x07 ignore', 'Error.*Invalid') self.assertRegexp('alias add abc\x07 ignore', 'Error.*Invalid')
@ -167,14 +167,14 @@ class EscapedAliasTestCase(ChannelPluginTestCase):
def testWriteDatabase(self): def testWriteDatabase(self):
self.assertNotError('alias add fooo.spam echo egg') self.assertNotError('alias add fooo.spam echo egg')
self.assertResponse('fooo.spam', 'egg') self.assertResponse('fooo.spam', 'egg')
self.failUnless(hasattr(conf.supybot.plugins.Alias.escapedaliases, self.assertTrue(hasattr(conf.supybot.plugins.Alias.escapedaliases,
'a1a4dfooospam')) 'a1a4dfooospam'))
self.assertEqual(conf.supybot.plugins.Alias.escapedaliases.a1a4dfooospam(), self.assertEqual(conf.supybot.plugins.Alias.escapedaliases.a1a4dfooospam(),
'echo egg') 'echo egg')
self.assertNotError('alias add foo.spam.egg echo supybot') self.assertNotError('alias add foo.spam.egg echo supybot')
self.assertResponse('foo.spam.egg', 'supybot') self.assertResponse('foo.spam.egg', 'supybot')
self.failUnless(hasattr(conf.supybot.plugins.Alias.escapedaliases, self.assertTrue(hasattr(conf.supybot.plugins.Alias.escapedaliases,
'a2a3d8dfoospamegg')) 'a2a3d8dfoospamegg'))
self.assertEqual(conf.supybot.plugins.Alias.escapedaliases.a2a3d8dfoospamegg(), self.assertEqual(conf.supybot.plugins.Alias.escapedaliases.a2a3d8dfoospamegg(),
'echo supybot') 'echo supybot')

View File

@ -38,7 +38,7 @@ class AnonymousTestCase(ChannelPluginTestCase):
try: try:
conf.supybot.plugins.Anonymous.requireRegistration.setValue(False) conf.supybot.plugins.Anonymous.requireRegistration.setValue(False)
m = self.assertNotError('anonymous say %s foo!' % self.channel) m = self.assertNotError('anonymous say %s foo!' % self.channel)
self.failUnless(m.args[1] == 'foo!') self.assertTrue(m.args[1] == 'foo!')
finally: finally:
conf.supybot.plugins.Anonymous.requireRegistration.setValue(origreg) conf.supybot.plugins.Anonymous.requireRegistration.setValue(origreg)
@ -51,7 +51,7 @@ class AnonymousTestCase(ChannelPluginTestCase):
self.assertError('anonymous tell %s foo!' % self.channel) self.assertError('anonymous tell %s foo!' % self.channel)
conf.supybot.plugins.Anonymous.allowPrivateTarget.setValue(True) conf.supybot.plugins.Anonymous.allowPrivateTarget.setValue(True)
m = self.assertNotError('anonymous tell %s foo!' % self.nick) m = self.assertNotError('anonymous tell %s foo!' % self.nick)
self.failUnless(m.args[1] == 'foo!') self.assertTrue(m.args[1] == 'foo!')
finally: finally:
conf.supybot.plugins.Anonymous.requireRegistration.setValue(origreg) conf.supybot.plugins.Anonymous.requireRegistration.setValue(origreg)
conf.supybot.plugins.Anonymous.allowPrivateTarget.setValue(origpriv) conf.supybot.plugins.Anonymous.allowPrivateTarget.setValue(origpriv)

View File

@ -116,18 +116,18 @@ class ChannelTestCase(ChannelPluginTestCase):
self.irc.feedMsg(ircmsgs.op(self.channel, self.nick)) self.irc.feedMsg(ircmsgs.op(self.channel, self.nick))
self.assertNotError('op') self.assertNotError('op')
m = self.getMsg('op foo') m = self.getMsg('op foo')
self.failUnless(m.command == 'MODE' and self.assertTrue(m.command == 'MODE' and
m.args == (self.channel, '+o', 'foo')) m.args == (self.channel, '+o', 'foo'))
m = self.getMsg('op foo bar') m = self.getMsg('op foo bar')
self.failUnless(m.command == 'MODE' and self.assertTrue(m.command == 'MODE' and
m.args == (self.channel, '+o', 'foo')) m.args == (self.channel, '+o', 'foo'))
m = self.irc.takeMsg() m = self.irc.takeMsg()
self.failUnless(m.command == 'MODE' and self.assertTrue(m.command == 'MODE' and
m.args == (self.channel, '+o', 'bar')) m.args == (self.channel, '+o', 'bar'))
self.irc.state.supported['MODES'] = 2 self.irc.state.supported['MODES'] = 2
m = self.getMsg('op foo bar') m = self.getMsg('op foo bar')
try: try:
self.failUnless(m.command == 'MODE' and self.assertTrue(m.command == 'MODE' and
m.args == (self.channel, '+oo', 'foo', 'bar')) m.args == (self.channel, '+oo', 'foo', 'bar'))
finally: finally:
self.irc.state.supported['MODES'] = 1 self.irc.state.supported['MODES'] = 1
@ -137,13 +137,13 @@ class ChannelTestCase(ChannelPluginTestCase):
self.irc.feedMsg(ircmsgs.op(self.channel, self.nick)) self.irc.feedMsg(ircmsgs.op(self.channel, self.nick))
self.assertNotError('halfop') self.assertNotError('halfop')
m = self.getMsg('halfop foo') m = self.getMsg('halfop foo')
self.failUnless(m.command == 'MODE' and self.assertTrue(m.command == 'MODE' and
m.args == (self.channel, '+h', 'foo')) m.args == (self.channel, '+h', 'foo'))
m = self.getMsg('halfop foo bar') m = self.getMsg('halfop foo bar')
self.failUnless(m.command == 'MODE' and self.assertTrue(m.command == 'MODE' and
m.args == (self.channel, '+h', 'foo')) m.args == (self.channel, '+h', 'foo'))
m = self.irc.takeMsg() m = self.irc.takeMsg()
self.failUnless(m.command == 'MODE' and self.assertTrue(m.command == 'MODE' and
m.args == (self.channel, '+h', 'bar')) m.args == (self.channel, '+h', 'bar'))
def testVoice(self): def testVoice(self):
@ -151,13 +151,13 @@ class ChannelTestCase(ChannelPluginTestCase):
self.irc.feedMsg(ircmsgs.op(self.channel, self.nick)) self.irc.feedMsg(ircmsgs.op(self.channel, self.nick))
self.assertNotError('voice') self.assertNotError('voice')
m = self.getMsg('voice foo') m = self.getMsg('voice foo')
self.failUnless(m.command == 'MODE' and self.assertTrue(m.command == 'MODE' and
m.args == (self.channel, '+v', 'foo')) m.args == (self.channel, '+v', 'foo'))
m = self.getMsg('voice foo bar') m = self.getMsg('voice foo bar')
self.failUnless(m.command == 'MODE' and self.assertTrue(m.command == 'MODE' and
m.args == (self.channel, '+v', 'foo')) m.args == (self.channel, '+v', 'foo'))
m = self.irc.takeMsg() m = self.irc.takeMsg()
self.failUnless(m.command == 'MODE' and self.assertTrue(m.command == 'MODE' and
m.args == (self.channel, '+v', 'bar')) m.args == (self.channel, '+v', 'bar'))
def assertKban(self, query, hostmask, **kwargs): def assertKban(self, query, hostmask, **kwargs):

View File

@ -155,7 +155,7 @@ class FactoidsTestCase(ChannelPluginTestCase):
conf.supybot.plugins.Factoids. \ conf.supybot.plugins.Factoids. \
showFactoidIfOnlyOneMatch.setValue(False) showFactoidIfOnlyOneMatch.setValue(False)
m2 = self.assertNotError('factoids search m/foo/') m2 = self.assertNotError('factoids search m/foo/')
self.failUnless(m1.args[1].startswith(m2.args[1])) self.assertTrue(m1.args[1].startswith(m2.args[1]))
finally: finally:
conf.supybot.plugins.Factoids. \ conf.supybot.plugins.Factoids. \
showFactoidIfOnlyOneMatch.setValue(orig) showFactoidIfOnlyOneMatch.setValue(orig)

View File

@ -156,7 +156,7 @@ class FilterTest(ChannelPluginTestCase):
self.assertNotError('outfilter rot13') self.assertNotError('outfilter rot13')
self.assertResponse('rot13 foobar', '%s: foobar' % s) self.assertResponse('rot13 foobar', '%s: foobar' % s)
m = self.getMsg('action foobar') m = self.getMsg('action foobar')
self.failUnless(ircmsgs.isAction(m)) self.assertTrue(ircmsgs.isAction(m))
s = ircmsgs.unAction(m) s = ircmsgs.unAction(m)
self.assertEqual(s, 'sbbone') self.assertEqual(s, 'sbbone')

View File

@ -38,15 +38,15 @@ class GamesTestCase(ChannelPluginTestCase):
for i in range(100): for i in range(100):
m = self.getMsg('roulette', frm='someoneElse!foo@bar') m = self.getMsg('roulette', frm='someoneElse!foo@bar')
if m.command == 'PRIVMSG': if m.command == 'PRIVMSG':
self.failUnless(self._nonKickRe.search(m.args[1]), self.assertTrue(self._nonKickRe.search(m.args[1]),
'Got a msg without bang|click|spin: %r' % m) 'Got a msg without bang|click|spin: %r' % m)
elif m.command == 'KICK': elif m.command == 'KICK':
sawKick = True sawKick = True
self.failUnless('bang' in m.args[2].lower(), self.assertTrue('bang' in m.args[2].lower(),
'Got a KICK without bang in it.') 'Got a KICK without bang in it.')
else: else:
self.fail('Got something other than a kick or a privmsg.') self.fail('Got something other than a kick or a privmsg.')
self.failUnless(sawKick, 'Didn\'t get a kick in %s iterations!' % i) self.assertTrue(sawKick, 'Didn\'t get a kick in %s iterations!' % i)
def testEightball(self): def testEightball(self):
self.assertNotError('eightball') self.assertNotError('eightball')

View File

@ -43,7 +43,7 @@ class LimiterTestCase(ChannelPluginTestCase):
self.assertEqual(m, ircmsgs.limit('#foo', 1+10)) self.assertEqual(m, ircmsgs.limit('#foo', 1+10))
self.irc.feedMsg(ircmsgs.join('#foo', prefix='bar!root@host')) self.irc.feedMsg(ircmsgs.join('#foo', prefix='bar!root@host'))
m = self.irc.takeMsg() m = self.irc.takeMsg()
self.failIf(m is not None) self.assertFalse(m is not None)
conf.supybot.plugins.Limiter.maximumExcess.setValue(7) conf.supybot.plugins.Limiter.maximumExcess.setValue(7)
self.irc.feedMsg(ircmsgs.part('#foo', prefix='bar!root@host')) self.irc.feedMsg(ircmsgs.part('#foo', prefix='bar!root@host'))
m = self.irc.takeMsg() m = self.irc.takeMsg()

View File

@ -105,23 +105,23 @@ class MessageParserTestCase(ChannelPluginTestCase):
self.assertNotError('messageparser add "stuff" "echo i saw some stuff"') self.assertNotError('messageparser add "stuff" "echo i saw some stuff"')
self.feedMsg('this message has some stuff in it') self.feedMsg('this message has some stuff in it')
m = self.getMsg(' ') m = self.getMsg(' ')
self.failUnless(str(m).startswith('PRIVMSG #test :i saw some stuff')) self.assertTrue(str(m).startswith('PRIVMSG #test :i saw some stuff'))
def testMaxTriggers(self): def testMaxTriggers(self):
self.assertNotError('messageparser add "stuff" "echo i saw some stuff"') self.assertNotError('messageparser add "stuff" "echo i saw some stuff"')
self.assertNotError('messageparser add "sbd" "echo i saw somebody"') self.assertNotError('messageparser add "sbd" "echo i saw somebody"')
self.feedMsg('this message issued by sbd has some stuff in it') self.feedMsg('this message issued by sbd has some stuff in it')
m = self.getMsg(' ') m = self.getMsg(' ')
self.failUnless(str(m).startswith('PRIVMSG #test :i saw some')) self.assertTrue(str(m).startswith('PRIVMSG #test :i saw some'))
m = self.getMsg(' ') m = self.getMsg(' ')
self.failUnless(str(m).startswith('PRIVMSG #test :i saw some')) self.assertTrue(str(m).startswith('PRIVMSG #test :i saw some'))
with conf.supybot.plugins.messageparser.maxtriggers.context(1): with conf.supybot.plugins.messageparser.maxtriggers.context(1):
self.feedMsg('this message issued by sbd has some stuff in it') self.feedMsg('this message issued by sbd has some stuff in it')
m = self.getMsg(' ') m = self.getMsg(' ')
self.failUnless(str(m).startswith('PRIVMSG #test :i saw some')) self.assertTrue(str(m).startswith('PRIVMSG #test :i saw some'))
m = self.getMsg(' ') m = self.getMsg(' ')
self.failIf(m) self.assertFalse(m)
def testLock(self): def testLock(self):
self.assertNotError('messageparser add "stuff" "echo i saw some stuff"') self.assertNotError('messageparser add "stuff" "echo i saw some stuff"')

View File

@ -86,11 +86,11 @@ class MiscTestCase(ChannelPluginTestCase):
def testHelpIncludeFullCommandName(self): def testHelpIncludeFullCommandName(self):
self.assertHelp('help channel capability add') self.assertHelp('help channel capability add')
m = self.getMsg('help channel capability add') m = self.getMsg('help channel capability add')
self.failUnless('channel capability add' in m.args[1]) self.assertTrue('channel capability add' in m.args[1])
def testHelpDoesAmbiguityWithDefaultPlugins(self): def testHelpDoesAmbiguityWithDefaultPlugins(self):
m = self.getMsg('help list') # Misc.list and User.list. m = self.getMsg('help list') # Misc.list and User.list.
self.failIf(m.args[1].startswith('Error')) self.assertFalse(m.args[1].startswith('Error'))
def testHelpIsCaseInsensitive(self): def testHelpIsCaseInsensitive(self):
self.assertHelp('help LIST') self.assertHelp('help LIST')
@ -145,19 +145,19 @@ class MiscTestCase(ChannelPluginTestCase):
oldprefix, self.prefix = self.prefix, 'tester!foo@bar__no_testcap__baz' oldprefix, self.prefix = self.prefix, 'tester!foo@bar__no_testcap__baz'
self.nick = 'tester' self.nick = 'tester'
m = self.getMsg('tell aljsdkfh [plugin tell]') m = self.getMsg('tell aljsdkfh [plugin tell]')
self.failUnless('let you do' in m.args[1]) self.assertTrue('let you do' in m.args[1])
m = self.getMsg('tell #foo [plugin tell]') m = self.getMsg('tell #foo [plugin tell]')
self.failUnless('No need for' in m.args[1]) self.assertTrue('No need for' in m.args[1])
m = self.getMsg('tell me you love me') m = self.getMsg('tell me you love me')
m = self.irc.takeMsg() m = self.irc.takeMsg()
self.failUnless(m.args[0] == self.nick) self.assertTrue(m.args[0] == self.nick)
def testNoNestedTell(self): def testNoNestedTell(self):
self.assertRegexp('echo [tell %s foo]' % self.nick, 'nested') self.assertRegexp('echo [tell %s foo]' % self.nick, 'nested')
def testTellDoesNotPropogateAction(self): def testTellDoesNotPropogateAction(self):
m = self.getMsg('tell foo [action bar]') m = self.getMsg('tell foo [action bar]')
self.failIf(ircmsgs.isAction(m)) self.assertFalse(ircmsgs.isAction(m))
def testLast(self): def testLast(self):
orig = conf.supybot.plugins.Misc.timestampFormat() orig = conf.supybot.plugins.Misc.timestampFormat()

View File

@ -53,11 +53,11 @@ class OptionListTestCase(SupyTestCase):
while max and L: while max and L:
max -= 1 max -= 1
option = plugin.pickOptions(s) option = plugin.pickOptions(s)
self.failUnless(option in original, self.assertTrue(option in original,
'Option %s not in %s' % (option, original)) 'Option %s not in %s' % (option, original))
if option in L: if option in L:
L.remove(option) L.remove(option)
self.failIf(L, 'Some options never seen: %s' % L) self.assertFalse(L, 'Some options never seen: %s' % L)
def testPickOptions(self): def testPickOptions(self):
self._testOptions('(a|b)', ['a', 'b']) self._testOptions('(a|b)', ['a', 'b'])
@ -356,7 +356,7 @@ class FactoidsTestCase(ChannelPluginTestCase):
self.assertResponse('foo', 'foo is bar') self.assertResponse('foo', 'foo is bar')
self.irc.feedMsg(ircmsgs.privmsg(self.irc.nick, '\x01VERSION\x01')) self.irc.feedMsg(ircmsgs.privmsg(self.irc.nick, '\x01VERSION\x01'))
m = self.irc.takeMsg() m = self.irc.takeMsg()
self.failIf(m) self.assertFalse(m)
def testAddFactoidNotCalledWithBadNestingSyntax(self): def testAddFactoidNotCalledWithBadNestingSyntax(self):
self.assertError('re s/Error:.*/foo/ ]') self.assertError('re s/Error:.*/foo/ ]')

View File

@ -371,7 +371,7 @@ class RSSTestCase(ChannelPluginTestCase):
timeFastForward(1.1) timeFastForward(1.1)
self.assertNotError('rss %s' % url) self.assertNotError('rss %s' % url)
m = self.assertNotError('rss %s 2' % url) m = self.assertNotError('rss %s 2' % url)
self.failUnless(m.args[1].count(' | ') == 1) self.assertTrue(m.args[1].count(' | ') == 1)
def testRssAdd(self): def testRssAdd(self):
timeFastForward(1.1) timeFastForward(1.1)

View File

@ -34,7 +34,7 @@ class ReplyTestCase(ChannelPluginTestCase):
plugins = ('Reply',) plugins = ('Reply',)
def testPrivate(self): def testPrivate(self):
m = self.getMsg('private [list]') m = self.getMsg('private [list]')
self.failIf(self.irc.isChannel(m.args[0])) self.assertFalse(self.irc.isChannel(m.args[0]))
def testNotice(self): def testNotice(self):
m = self.getMsg('notice [list]') m = self.getMsg('notice [list]')
@ -62,6 +62,6 @@ class ReplyNonChannelTestCase(PluginTestCase):
self.prefix = 'something!else@somewhere.else' self.prefix = 'something!else@somewhere.else'
self.nick = 'something' self.nick = 'something'
m = self.assertAction('action foo', 'foo') m = self.assertAction('action foo', 'foo')
self.failIf(m.args[0] == self.irc.nick) self.assertFalse(m.args[0] == self.irc.nick)
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:

View File

@ -54,7 +54,7 @@ class SchedulerTestCase(ChannelPluginTestCase):
if s.isdigit(): if s.isdigit():
id = s id = s
break break
self.failUnless(id, 'Couldn\'t find id in reply.') self.assertTrue(id, 'Couldn\'t find id in reply.')
self.assertNotError('scheduler remove %s' % id) self.assertNotError('scheduler remove %s' % id)
timeFastForward(5) timeFastForward(5)
self.assertNoResponse(' ', timeout=1) self.assertNoResponse(' ', timeout=1)

View File

@ -85,7 +85,7 @@ class ChannelDBTestCase(ChannelPluginTestCase):
self.assertError('seen *') self.assertError('seen *')
self.assertNotError('seen %s' % self.nick) self.assertNotError('seen %s' % self.nick)
m = self.assertNotError('seen %s' % self.nick.upper()) m = self.assertNotError('seen %s' % self.nick.upper())
self.failUnless(self.nick.upper() in m.args[1]) self.assertTrue(self.nick.upper() in m.args[1])
self.assertRegexp('seen user %s' % self.nick, self.assertRegexp('seen user %s' % self.nick,
'^%s was last seen' % self.nick) '^%s was last seen' % self.nick)
self.assertNotError('config plugins.Seen.minimumNonWildcard 0') self.assertNotError('config plugins.Seen.minimumNonWildcard 0')

View File

@ -41,12 +41,12 @@ class ServicesTestCase(PluginTestCase):
self.assertError('services identify') # Don't have a password. self.assertError('services identify') # Don't have a password.
self.assertNotError('services password %s baz' % self.nick) self.assertNotError('services password %s baz' % self.nick)
m = self.assertNotError('services identify') m = self.assertNotError('services identify')
self.failUnless(m.args[0] == 'NickServ') self.assertTrue(m.args[0] == 'NickServ')
self.failUnless(m.args[1].lower() == 'identify baz') self.assertTrue(m.args[1].lower() == 'identify baz')
self.assertNotError('services password %s biff' % self.nick) self.assertNotError('services password %s biff' % self.nick)
m = self.assertNotError('services identify') m = self.assertNotError('services identify')
self.failUnless(m.args[0] == 'NickServ') self.assertTrue(m.args[0] == 'NickServ')
self.failUnless(m.args[1].lower() == 'identify biff') self.assertTrue(m.args[1].lower() == 'identify biff')
def testPasswordConfg(self): def testPasswordConfg(self):
self.assertNotError('config plugins.Services.nicks ""') self.assertNotError('config plugins.Services.nicks ""')
@ -72,8 +72,8 @@ class ServicesTestCase(PluginTestCase):
'Global: bar; test: bar2') 'Global: bar; test: bar2')
m = self.assertNotError('services identify') m = self.assertNotError('services identify')
self.failUnless(m.args[0] == 'NickServ') self.assertTrue(m.args[0] == 'NickServ')
self.failUnless(m.args[1].lower() == 'identify bar2') self.assertTrue(m.args[1].lower() == 'identify bar2')
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:

View File

@ -40,11 +40,11 @@ class StatusTestCase(PluginTestCase):
def testCpu(self): def testCpu(self):
m = self.assertNotError('status cpu') m = self.assertNotError('status cpu')
self.failIf('kB kB' in m.args[1]) self.assertFalse('kB kB' in m.args[1])
self.failIf('None' in m.args[1], 'None in cpu output: %r.' % m) self.assertFalse('None' in m.args[1], 'None in cpu output: %r.' % m)
for s in ['linux', 'freebsd', 'openbsd', 'netbsd', 'darwin']: for s in ['linux', 'freebsd', 'openbsd', 'netbsd', 'darwin']:
if sys.platform.startswith(s): if sys.platform.startswith(s):
self.failUnless('B' in m.args[1] or 'KB' in m.args[1] or self.assertTrue('B' in m.args[1] or 'KB' in m.args[1] or
'MB' in m.args[1], 'MB' in m.args[1],
'No memory string on supported platform.') 'No memory string on supported platform.')
try: try:

View File

@ -128,7 +128,7 @@ class TopicTestCase(ChannelPluginTestCase):
conf.supybot.plugins.Topic.separator.setValue(' <==> ') conf.supybot.plugins.Topic.separator.setValue(' <==> ')
_ = self.getMsg('topic add foo') _ = self.getMsg('topic add foo')
m = self.getMsg('topic add bar') m = self.getMsg('topic add bar')
self.failUnless('<==>' in m.args[1]) self.assertTrue('<==>' in m.args[1])
finally: finally:
conf.supybot.plugins.Topic.separator.setValue(original) conf.supybot.plugins.Topic.separator.setValue(original)

View File

@ -103,13 +103,13 @@ class UserTestCase(PluginTestCase):
self.assertResponse('hostmask', self.prefix) self.assertResponse('hostmask', self.prefix)
self.assertError('@hostmask asdf') self.assertError('@hostmask asdf')
m = self.irc.takeMsg() m = self.irc.takeMsg()
self.failIf(m is not None, m) self.assertFalse(m is not None, m)
def testRegisterUnregister(self): def testRegisterUnregister(self):
self.prefix = self.prefix1 self.prefix = self.prefix1
self.assertNotError('register foo bar') self.assertNotError('register foo bar')
self.assertError('register foo baz') self.assertError('register foo baz')
self.failUnless(ircdb.users.getUserId('foo')) self.assertTrue(ircdb.users.getUserId('foo'))
self.assertError('unregister foo') self.assertError('unregister foo')
self.assertNotError('unregister foo bar') self.assertNotError('unregister foo bar')
self.assertRaises(KeyError, ircdb.users.getUserId, 'foo') self.assertRaises(KeyError, ircdb.users.getUserId, 'foo')
@ -122,8 +122,8 @@ class UserTestCase(PluginTestCase):
try: try:
self.assertError('unregister foo') self.assertError('unregister foo')
m = self.irc.takeMsg() m = self.irc.takeMsg()
self.failIf(m is not None, m) self.assertFalse(m is not None, m)
self.failUnless(ircdb.users.getUserId('foo')) self.assertTrue(ircdb.users.getUserId('foo'))
finally: finally:
conf.supybot.databases.users.allowUnregistration.setValue(orig) conf.supybot.databases.users.allowUnregistration.setValue(orig)

View File

@ -41,7 +41,7 @@ class WebTestCase(ChannelPluginTestCase):
self.assertError('doctype ftp://ftp.cdrom.com/pub/linux') self.assertError('doctype ftp://ftp.cdrom.com/pub/linux')
self.assertNotError('doctype http://www.slashdot.org/') self.assertNotError('doctype http://www.slashdot.org/')
m = self.getMsg('doctype http://moobot.sf.net/') m = self.getMsg('doctype http://moobot.sf.net/')
self.failUnless(m.args[1].endswith('>')) self.assertTrue(m.args[1].endswith('>'))
def testSize(self): def testSize(self):
self.assertError('size ftp://ftp.cdrom.com/pub/linux') self.assertError('size ftp://ftp.cdrom.com/pub/linux')

View File

@ -342,7 +342,7 @@ class PluginTestCase(SupyTestCase):
if m is None: if m is None:
raise TimeoutError(query) raise TimeoutError(query)
if lastGetHelp not in m.args[1]: if lastGetHelp not in m.args[1]:
self.failUnless(m.args[1].startswith('Error:'), self.assertTrue(m.args[1].startswith('Error:'),
'%r did not error: %s' % (query, m.args[1])) '%r did not error: %s' % (query, m.args[1]))
return m return m
@ -353,10 +353,10 @@ class PluginTestCase(SupyTestCase):
m = self._feedMsg(query, **kwargs) m = self._feedMsg(query, **kwargs)
if m is None: if m is None:
raise TimeoutError(query) raise TimeoutError(query)
self.failIf(m.args[1].startswith('Error:'), self.assertFalse(m.args[1].startswith('Error:'),
'%r errored: %s' % (query, m.args[1])) '%r errored: %s' % (query, m.args[1]))
self.failIf(lastGetHelp in m.args[1], self.assertFalse(lastGetHelp in m.args[1],
'%r returned the help string.' % query) '%r returned the help string.' % query)
return m return m
def assertSnarfNotError(self, query, **kwargs): def assertSnarfNotError(self, query, **kwargs):
@ -369,13 +369,13 @@ class PluginTestCase(SupyTestCase):
msg = m.args[1] msg = m.args[1]
if 'more message' in msg: if 'more message' in msg:
msg = msg[0:-27] # Strip (XXX more messages) msg = msg[0:-27] # Strip (XXX more messages)
self.failUnless(msg in lastGetHelp, self.assertTrue(msg in lastGetHelp,
'%s is not the help (%s)' % (m.args[1], lastGetHelp)) '%s is not the help (%s)' % (m.args[1], lastGetHelp))
return m return m
def assertNoResponse(self, query, timeout=0, **kwargs): def assertNoResponse(self, query, timeout=0, **kwargs):
m = self._feedMsg(query, timeout=timeout, **kwargs) m = self._feedMsg(query, timeout=timeout, **kwargs)
self.failIf(m, 'Unexpected response: %r' % m) self.assertFalse(m, 'Unexpected response: %r' % m)
return m return m
def assertSnarfNoResponse(self, query, timeout=0, **kwargs): def assertSnarfNoResponse(self, query, timeout=0, **kwargs):
@ -398,7 +398,7 @@ class PluginTestCase(SupyTestCase):
m = self._feedMsg(query, **kwargs) m = self._feedMsg(query, **kwargs)
if m is None: if m is None:
raise TimeoutError(query) raise TimeoutError(query)
self.failUnless(re.search(regexp, m.args[1], flags), self.assertTrue(re.search(regexp, m.args[1], flags),
'%r does not match %r' % (m.args[1], regexp)) '%r does not match %r' % (m.args[1], regexp))
return m return m
@ -410,7 +410,7 @@ class PluginTestCase(SupyTestCase):
m = self._feedMsg(query, **kwargs) m = self._feedMsg(query, **kwargs)
if m is None: if m is None:
raise TimeoutError(query) raise TimeoutError(query)
self.failUnless(re.search(regexp, m.args[1], flags) is None, self.assertTrue(re.search(regexp, m.args[1], flags) is None,
'%r matched %r' % (m.args[1], regexp)) '%r matched %r' % (m.args[1], regexp))
return m return m
@ -422,7 +422,7 @@ class PluginTestCase(SupyTestCase):
m = self._feedMsg(query, **kwargs) m = self._feedMsg(query, **kwargs)
if m is None: if m is None:
raise TimeoutError(query) raise TimeoutError(query)
self.failUnless(ircmsgs.isAction(m), '%r is not an action.' % m) self.assertTrue(ircmsgs.isAction(m), '%r is not an action.' % m)
if expectedResponse is not None: if expectedResponse is not None:
s = ircmsgs.unAction(m) s = ircmsgs.unAction(m)
self.assertEqual(s, expectedResponse, self.assertEqual(s, expectedResponse,
@ -437,9 +437,9 @@ class PluginTestCase(SupyTestCase):
m = self._feedMsg(query, **kwargs) m = self._feedMsg(query, **kwargs)
if m is None: if m is None:
raise TimeoutError(query) raise TimeoutError(query)
self.failUnless(ircmsgs.isAction(m)) self.assertTrue(ircmsgs.isAction(m))
s = ircmsgs.unAction(m) s = ircmsgs.unAction(m)
self.failUnless(re.search(regexp, s, flags), self.assertTrue(re.search(regexp, s, flags),
'%r does not match %r' % (s, regexp)) '%r does not match %r' % (s, regexp))
def assertSnarfActionRegexp(self, query, regexp, flags=re.I, **kwargs): def assertSnarfActionRegexp(self, query, regexp, flags=re.I, **kwargs):
@ -456,13 +456,13 @@ class PluginTestCase(SupyTestCase):
if ((name in self._noTestDoc) and \ if ((name in self._noTestDoc) and \
not name.lower() in self.__class__.__name__.lower()): not name.lower() in self.__class__.__name__.lower()):
continue continue
self.failUnless(sys.modules[cb.__class__.__name__].__doc__, self.assertTrue(sys.modules[cb.__class__.__name__].__doc__,
'%s has no module documentation.' % name) '%s has no module documentation.' % name)
if hasattr(cb, 'isCommandMethod'): if hasattr(cb, 'isCommandMethod'):
for attr in dir(cb): for attr in dir(cb):
if cb.isCommandMethod(attr) and \ if cb.isCommandMethod(attr) and \
attr == callbacks.canonicalName(attr): attr == callbacks.canonicalName(attr):
self.failUnless(getattr(cb, attr, None).__doc__, self.assertTrue(getattr(cb, attr, None).__doc__,
'%s.%s has no help.' % (name, attr)) '%s.%s has no help.' % (name, attr))
@ -476,13 +476,13 @@ class ChannelPluginTestCase(PluginTestCase):
PluginTestCase.setUp(self) PluginTestCase.setUp(self)
self.irc.feedMsg(ircmsgs.join(self.channel, prefix=self.prefix)) self.irc.feedMsg(ircmsgs.join(self.channel, prefix=self.prefix))
m = self.irc.takeMsg() m = self.irc.takeMsg()
self.failIf(m is None, 'No message back from joining channel.') self.assertFalse(m is None, 'No message back from joining channel.')
self.assertEqual(m.command, 'MODE') self.assertEqual(m.command, 'MODE')
m = self.irc.takeMsg() m = self.irc.takeMsg()
self.failIf(m is None, 'No message back from joining channel.') self.assertFalse(m is None, 'No message back from joining channel.')
self.assertEqual(m.command, 'MODE') self.assertEqual(m.command, 'MODE')
m = self.irc.takeMsg() m = self.irc.takeMsg()
self.failIf(m is None, 'No message back from joining channel.') self.assertFalse(m is None, 'No message back from joining channel.')
self.assertEqual(m.command, 'WHO') self.assertEqual(m.command, 'WHO')
def _feedMsg(self, query, timeout=None, to=None, frm=None, private=False, def _feedMsg(self, query, timeout=None, to=None, frm=None, private=False,

View File

@ -184,9 +184,9 @@ class FunctionsTestCase(SupyTestCase):
'%s: foo' % nick.capitalize(), '%s: foo' % nick.upper()] '%s: foo' % nick.capitalize(), '%s: foo' % nick.upper()]
inChannel = [ircmsgs.privmsg('#foo', s) for s in inChannel] inChannel = [ircmsgs.privmsg('#foo', s) for s in inChannel]
badmsg = ircmsgs.privmsg('#foo', '%s:foo' % nick) badmsg = ircmsgs.privmsg('#foo', '%s:foo' % nick)
self.failIf(callbacks.addressed(nick, badmsg)) self.assertFalse(callbacks.addressed(nick, badmsg))
badmsg = ircmsgs.privmsg('#foo', '%s^: foo' % nick) badmsg = ircmsgs.privmsg('#foo', '%s^: foo' % nick)
self.failIf(callbacks.addressed(nick, badmsg)) self.assertFalse(callbacks.addressed(nick, badmsg))
for msg in inChannel: for msg in inChannel:
self.assertEqual('foo', callbacks.addressed(nick, msg), msg) self.assertEqual('foo', callbacks.addressed(nick, msg), msg)
msg = ircmsgs.privmsg(nick, 'foo') msg = ircmsgs.privmsg(nick, 'foo')
@ -198,7 +198,7 @@ class FunctionsTestCase(SupyTestCase):
msg = ircmsgs.privmsg('#foo', '%s: foo' % nick.upper()) msg = ircmsgs.privmsg('#foo', '%s: foo' % nick.upper())
self.assertEqual('foo', callbacks.addressed(nick, msg)) self.assertEqual('foo', callbacks.addressed(nick, msg))
badmsg = ircmsgs.privmsg('#foo', '%s`: foo' % nick) badmsg = ircmsgs.privmsg('#foo', '%s`: foo' % nick)
self.failIf(callbacks.addressed(nick, badmsg)) self.assertFalse(callbacks.addressed(nick, badmsg))
def testAddressedReplyWhenNotAddressed(self): def testAddressedReplyWhenNotAddressed(self):
msg1 = ircmsgs.privmsg('#foo', '@bar') msg1 = ircmsgs.privmsg('#foo', '@bar')
@ -382,15 +382,15 @@ class PrivmsgTestCase(ChannelPluginTestCase):
def testReplyWithNickPrefix(self): def testReplyWithNickPrefix(self):
self.feedMsg('@len foo') self.feedMsg('@len foo')
m = self.irc.takeMsg() m = self.irc.takeMsg()
self.failUnless(m is not None, 'm: %r' % m) self.assertTrue(m is not None, 'm: %r' % m)
self.failUnless(m.args[1].startswith(self.nick)) self.assertTrue(m.args[1].startswith(self.nick))
try: try:
original = conf.supybot.reply.withNickPrefix() original = conf.supybot.reply.withNickPrefix()
conf.supybot.reply.withNickPrefix.setValue(False) conf.supybot.reply.withNickPrefix.setValue(False)
self.feedMsg('@len foobar') self.feedMsg('@len foobar')
m = self.irc.takeMsg() m = self.irc.takeMsg()
self.failUnless(m is not None) self.assertTrue(m is not None)
self.failIf(m.args[1].startswith(self.nick)) self.assertFalse(m.args[1].startswith(self.nick))
finally: finally:
conf.supybot.reply.withNickPrefix.setValue(original) conf.supybot.reply.withNickPrefix.setValue(original)
@ -399,8 +399,8 @@ class PrivmsgTestCase(ChannelPluginTestCase):
original = conf.supybot.reply.error.inPrivate() original = conf.supybot.reply.error.inPrivate()
conf.supybot.reply.error.inPrivate.setValue(False) conf.supybot.reply.error.inPrivate.setValue(False)
m = self.getMsg("eval irc.error('foo', private=True)") m = self.getMsg("eval irc.error('foo', private=True)")
self.failUnless(m, 'No message returned.') self.assertTrue(m, 'No message returned.')
self.failIf(ircutils.isChannel(m.args[0])) self.assertFalse(ircutils.isChannel(m.args[0]))
finally: finally:
conf.supybot.reply.error.inPrivate.setValue(original) conf.supybot.reply.error.inPrivate.setValue(original)
@ -412,8 +412,8 @@ class PrivmsgTestCase(ChannelPluginTestCase):
original = conf.supybot.reply.error.withNotice() original = conf.supybot.reply.error.withNotice()
conf.supybot.reply.error.withNotice.setValue(True) conf.supybot.reply.error.withNotice.setValue(True)
m = self.getMsg("eval irc.error('foo')") m = self.getMsg("eval irc.error('foo')")
self.failUnless(m, 'No message returned.') self.assertTrue(m, 'No message returned.')
self.failUnless(m.command == 'NOTICE') self.assertTrue(m.command == 'NOTICE')
finally: finally:
conf.supybot.reply.error.withNotice.setValue(original) conf.supybot.reply.error.withNotice.setValue(original)
@ -428,10 +428,10 @@ class PrivmsgTestCase(ChannelPluginTestCase):
s = 're s/foo/bar baz' # will error; should be "re s/foo/bar/ baz" s = 're s/foo/bar baz' # will error; should be "re s/foo/bar/ baz"
self.assertError(s) self.assertError(s)
m = self.getMsg(s) m = self.getMsg(s)
self.failUnless(ircutils.isChannel(m.args[0])) self.assertTrue(ircutils.isChannel(m.args[0]))
conf.supybot.reply.error.inPrivate.set('True') conf.supybot.reply.error.inPrivate.set('True')
m = self.getMsg(s) m = self.getMsg(s)
self.failIf(ircutils.isChannel(m.args[0])) self.assertFalse(ircutils.isChannel(m.args[0]))
finally: finally:
conf.supybot.reply.error.inPrivate.set(original) conf.supybot.reply.error.inPrivate.set(original)
@ -508,7 +508,7 @@ class PrivmsgTestCase(ChannelPluginTestCase):
self.irc.addCallback(self.TwoRepliesFirstAction(self.irc)) self.irc.addCallback(self.TwoRepliesFirstAction(self.irc))
self.assertAction('testactionreply', 'foo') self.assertAction('testactionreply', 'foo')
m = self.getMsg(' ') m = self.getMsg(' ')
self.failIf(m.args[1].startswith('\x01ACTION')) self.assertFalse(m.args[1].startswith('\x01ACTION'))
def testEmptyNest(self): def testEmptyNest(self):
try: try:
@ -670,11 +670,11 @@ class WithPrivateNoticeTestCase(ChannelPluginTestCase):
self.irc.addCallback(self.WithPrivateNotice(self.irc)) self.irc.addCallback(self.WithPrivateNotice(self.irc))
# Check normal behavior. # Check normal behavior.
m = self.assertNotError('normal') m = self.assertNotError('normal')
self.failIf(m.command == 'NOTICE') self.assertFalse(m.command == 'NOTICE')
self.failUnless(ircutils.isChannel(m.args[0])) self.assertTrue(ircutils.isChannel(m.args[0]))
m = self.assertNotError('explicit') m = self.assertNotError('explicit')
self.failIf(m.command == 'NOTICE') self.assertFalse(m.command == 'NOTICE')
self.failUnless(ircutils.isChannel(m.args[0])) self.assertTrue(ircutils.isChannel(m.args[0]))
# Check abnormal behavior. # Check abnormal behavior.
originalInPrivate = conf.supybot.reply.inPrivate() originalInPrivate = conf.supybot.reply.inPrivate()
originalWithNotice = conf.supybot.reply.withNotice() originalWithNotice = conf.supybot.reply.withNotice()
@ -682,11 +682,11 @@ class WithPrivateNoticeTestCase(ChannelPluginTestCase):
conf.supybot.reply.inPrivate.setValue(True) conf.supybot.reply.inPrivate.setValue(True)
conf.supybot.reply.withNotice.setValue(True) conf.supybot.reply.withNotice.setValue(True)
m = self.assertNotError('normal') m = self.assertNotError('normal')
self.failUnless(m.command == 'NOTICE') self.assertTrue(m.command == 'NOTICE')
self.failIf(ircutils.isChannel(m.args[0])) self.assertFalse(ircutils.isChannel(m.args[0]))
m = self.assertNotError('explicit') m = self.assertNotError('explicit')
self.failIf(m.command == 'NOTICE') self.assertFalse(m.command == 'NOTICE')
self.failUnless(ircutils.isChannel(m.args[0])) self.assertTrue(ircutils.isChannel(m.args[0]))
finally: finally:
conf.supybot.reply.inPrivate.setValue(originalInPrivate) conf.supybot.reply.inPrivate.setValue(originalInPrivate)
conf.supybot.reply.withNotice.setValue(originalWithNotice) conf.supybot.reply.withNotice.setValue(originalWithNotice)
@ -694,11 +694,11 @@ class WithPrivateNoticeTestCase(ChannelPluginTestCase):
try: try:
conf.supybot.reply.withNoticeWhenPrivate.setValue(True) conf.supybot.reply.withNoticeWhenPrivate.setValue(True)
m = self.assertNotError('implicit') m = self.assertNotError('implicit')
self.failUnless(m.command == 'NOTICE') self.assertTrue(m.command == 'NOTICE')
self.failIf(ircutils.isChannel(m.args[0])) self.assertFalse(ircutils.isChannel(m.args[0]))
m = self.assertNotError('normal') m = self.assertNotError('normal')
self.failIf(m.command == 'NOTICE') self.assertFalse(m.command == 'NOTICE')
self.failUnless(ircutils.isChannel(m.args[0])) self.assertTrue(ircutils.isChannel(m.args[0]))
finally: finally:
conf.supybot.reply.withNoticeWhenPrivate.setValue(orig) conf.supybot.reply.withNoticeWhenPrivate.setValue(orig)
@ -707,10 +707,10 @@ class WithPrivateNoticeTestCase(ChannelPluginTestCase):
try: try:
conf.supybot.reply.withNoticeWhenPrivate.setValue(True) conf.supybot.reply.withNoticeWhenPrivate.setValue(True)
m = self.assertNotError("eval irc.reply('y',to='x',private=True)") m = self.assertNotError("eval irc.reply('y',to='x',private=True)")
self.failUnless(m.command == 'NOTICE') self.assertTrue(m.command == 'NOTICE')
m = self.getMsg(' ') m = self.getMsg(' ')
m = self.assertNotError("eval irc.reply('y',to='#x',private=True)") m = self.assertNotError("eval irc.reply('y',to='#x',private=True)")
self.failIf(m.command == 'NOTICE') self.assertFalse(m.command == 'NOTICE')
finally: finally:
conf.supybot.reply.withNoticeWhenPrivate.setValue(original) conf.supybot.reply.withNoticeWhenPrivate.setValue(original)
@ -722,28 +722,28 @@ class ProxyTestCase(SupyTestCase):
irc = irclib.Irc('test') irc = irclib.Irc('test')
proxy = callbacks.SimpleProxy(irc, msg) proxy = callbacks.SimpleProxy(irc, msg)
# First one way... # First one way...
self.failIf(proxy != irc) self.assertFalse(proxy != irc)
self.failUnless(proxy == irc) self.assertTrue(proxy == irc)
self.assertEqual(hash(proxy), hash(irc)) self.assertEqual(hash(proxy), hash(irc))
# Then the other! # Then the other!
self.failIf(irc != proxy) self.assertFalse(irc != proxy)
self.failUnless(irc == proxy) self.assertTrue(irc == proxy)
self.assertEqual(hash(irc), hash(proxy)) self.assertEqual(hash(irc), hash(proxy))
# And now dictionaries... # And now dictionaries...
d = {} d = {}
d[irc] = 'foo' d[irc] = 'foo'
self.failUnless(len(d) == 1) self.assertTrue(len(d) == 1)
self.failUnless(d[irc] == 'foo') self.assertTrue(d[irc] == 'foo')
self.failUnless(d[proxy] == 'foo') self.assertTrue(d[proxy] == 'foo')
d[proxy] = 'bar' d[proxy] = 'bar'
self.failUnless(len(d) == 1) self.assertTrue(len(d) == 1)
self.failUnless(d[irc] == 'bar') self.assertTrue(d[irc] == 'bar')
self.failUnless(d[proxy] == 'bar') self.assertTrue(d[proxy] == 'bar')
d[irc] = 'foo' d[irc] = 'foo'
self.failUnless(len(d) == 1) self.assertTrue(len(d) == 1)
self.failUnless(d[irc] == 'foo') self.assertTrue(d[irc] == 'foo')
self.failUnless(d[proxy] == 'foo') self.assertTrue(d[proxy] == 'foo')

View File

@ -193,7 +193,7 @@ class ConverterTestCase(CommandsTestCase):
class FirstTestCase(CommandsTestCase): class FirstTestCase(CommandsTestCase):
def testRepr(self): def testRepr(self):
self.failUnless(repr(first('int'))) self.assertTrue(repr(first('int')))
def testFirstConverterFailsAndNotErroredState(self): def testFirstConverterFailsAndNotErroredState(self):
self.assertStateErrored([first('int', 'something')], ['words'], self.assertStateErrored([first('int', 'something')], ['words'],

View File

@ -31,7 +31,7 @@ from supybot.test import *
class FormatTestCase(SupyTestCase): class FormatTestCase(SupyTestCase):
def test_t_acceptsNone(self): def test_t_acceptsNone(self):
self.failUnless(format('%t', None)) self.assertTrue(format('%t', None))
def testFloatingPoint(self): def testFloatingPoint(self):
self.assertEqual(format('%.2f', 0.12345), '0.12') self.assertEqual(format('%.2f', 0.12345), '0.12')

View File

@ -48,17 +48,17 @@ class IrcdbTestCase(SupyTestCase):
class FunctionsTestCase(IrcdbTestCase): class FunctionsTestCase(IrcdbTestCase):
def testIsAntiCapability(self): def testIsAntiCapability(self):
self.failIf(ircdb.isAntiCapability('foo')) self.assertFalse(ircdb.isAntiCapability('foo'))
self.failIf(ircdb.isAntiCapability('#foo,bar')) self.assertFalse(ircdb.isAntiCapability('#foo,bar'))
self.failUnless(ircdb.isAntiCapability('-foo')) self.assertTrue(ircdb.isAntiCapability('-foo'))
self.failUnless(ircdb.isAntiCapability('#foo,-bar')) self.assertTrue(ircdb.isAntiCapability('#foo,-bar'))
self.failUnless(ircdb.isAntiCapability('#foo.bar,-baz')) self.assertTrue(ircdb.isAntiCapability('#foo.bar,-baz'))
def testIsChannelCapability(self): def testIsChannelCapability(self):
self.failIf(ircdb.isChannelCapability('foo')) self.assertFalse(ircdb.isChannelCapability('foo'))
self.failUnless(ircdb.isChannelCapability('#foo,bar')) self.assertTrue(ircdb.isChannelCapability('#foo,bar'))
self.failUnless(ircdb.isChannelCapability('#foo.bar,baz')) self.assertTrue(ircdb.isChannelCapability('#foo.bar,baz'))
self.failUnless(ircdb.isChannelCapability('#foo,bar.baz')) self.assertTrue(ircdb.isChannelCapability('#foo,bar.baz'))
def testMakeAntiCapability(self): def testMakeAntiCapability(self):
self.assertEqual(ircdb.makeAntiCapability('foo'), '-foo') self.assertEqual(ircdb.makeAntiCapability('foo'), '-foo')
@ -94,17 +94,17 @@ class CapabilitySetTestCase(SupyTestCase):
d = ircdb.CapabilitySet() d = ircdb.CapabilitySet()
self.assertRaises(KeyError, d.check, 'foo') self.assertRaises(KeyError, d.check, 'foo')
d = ircdb.CapabilitySet(('foo',)) d = ircdb.CapabilitySet(('foo',))
self.failUnless(d.check('foo')) self.assertTrue(d.check('foo'))
self.failIf(d.check('-foo')) self.assertFalse(d.check('-foo'))
d.add('bar') d.add('bar')
self.failUnless(d.check('bar')) self.assertTrue(d.check('bar'))
self.failIf(d.check('-bar')) self.assertFalse(d.check('-bar'))
d.add('-baz') d.add('-baz')
self.failIf(d.check('baz')) self.assertFalse(d.check('baz'))
self.failUnless(d.check('-baz')) self.assertTrue(d.check('-baz'))
d.add('-bar') d.add('-bar')
self.failIf(d.check('bar')) self.assertFalse(d.check('bar'))
self.failUnless(d.check('-bar')) self.assertTrue(d.check('-bar'))
d.remove('-bar') d.remove('-bar')
self.assertRaises(KeyError, d.check, '-bar') self.assertRaises(KeyError, d.check, '-bar')
self.assertRaises(KeyError, d.check, 'bar') self.assertRaises(KeyError, d.check, 'bar')
@ -119,31 +119,31 @@ class CapabilitySetTestCase(SupyTestCase):
def testContains(self): def testContains(self):
s = ircdb.CapabilitySet() s = ircdb.CapabilitySet()
self.failIf('foo' in s) self.assertFalse('foo' in s)
self.failIf('-foo' in s) self.assertFalse('-foo' in s)
s.add('foo') s.add('foo')
self.failUnless('foo' in s) self.assertTrue('foo' in s)
self.failUnless('-foo' in s) self.assertTrue('-foo' in s)
s.remove('foo') s.remove('foo')
self.failIf('foo' in s) self.assertFalse('foo' in s)
self.failIf('-foo' in s) self.assertFalse('-foo' in s)
s.add('-foo') s.add('-foo')
self.failUnless('foo' in s) self.assertTrue('foo' in s)
self.failUnless('-foo' in s) self.assertTrue('-foo' in s)
def testCheck(self): def testCheck(self):
s = ircdb.CapabilitySet() s = ircdb.CapabilitySet()
self.assertRaises(KeyError, s.check, 'foo') self.assertRaises(KeyError, s.check, 'foo')
self.assertRaises(KeyError, s.check, '-foo') self.assertRaises(KeyError, s.check, '-foo')
s.add('foo') s.add('foo')
self.failUnless(s.check('foo')) self.assertTrue(s.check('foo'))
self.failIf(s.check('-foo')) self.assertFalse(s.check('-foo'))
s.remove('foo') s.remove('foo')
self.assertRaises(KeyError, s.check, 'foo') self.assertRaises(KeyError, s.check, 'foo')
self.assertRaises(KeyError, s.check, '-foo') self.assertRaises(KeyError, s.check, '-foo')
s.add('-foo') s.add('-foo')
self.failIf(s.check('foo')) self.assertFalse(s.check('foo'))
self.failUnless(s.check('-foo')) self.assertTrue(s.check('-foo'))
s.remove('-foo') s.remove('-foo')
self.assertRaises(KeyError, s.check, 'foo') self.assertRaises(KeyError, s.check, 'foo')
self.assertRaises(KeyError, s.check, '-foo') self.assertRaises(KeyError, s.check, '-foo')
@ -152,26 +152,26 @@ class CapabilitySetTestCase(SupyTestCase):
s = ircdb.CapabilitySet() s = ircdb.CapabilitySet()
s.add('foo') s.add('foo')
s.add('-foo') s.add('-foo')
self.failIf(s.check('foo')) self.assertFalse(s.check('foo'))
self.failUnless(s.check('-foo')) self.assertTrue(s.check('-foo'))
s.add('foo') s.add('foo')
self.failUnless(s.check('foo')) self.assertTrue(s.check('foo'))
self.failIf(s.check('-foo')) self.assertFalse(s.check('-foo'))
class UserCapabilitySetTestCase(SupyTestCase): class UserCapabilitySetTestCase(SupyTestCase):
def testOwnerHasAll(self): def testOwnerHasAll(self):
d = ircdb.UserCapabilitySet(('owner',)) d = ircdb.UserCapabilitySet(('owner',))
self.failIf(d.check('-foo')) self.assertFalse(d.check('-foo'))
self.failUnless(d.check('foo')) self.assertTrue(d.check('foo'))
def testOwnerIsAlwaysPresent(self): def testOwnerIsAlwaysPresent(self):
d = ircdb.UserCapabilitySet() d = ircdb.UserCapabilitySet()
self.failUnless('owner' in d) self.assertTrue('owner' in d)
self.failUnless('-owner' in d) self.assertTrue('-owner' in d)
self.failIf(d.check('owner')) self.assertFalse(d.check('owner'))
d.add('owner') d.add('owner')
self.failUnless(d.check('owner')) self.assertTrue(d.check('owner'))
def testReprEval(self): def testReprEval(self):
s = ircdb.UserCapabilitySet() s = ircdb.UserCapabilitySet()
@ -184,30 +184,30 @@ class UserCapabilitySetTestCase(SupyTestCase):
def testOwner(self): def testOwner(self):
s = ircdb.UserCapabilitySet() s = ircdb.UserCapabilitySet()
s.add('owner') s.add('owner')
self.failUnless('foo' in s) self.assertTrue('foo' in s)
self.failUnless('-foo' in s) self.assertTrue('-foo' in s)
self.failUnless(s.check('owner')) self.assertTrue(s.check('owner'))
self.failIf(s.check('-owner')) self.assertFalse(s.check('-owner'))
self.failIf(s.check('-foo')) self.assertFalse(s.check('-foo'))
self.failUnless(s.check('foo')) self.assertTrue(s.check('foo'))
## def testWorksAfterReload(self): ## def testWorksAfterReload(self):
## s = ircdb.UserCapabilitySet(['owner']) ## s = ircdb.UserCapabilitySet(['owner'])
## self.failUnless(s.check('owner')) ## self.assertTrue(s.check('owner'))
## import sets ## import sets
## reload(sets) ## reload(sets)
## self.failUnless(s.check('owner')) ## self.assertTrue(s.check('owner'))
class IrcUserTestCase(IrcdbTestCase): class IrcUserTestCase(IrcdbTestCase):
def testCapabilities(self): def testCapabilities(self):
u = ircdb.IrcUser() u = ircdb.IrcUser()
u.addCapability('foo') u.addCapability('foo')
self.failUnless(u._checkCapability('foo')) self.assertTrue(u._checkCapability('foo'))
self.failIf(u._checkCapability('-foo')) self.assertFalse(u._checkCapability('-foo'))
u.addCapability('-bar') u.addCapability('-bar')
self.failUnless(u._checkCapability('-bar')) self.assertTrue(u._checkCapability('-bar'))
self.failIf(u._checkCapability('bar')) self.assertFalse(u._checkCapability('bar'))
u.removeCapability('foo') u.removeCapability('foo')
u.removeCapability('-bar') u.removeCapability('-bar')
self.assertRaises(KeyError, u._checkCapability, 'foo') self.assertRaises(KeyError, u._checkCapability, 'foo')
@ -220,26 +220,26 @@ class IrcUserTestCase(IrcdbTestCase):
def testRemoveHostmask(self): def testRemoveHostmask(self):
u = ircdb.IrcUser() u = ircdb.IrcUser()
u.addHostmask('foo!bar@baz') u.addHostmask('foo!bar@baz')
self.failUnless(u.checkHostmask('foo!bar@baz')) self.assertTrue(u.checkHostmask('foo!bar@baz'))
u.addHostmask('foo!bar@baz') u.addHostmask('foo!bar@baz')
u.removeHostmask('foo!bar@baz') u.removeHostmask('foo!bar@baz')
self.failIf(u.checkHostmask('foo!bar@baz')) self.assertFalse(u.checkHostmask('foo!bar@baz'))
def testOwner(self): def testOwner(self):
u = ircdb.IrcUser() u = ircdb.IrcUser()
u.addCapability('owner') u.addCapability('owner')
self.failUnless(u._checkCapability('foo')) self.assertTrue(u._checkCapability('foo'))
self.failIf(u._checkCapability('-foo')) self.assertFalse(u._checkCapability('-foo'))
def testInitCapabilities(self): def testInitCapabilities(self):
u = ircdb.IrcUser(capabilities=['foo']) u = ircdb.IrcUser(capabilities=['foo'])
self.failUnless(u._checkCapability('foo')) self.assertTrue(u._checkCapability('foo'))
def testPassword(self): def testPassword(self):
u = ircdb.IrcUser() u = ircdb.IrcUser()
u.setPassword('foobar') u.setPassword('foobar')
self.failUnless(u.checkPassword('foobar')) self.assertTrue(u.checkPassword('foobar'))
self.failIf(u.checkPassword('somethingelse')) self.assertFalse(u.checkPassword('somethingelse'))
def testTimeoutAuth(self): def testTimeoutAuth(self):
orig = conf.supybot.databases.users.timeoutIdentification() orig = conf.supybot.databases.users.timeoutIdentification()
@ -247,9 +247,9 @@ class IrcUserTestCase(IrcdbTestCase):
conf.supybot.databases.users.timeoutIdentification.setValue(2) conf.supybot.databases.users.timeoutIdentification.setValue(2)
u = ircdb.IrcUser() u = ircdb.IrcUser()
u.addAuth('foo!bar@baz') u.addAuth('foo!bar@baz')
self.failUnless(u.checkHostmask('foo!bar@baz')) self.assertTrue(u.checkHostmask('foo!bar@baz'))
timeFastForward(2.1) timeFastForward(2.1)
self.failIf(u.checkHostmask('foo!bar@baz')) self.assertFalse(u.checkHostmask('foo!bar@baz'))
finally: finally:
conf.supybot.databases.users.timeoutIdentification.setValue(orig) conf.supybot.databases.users.timeoutIdentification.setValue(orig)
@ -259,46 +259,46 @@ class IrcUserTestCase(IrcdbTestCase):
conf.supybot.databases.users.timeoutIdentification.setValue(2) conf.supybot.databases.users.timeoutIdentification.setValue(2)
u = ircdb.IrcUser() u = ircdb.IrcUser()
u.addAuth('foo!bar@baz') u.addAuth('foo!bar@baz')
self.failUnless(u.checkHostmask('foo!bar@baz')) self.assertTrue(u.checkHostmask('foo!bar@baz'))
u.addAuth('foo!bar@baz') u.addAuth('foo!bar@baz')
self.failUnless(u.checkHostmask('foo!bar@baz')) self.assertTrue(u.checkHostmask('foo!bar@baz'))
self.failUnless(len(u.auth) == 1) self.assertTrue(len(u.auth) == 1)
u.addAuth('boo!far@fizz') u.addAuth('boo!far@fizz')
self.failUnless(u.checkHostmask('boo!far@fizz')) self.assertTrue(u.checkHostmask('boo!far@fizz'))
timeFastForward(2.1) timeFastForward(2.1)
self.failIf(u.checkHostmask('foo!bar@baz')) self.assertFalse(u.checkHostmask('foo!bar@baz'))
self.failIf(u.checkHostmask('boo!far@fizz')) self.assertFalse(u.checkHostmask('boo!far@fizz'))
finally: finally:
conf.supybot.databases.users.timeoutIdentification.setValue(orig) conf.supybot.databases.users.timeoutIdentification.setValue(orig)
def testHashedPassword(self): def testHashedPassword(self):
u = ircdb.IrcUser() u = ircdb.IrcUser()
u.setPassword('foobar', hashed=True) u.setPassword('foobar', hashed=True)
self.failUnless(u.checkPassword('foobar')) self.assertTrue(u.checkPassword('foobar'))
self.failIf(u.checkPassword('somethingelse')) self.assertFalse(u.checkPassword('somethingelse'))
self.assertNotEqual(u.password, 'foobar') self.assertNotEqual(u.password, 'foobar')
def testHostmasks(self): def testHostmasks(self):
prefix = 'foo12341234!bar@baz.domain.tld' prefix = 'foo12341234!bar@baz.domain.tld'
hostmasks = ['*!bar@baz.domain.tld', 'foo12341234!*@*'] hostmasks = ['*!bar@baz.domain.tld', 'foo12341234!*@*']
u = ircdb.IrcUser() u = ircdb.IrcUser()
self.failIf(u.checkHostmask(prefix)) self.assertFalse(u.checkHostmask(prefix))
for hostmask in hostmasks: for hostmask in hostmasks:
u.addHostmask(hostmask) u.addHostmask(hostmask)
self.failUnless(u.checkHostmask(prefix)) self.assertTrue(u.checkHostmask(prefix))
def testAuth(self): def testAuth(self):
prefix = 'foo!bar@baz' prefix = 'foo!bar@baz'
u = ircdb.IrcUser() u = ircdb.IrcUser()
u.addAuth(prefix) u.addAuth(prefix)
self.failUnless(u.auth) self.assertTrue(u.auth)
u.clearAuth() u.clearAuth()
self.failIf(u.auth) self.assertFalse(u.auth)
def testIgnore(self): def testIgnore(self):
u = ircdb.IrcUser(ignore=True) u = ircdb.IrcUser(ignore=True)
self.failIf(u._checkCapability('foo')) self.assertFalse(u._checkCapability('foo'))
self.failUnless(u._checkCapability('-foo')) self.assertTrue(u._checkCapability('-foo'))
def testRemoveCapability(self): def testRemoveCapability(self):
u = ircdb.IrcUser(capabilities=('foo',)) u = ircdb.IrcUser(capabilities=('foo',))
@ -307,45 +307,45 @@ class IrcUserTestCase(IrcdbTestCase):
class IrcChannelTestCase(IrcdbTestCase): class IrcChannelTestCase(IrcdbTestCase):
def testInit(self): def testInit(self):
c = ircdb.IrcChannel() c = ircdb.IrcChannel()
self.failIf(c._checkCapability('op')) self.assertFalse(c._checkCapability('op'))
self.failIf(c._checkCapability('voice')) self.assertFalse(c._checkCapability('voice'))
self.failIf(c._checkCapability('halfop')) self.assertFalse(c._checkCapability('halfop'))
self.failIf(c._checkCapability('protected')) self.assertFalse(c._checkCapability('protected'))
def testCapabilities(self): def testCapabilities(self):
c = ircdb.IrcChannel(defaultAllow=False) c = ircdb.IrcChannel(defaultAllow=False)
self.failIf(c._checkCapability('foo')) self.assertFalse(c._checkCapability('foo'))
c.addCapability('foo') c.addCapability('foo')
self.failUnless(c._checkCapability('foo')) self.assertTrue(c._checkCapability('foo'))
c.removeCapability('foo') c.removeCapability('foo')
self.failIf(c._checkCapability('foo')) self.assertFalse(c._checkCapability('foo'))
def testDefaultCapability(self): def testDefaultCapability(self):
c = ircdb.IrcChannel() c = ircdb.IrcChannel()
c.setDefaultCapability(False) c.setDefaultCapability(False)
self.failIf(c._checkCapability('foo')) self.assertFalse(c._checkCapability('foo'))
self.failUnless(c._checkCapability('-foo')) self.assertTrue(c._checkCapability('-foo'))
c.setDefaultCapability(True) c.setDefaultCapability(True)
self.failUnless(c._checkCapability('foo')) self.assertTrue(c._checkCapability('foo'))
self.failIf(c._checkCapability('-foo')) self.assertFalse(c._checkCapability('-foo'))
def testLobotomized(self): def testLobotomized(self):
c = ircdb.IrcChannel(lobotomized=True) c = ircdb.IrcChannel(lobotomized=True)
self.failUnless(c.checkIgnored('foo!bar@baz')) self.assertTrue(c.checkIgnored('foo!bar@baz'))
def testIgnored(self): def testIgnored(self):
prefix = 'foo!bar@baz' prefix = 'foo!bar@baz'
banmask = ircutils.banmask(prefix) banmask = ircutils.banmask(prefix)
c = ircdb.IrcChannel() c = ircdb.IrcChannel()
self.failIf(c.checkIgnored(prefix)) self.assertFalse(c.checkIgnored(prefix))
c.addIgnore(banmask) c.addIgnore(banmask)
self.failUnless(c.checkIgnored(prefix)) self.assertTrue(c.checkIgnored(prefix))
c.removeIgnore(banmask) c.removeIgnore(banmask)
self.failIf(c.checkIgnored(prefix)) self.assertFalse(c.checkIgnored(prefix))
c.addBan(banmask) c.addBan(banmask)
self.failUnless(c.checkIgnored(prefix)) self.assertTrue(c.checkIgnored(prefix))
c.removeBan(banmask) c.removeBan(banmask)
self.failIf(c.checkIgnored(prefix)) self.assertFalse(c.checkIgnored(prefix))
class UsersDictionaryTestCase(IrcdbTestCase): class UsersDictionaryTestCase(IrcdbTestCase):
filename = os.path.join(conf.supybot.directories.conf(), filename = os.path.join(conf.supybot.directories.conf(),
@ -483,13 +483,13 @@ class CheckCapabilityTestCase(IrcdbTestCase):
self.users, self.channels) self.users, self.channels)
def testOwner(self): def testOwner(self):
self.failUnless(self.checkCapability(self.owner, self.cap)) self.assertTrue(self.checkCapability(self.owner, self.cap))
self.failIf(self.checkCapability(self.owner, self.anticap)) self.assertFalse(self.checkCapability(self.owner, self.anticap))
self.failUnless(self.checkCapability(self.owner, self.chancap)) self.assertTrue(self.checkCapability(self.owner, self.chancap))
self.failIf(self.checkCapability(self.owner, self.antichancap)) self.assertFalse(self.checkCapability(self.owner, self.antichancap))
self.channels.setChannel(self.channel, self.channelanticap) self.channels.setChannel(self.channel, self.channelanticap)
self.failUnless(self.checkCapability(self.owner, self.cap)) self.assertTrue(self.checkCapability(self.owner, self.cap))
self.failIf(self.checkCapability(self.owner, self.anticap)) self.assertFalse(self.checkCapability(self.owner, self.anticap))
def testNothingAgainstChannel(self): def testNothingAgainstChannel(self):
self.channels.setChannel(self.channel, self.channelnothing) self.channels.setChannel(self.channel, self.channelnothing)
@ -500,11 +500,11 @@ class CheckCapabilityTestCase(IrcdbTestCase):
self.assertEqual(self.checkCapability(self.nothing, self.chancap), self.assertEqual(self.checkCapability(self.nothing, self.chancap),
self.channelnothing.defaultAllow) self.channelnothing.defaultAllow)
self.channels.setChannel(self.channel, self.channelcap) self.channels.setChannel(self.channel, self.channelcap)
self.failUnless(self.checkCapability(self.nothing, self.chancap)) self.assertTrue(self.checkCapability(self.nothing, self.chancap))
self.failIf(self.checkCapability(self.nothing, self.antichancap)) self.assertFalse(self.checkCapability(self.nothing, self.antichancap))
self.channels.setChannel(self.channel, self.channelanticap) self.channels.setChannel(self.channel, self.channelanticap)
self.failIf(self.checkCapability(self.nothing, self.chancap)) self.assertFalse(self.checkCapability(self.nothing, self.chancap))
self.failUnless(self.checkCapability(self.nothing, self.antichancap)) self.assertTrue(self.checkCapability(self.nothing, self.antichancap))
def testNothing(self): def testNothing(self):
self.assertEqual(self.checkCapability(self.nothing, self.cap), self.assertEqual(self.checkCapability(self.nothing, self.cap),
@ -513,23 +513,23 @@ class CheckCapabilityTestCase(IrcdbTestCase):
not conf.supybot.capabilities.default()) not conf.supybot.capabilities.default())
def testJustFoo(self): def testJustFoo(self):
self.failUnless(self.checkCapability(self.justfoo, self.cap)) self.assertTrue(self.checkCapability(self.justfoo, self.cap))
self.failIf(self.checkCapability(self.justfoo, self.anticap)) self.assertFalse(self.checkCapability(self.justfoo, self.anticap))
def testAntiFoo(self): def testAntiFoo(self):
self.failUnless(self.checkCapability(self.antifoo, self.anticap)) self.assertTrue(self.checkCapability(self.antifoo, self.anticap))
self.failIf(self.checkCapability(self.antifoo, self.cap)) self.assertFalse(self.checkCapability(self.antifoo, self.cap))
def testJustChanFoo(self): def testJustChanFoo(self):
self.channels.setChannel(self.channel, self.channelnothing) self.channels.setChannel(self.channel, self.channelnothing)
self.failUnless(self.checkCapability(self.justchanfoo, self.chancap)) self.assertTrue(self.checkCapability(self.justchanfoo, self.chancap))
self.failIf(self.checkCapability(self.justchanfoo, self.antichancap)) self.assertFalse(self.checkCapability(self.justchanfoo, self.antichancap))
self.channelnothing.defaultAllow = not self.channelnothing.defaultAllow self.channelnothing.defaultAllow = not self.channelnothing.defaultAllow
self.failUnless(self.checkCapability(self.justchanfoo, self.chancap)) self.assertTrue(self.checkCapability(self.justchanfoo, self.chancap))
self.failIf(self.checkCapability(self.justchanfoo, self.antichancap)) self.assertFalse(self.checkCapability(self.justchanfoo, self.antichancap))
self.channels.setChannel(self.channel, self.channelanticap) self.channels.setChannel(self.channel, self.channelanticap)
self.failUnless(self.checkCapability(self.justchanfoo, self.chancap)) self.assertTrue(self.checkCapability(self.justchanfoo, self.chancap))
self.failIf(self.checkCapability(self.justchanfoo, self.antichancap)) self.assertFalse(self.checkCapability(self.justchanfoo, self.antichancap))
def testChanOpCountsAsEverything(self): def testChanOpCountsAsEverything(self):
self.channels.setChannel(self.channel, self.channelanticap) self.channels.setChannel(self.channel, self.channelanticap)
@ -537,20 +537,20 @@ class CheckCapabilityTestCase(IrcdbTestCase):
u = self.users.getUser(id) u = self.users.getUser(id)
u.addCapability(self.chanop) u.addCapability(self.chanop)
self.users.setUser(u) self.users.setUser(u)
self.failUnless(self.checkCapability(self.nothing, self.chancap)) self.assertTrue(self.checkCapability(self.nothing, self.chancap))
self.channels.setChannel(self.channel, self.channelnothing) self.channels.setChannel(self.channel, self.channelnothing)
self.failUnless(self.checkCapability(self.nothing, self.chancap)) self.assertTrue(self.checkCapability(self.nothing, self.chancap))
self.channelnothing.defaultAllow = not self.channelnothing.defaultAllow self.channelnothing.defaultAllow = not self.channelnothing.defaultAllow
self.failUnless(self.checkCapability(self.nothing, self.chancap)) self.assertTrue(self.checkCapability(self.nothing, self.chancap))
def testAntiChanFoo(self): def testAntiChanFoo(self):
self.channels.setChannel(self.channel, self.channelnothing) self.channels.setChannel(self.channel, self.channelnothing)
self.failIf(self.checkCapability(self.antichanfoo, self.chancap)) self.assertFalse(self.checkCapability(self.antichanfoo, self.chancap))
self.failUnless(self.checkCapability(self.antichanfoo, self.assertTrue(self.checkCapability(self.antichanfoo,
self.antichancap)) self.antichancap))
def testSecurefoo(self): def testSecurefoo(self):
self.failUnless(self.checkCapability(self.securefoo, self.cap)) self.assertTrue(self.checkCapability(self.securefoo, self.cap))
id = self.users.getUserId(self.securefoo) id = self.users.getUserId(self.securefoo)
u = self.users.getUser(id) u = self.users.getUser(id)
u.addAuth(self.securefoo) u.addAuth(self.securefoo)
@ -558,7 +558,7 @@ class CheckCapabilityTestCase(IrcdbTestCase):
try: try:
originalConfDefaultAllow = conf.supybot.capabilities.default() originalConfDefaultAllow = conf.supybot.capabilities.default()
conf.supybot.capabilities.default.set('False') conf.supybot.capabilities.default.set('False')
self.failIf(self.checkCapability('a' + self.securefoo, self.cap)) self.assertFalse(self.checkCapability('a' + self.securefoo, self.cap))
finally: finally:
conf.supybot.capabilities.default.set(str(originalConfDefaultAllow)) conf.supybot.capabilities.default.set(str(originalConfDefaultAllow))

View File

@ -169,13 +169,13 @@ class IrcMsgQueueTestCase(SupyTestCase):
q.enqueue(self.msg) q.enqueue(self.msg)
q.enqueue(self.msg) q.enqueue(self.msg)
q.enqueue(self.msg) q.enqueue(self.msg)
self.failUnless(self.msg in q) self.assertTrue(self.msg in q)
q.dequeue() q.dequeue()
self.failUnless(self.msg in q) self.assertTrue(self.msg in q)
q.dequeue() q.dequeue()
self.failUnless(self.msg in q) self.assertTrue(self.msg in q)
q.dequeue() q.dequeue()
self.failIf(self.msg in q) self.assertFalse(self.msg in q)
def testRepr(self): def testRepr(self):
q = irclib.IrcMsgQueue() q = irclib.IrcMsgQueue()
@ -189,14 +189,14 @@ class IrcMsgQueueTestCase(SupyTestCase):
def testEmpty(self): def testEmpty(self):
q = irclib.IrcMsgQueue() q = irclib.IrcMsgQueue()
self.failIf(q) self.assertFalse(q)
def testEnqueueDequeue(self): def testEnqueueDequeue(self):
q = irclib.IrcMsgQueue() q = irclib.IrcMsgQueue()
q.enqueue(self.msg) q.enqueue(self.msg)
self.failUnless(q) self.assertTrue(q)
self.assertEqual(self.msg, q.dequeue()) self.assertEqual(self.msg, q.dequeue())
self.failIf(q) self.assertFalse(q)
q.enqueue(self.msg) q.enqueue(self.msg)
q.enqueue(self.notice) q.enqueue(self.notice)
self.assertEqual(self.msg, q.dequeue()) self.assertEqual(self.msg, q.dequeue())
@ -236,7 +236,7 @@ class IrcMsgQueueTestCase(SupyTestCase):
q.enqueue(self.msg) q.enqueue(self.msg)
q.enqueue(self.msg) q.enqueue(self.msg)
self.assertEqual(self.msg, q.dequeue()) self.assertEqual(self.msg, q.dequeue())
self.failIf(q) self.assertFalse(q)
finally: finally:
configVar.setValue(original) configVar.setValue(original)
@ -278,39 +278,39 @@ class ChannelStateTestCase(SupyTestCase):
c1 = pickle.loads(pickle.dumps(c)) c1 = pickle.loads(pickle.dumps(c))
self.assertEqual(c, c1) self.assertEqual(c, c1)
c.removeUser('jemfinch') c.removeUser('jemfinch')
self.failIf('jemfinch' in c.users) self.assertFalse('jemfinch' in c.users)
self.failUnless('jemfinch' in c1.users) self.assertTrue('jemfinch' in c1.users)
def testCopy(self): def testCopy(self):
c = irclib.ChannelState() c = irclib.ChannelState()
c.addUser('jemfinch') c.addUser('jemfinch')
c1 = copy.deepcopy(c) c1 = copy.deepcopy(c)
c.removeUser('jemfinch') c.removeUser('jemfinch')
self.failIf('jemfinch' in c.users) self.assertFalse('jemfinch' in c.users)
self.failUnless('jemfinch' in c1.users) self.assertTrue('jemfinch' in c1.users)
def testAddUser(self): def testAddUser(self):
c = irclib.ChannelState() c = irclib.ChannelState()
c.addUser('foo') c.addUser('foo')
self.failUnless('foo' in c.users) self.assertTrue('foo' in c.users)
self.failIf('foo' in c.ops) self.assertFalse('foo' in c.ops)
self.failIf('foo' in c.voices) self.assertFalse('foo' in c.voices)
self.failIf('foo' in c.halfops) self.assertFalse('foo' in c.halfops)
c.addUser('+bar') c.addUser('+bar')
self.failUnless('bar' in c.users) self.assertTrue('bar' in c.users)
self.failUnless('bar' in c.voices) self.assertTrue('bar' in c.voices)
self.failIf('bar' in c.ops) self.assertFalse('bar' in c.ops)
self.failIf('bar' in c.halfops) self.assertFalse('bar' in c.halfops)
c.addUser('%baz') c.addUser('%baz')
self.failUnless('baz' in c.users) self.assertTrue('baz' in c.users)
self.failUnless('baz' in c.halfops) self.assertTrue('baz' in c.halfops)
self.failIf('baz' in c.voices) self.assertFalse('baz' in c.voices)
self.failIf('baz' in c.ops) self.assertFalse('baz' in c.ops)
c.addUser('@quuz') c.addUser('@quuz')
self.failUnless('quuz' in c.users) self.assertTrue('quuz' in c.users)
self.failUnless('quuz' in c.ops) self.assertTrue('quuz' in c.ops)
self.failIf('quuz' in c.halfops) self.assertFalse('quuz' in c.halfops)
self.failIf('quuz' in c.voices) self.assertFalse('quuz' in c.voices)
class IrcStateTestCase(SupyTestCase): class IrcStateTestCase(SupyTestCase):
@ -327,7 +327,7 @@ class IrcStateTestCase(SupyTestCase):
st.channels['#foo'] = irclib.ChannelState() st.channels['#foo'] = irclib.ChannelState()
m = ircmsgs.kick('#foo', self.irc.nick, prefix=self.irc.prefix) m = ircmsgs.kick('#foo', self.irc.nick, prefix=self.irc.prefix)
st.addMsg(self.irc, m) st.addMsg(self.irc, m)
self.failIf('#foo' in st.channels) self.assertFalse('#foo' in st.channels)
def testAddMsgRemovesOpsProperly(self): def testAddMsgRemovesOpsProperly(self):
st = irclib.IrcState() st = irclib.IrcState()
@ -335,19 +335,19 @@ class IrcStateTestCase(SupyTestCase):
st.channels['#foo'].ops.add('bar') st.channels['#foo'].ops.add('bar')
m = ircmsgs.mode('#foo', ('-o', 'bar')) m = ircmsgs.mode('#foo', ('-o', 'bar'))
st.addMsg(self.irc, m) st.addMsg(self.irc, m)
self.failIf('bar' in st.channels['#foo'].ops) self.assertFalse('bar' in st.channels['#foo'].ops)
def testNickChangesChangeChannelUsers(self): def testNickChangesChangeChannelUsers(self):
st = irclib.IrcState() st = irclib.IrcState()
st.channels['#foo'] = irclib.ChannelState() st.channels['#foo'] = irclib.ChannelState()
st.channels['#foo'].addUser('@bar') st.channels['#foo'].addUser('@bar')
self.failUnless('bar' in st.channels['#foo'].users) self.assertTrue('bar' in st.channels['#foo'].users)
self.failUnless(st.channels['#foo'].isOp('bar')) self.assertTrue(st.channels['#foo'].isOp('bar'))
st.addMsg(self.irc, ircmsgs.IrcMsg(':bar!asfd@asdf.com NICK baz')) st.addMsg(self.irc, ircmsgs.IrcMsg(':bar!asfd@asdf.com NICK baz'))
self.failIf('bar' in st.channels['#foo'].users) self.assertFalse('bar' in st.channels['#foo'].users)
self.failIf(st.channels['#foo'].isOp('bar')) self.assertFalse(st.channels['#foo'].isOp('bar'))
self.failUnless('baz' in st.channels['#foo'].users) self.assertTrue('baz' in st.channels['#foo'].users)
self.failUnless(st.channels['#foo'].isOp('baz')) self.assertTrue(st.channels['#foo'].isOp('baz'))
def testHistory(self): def testHistory(self):
if len(msgs) < 10: if len(msgs) < 10:
@ -360,7 +360,7 @@ class IrcStateTestCase(SupyTestCase):
state.addMsg(self.irc, msg) state.addMsg(self.irc, msg)
except Exception: except Exception:
pass pass
self.failIf(len(state.history) > maxHistoryLength()) self.assertFalse(len(state.history) > maxHistoryLength())
self.assertEqual(len(state.history), maxHistoryLength()) self.assertEqual(len(state.history), maxHistoryLength())
self.assertEqual(list(state.history), self.assertEqual(list(state.history),
msgs[len(msgs) - maxHistoryLength():]) msgs[len(msgs) - maxHistoryLength():])
@ -414,19 +414,19 @@ class IrcStateTestCase(SupyTestCase):
state = irclib.IrcState() state = irclib.IrcState()
stateCopy = state.copy() stateCopy = state.copy()
state.channels['#foo'] = None state.channels['#foo'] = None
self.failIf('#foo' in stateCopy.channels) self.assertFalse('#foo' in stateCopy.channels)
def testJoin(self): def testJoin(self):
st = irclib.IrcState() st = irclib.IrcState()
st.addMsg(self.irc, ircmsgs.join('#foo', prefix=self.irc.prefix)) st.addMsg(self.irc, ircmsgs.join('#foo', prefix=self.irc.prefix))
self.failUnless('#foo' in st.channels) self.assertTrue('#foo' in st.channels)
self.failUnless(self.irc.nick in st.channels['#foo'].users) self.assertTrue(self.irc.nick in st.channels['#foo'].users)
st.addMsg(self.irc, ircmsgs.join('#foo', prefix='foo!bar@baz')) st.addMsg(self.irc, ircmsgs.join('#foo', prefix='foo!bar@baz'))
self.failUnless('foo' in st.channels['#foo'].users) self.assertTrue('foo' in st.channels['#foo'].users)
st2 = st.copy() st2 = st.copy()
st.addMsg(self.irc, ircmsgs.quit(prefix='foo!bar@baz')) st.addMsg(self.irc, ircmsgs.quit(prefix='foo!bar@baz'))
self.failIf('foo' in st.channels['#foo'].users) self.assertFalse('foo' in st.channels['#foo'].users)
self.failUnless('foo' in st2.channels['#foo'].users) self.assertTrue('foo' in st2.channels['#foo'].users)
def testEq(self): def testEq(self):
@ -444,23 +444,23 @@ class IrcStateTestCase(SupyTestCase):
def testHandlesModes(self): def testHandlesModes(self):
st = irclib.IrcState() st = irclib.IrcState()
st.addMsg(self.irc, ircmsgs.join('#foo', prefix=self.irc.prefix)) st.addMsg(self.irc, ircmsgs.join('#foo', prefix=self.irc.prefix))
self.failIf('bar' in st.channels['#foo'].ops) self.assertFalse('bar' in st.channels['#foo'].ops)
st.addMsg(self.irc, ircmsgs.op('#foo', 'bar')) st.addMsg(self.irc, ircmsgs.op('#foo', 'bar'))
self.failUnless('bar' in st.channels['#foo'].ops) self.assertTrue('bar' in st.channels['#foo'].ops)
st.addMsg(self.irc, ircmsgs.deop('#foo', 'bar')) st.addMsg(self.irc, ircmsgs.deop('#foo', 'bar'))
self.failIf('bar' in st.channels['#foo'].ops) self.assertFalse('bar' in st.channels['#foo'].ops)
self.failIf('bar' in st.channels['#foo'].voices) self.assertFalse('bar' in st.channels['#foo'].voices)
st.addMsg(self.irc, ircmsgs.voice('#foo', 'bar')) st.addMsg(self.irc, ircmsgs.voice('#foo', 'bar'))
self.failUnless('bar' in st.channels['#foo'].voices) self.assertTrue('bar' in st.channels['#foo'].voices)
st.addMsg(self.irc, ircmsgs.devoice('#foo', 'bar')) st.addMsg(self.irc, ircmsgs.devoice('#foo', 'bar'))
self.failIf('bar' in st.channels['#foo'].voices) self.assertFalse('bar' in st.channels['#foo'].voices)
self.failIf('bar' in st.channels['#foo'].halfops) self.assertFalse('bar' in st.channels['#foo'].halfops)
st.addMsg(self.irc, ircmsgs.halfop('#foo', 'bar')) st.addMsg(self.irc, ircmsgs.halfop('#foo', 'bar'))
self.failUnless('bar' in st.channels['#foo'].halfops) self.assertTrue('bar' in st.channels['#foo'].halfops)
st.addMsg(self.irc, ircmsgs.dehalfop('#foo', 'bar')) st.addMsg(self.irc, ircmsgs.dehalfop('#foo', 'bar'))
self.failIf('bar' in st.channels['#foo'].halfops) self.assertFalse('bar' in st.channels['#foo'].halfops)
def testDoModeOnlyChannels(self): def testDoModeOnlyChannels(self):
st = irclib.IrcState() st = irclib.IrcState()
@ -471,14 +471,14 @@ class IrcCapsTestCase(SupyTestCase):
self.irc = irclib.Irc('test') self.irc = irclib.Irc('test')
m = self.irc.takeMsg() m = self.irc.takeMsg()
self.failUnless(m.command == 'CAP', 'Expected CAP, got %r.' % m) self.assertTrue(m.command == 'CAP', 'Expected CAP, got %r.' % m)
self.failUnless(m.args == ('LS', '302'), 'Expected CAP LS 302, got %r.' % m) self.assertTrue(m.args == ('LS', '302'), 'Expected CAP LS 302, got %r.' % m)
m = self.irc.takeMsg() m = self.irc.takeMsg()
self.failUnless(m.command == 'NICK', 'Expected NICK, got %r.' % m) self.assertTrue(m.command == 'NICK', 'Expected NICK, got %r.' % m)
m = self.irc.takeMsg() m = self.irc.takeMsg()
self.failUnless(m.command == 'USER', 'Expected USER, got %r.' % m) self.assertTrue(m.command == 'USER', 'Expected USER, got %r.' % m)
self.irc.REQUEST_CAPABILITIES = set(['a'*400, 'b'*400]) self.irc.REQUEST_CAPABILITIES = set(['a'*400, 'b'*400])
caps = ' '.join(self.irc.REQUEST_CAPABILITIES) caps = ' '.join(self.irc.REQUEST_CAPABILITIES)
@ -488,12 +488,12 @@ class IrcCapsTestCase(SupyTestCase):
args=('*', 'LS', 'b'*400))) args=('*', 'LS', 'b'*400)))
m = self.irc.takeMsg() m = self.irc.takeMsg()
self.failUnless(m.command == 'CAP', 'Expected CAP, got %r.' % m) self.assertTrue(m.command == 'CAP', 'Expected CAP, got %r.' % m)
self.assertEqual(m.args[0], 'REQ', m) self.assertEqual(m.args[0], 'REQ', m)
self.assertEqual(m.args[1], 'a'*400) self.assertEqual(m.args[1], 'a'*400)
m = self.irc.takeMsg() m = self.irc.takeMsg()
self.failUnless(m.command == 'CAP', 'Expected CAP, got %r.' % m) self.assertTrue(m.command == 'CAP', 'Expected CAP, got %r.' % m)
self.assertEqual(m.args[0], 'REQ', m) self.assertEqual(m.args[0], 'REQ', m)
self.assertEqual(m.args[1], 'b'*400) self.assertEqual(m.args[1], 'b'*400)
@ -502,17 +502,17 @@ class IrcTestCase(SupyTestCase):
self.irc = irclib.Irc('test') self.irc = irclib.Irc('test')
#m = self.irc.takeMsg() #m = self.irc.takeMsg()
#self.failUnless(m.command == 'PASS', 'Expected PASS, got %r.' % m) #self.assertTrue(m.command == 'PASS', 'Expected PASS, got %r.' % m)
m = self.irc.takeMsg() m = self.irc.takeMsg()
self.failUnless(m.command == 'CAP', 'Expected CAP, got %r.' % m) self.assertTrue(m.command == 'CAP', 'Expected CAP, got %r.' % m)
self.failUnless(m.args == ('LS', '302'), 'Expected CAP LS 302, got %r.' % m) self.assertTrue(m.args == ('LS', '302'), 'Expected CAP LS 302, got %r.' % m)
m = self.irc.takeMsg() m = self.irc.takeMsg()
self.failUnless(m.command == 'NICK', 'Expected NICK, got %r.' % m) self.assertTrue(m.command == 'NICK', 'Expected NICK, got %r.' % m)
m = self.irc.takeMsg() m = self.irc.takeMsg()
self.failUnless(m.command == 'USER', 'Expected USER, got %r.' % m) self.assertTrue(m.command == 'USER', 'Expected USER, got %r.' % m)
# TODO # TODO
self.irc.feedMsg(ircmsgs.IrcMsg(command='CAP', self.irc.feedMsg(ircmsgs.IrcMsg(command='CAP',
@ -521,7 +521,7 @@ class IrcTestCase(SupyTestCase):
args=('*', 'LS', 'extended-join'))) args=('*', 'LS', 'extended-join')))
m = self.irc.takeMsg() m = self.irc.takeMsg()
self.failUnless(m.command == 'CAP', 'Expected CAP, got %r.' % m) self.assertTrue(m.command == 'CAP', 'Expected CAP, got %r.' % m)
self.assertEqual(m.args[0], 'REQ', m) self.assertEqual(m.args[0], 'REQ', m)
# NOTE: Capabilities are requested in alphabetic order, because # NOTE: Capabilities are requested in alphabetic order, because
# sets are unordered, and their "order" is nondeterministic. # sets are unordered, and their "order" is nondeterministic.
@ -531,11 +531,11 @@ class IrcTestCase(SupyTestCase):
args=('*', 'ACK', 'account-tag multi-prefix extended-join'))) args=('*', 'ACK', 'account-tag multi-prefix extended-join')))
m = self.irc.takeMsg() m = self.irc.takeMsg()
self.failUnless(m.command == 'CAP', 'Expected CAP, got %r.' % m) self.assertTrue(m.command == 'CAP', 'Expected CAP, got %r.' % m)
self.assertEqual(m.args, ('END',), m) self.assertEqual(m.args, ('END',), m)
m = self.irc.takeMsg() m = self.irc.takeMsg()
self.failUnless(m is None, m) self.assertTrue(m is None, m)
def testPingResponse(self): def testPingResponse(self):
self.irc.feedMsg(ircmsgs.ping('123')) self.irc.feedMsg(ircmsgs.ping('123'))
@ -547,11 +547,11 @@ class IrcTestCase(SupyTestCase):
self.irc.feedMsg(ircmsgs.IrcMsg('433 * %s :Nickname already in use.' %\ self.irc.feedMsg(ircmsgs.IrcMsg('433 * %s :Nickname already in use.' %\
self.irc.nick)) self.irc.nick))
msg = self.irc.takeMsg() msg = self.irc.takeMsg()
self.failUnless(msg.command == 'NICK' and msg.args[0] != self.irc.nick) self.assertTrue(msg.command == 'NICK' and msg.args[0] != self.irc.nick)
self.irc.feedMsg(ircmsgs.IrcMsg('433 * %s :Nickname already in use.' %\ self.irc.feedMsg(ircmsgs.IrcMsg('433 * %s :Nickname already in use.' %\
self.irc.nick)) self.irc.nick))
msg = self.irc.takeMsg() msg = self.irc.takeMsg()
self.failUnless(msg.command == 'NICK' and msg.args[0] != self.irc.nick) self.assertTrue(msg.command == 'NICK' and msg.args[0] != self.irc.nick)
def testSendBeforeQueue(self): def testSendBeforeQueue(self):
while self.irc.takeMsg() is not None: while self.irc.takeMsg() is not None:
@ -559,14 +559,14 @@ class IrcTestCase(SupyTestCase):
self.irc.queueMsg(ircmsgs.IrcMsg('NOTICE #foo bar')) self.irc.queueMsg(ircmsgs.IrcMsg('NOTICE #foo bar'))
self.irc.sendMsg(ircmsgs.IrcMsg('PRIVMSG #foo yeah!')) self.irc.sendMsg(ircmsgs.IrcMsg('PRIVMSG #foo yeah!'))
msg = self.irc.takeMsg() msg = self.irc.takeMsg()
self.failUnless(msg.command == 'PRIVMSG') self.assertTrue(msg.command == 'PRIVMSG')
msg = self.irc.takeMsg() msg = self.irc.takeMsg()
self.failUnless(msg.command == 'NOTICE') self.assertTrue(msg.command == 'NOTICE')
def testNoMsgLongerThan512(self): def testNoMsgLongerThan512(self):
self.irc.queueMsg(ircmsgs.privmsg('whocares', 'x'*1000)) self.irc.queueMsg(ircmsgs.privmsg('whocares', 'x'*1000))
msg = self.irc.takeMsg() msg = self.irc.takeMsg()
self.failUnless(len(msg) <= 512, 'len(msg) was %s' % len(msg)) self.assertTrue(len(msg) <= 512, 'len(msg) was %s' % len(msg))
def testReset(self): def testReset(self):
for msg in msgs: for msg in msgs:
@ -575,9 +575,9 @@ class IrcTestCase(SupyTestCase):
except: except:
pass pass
self.irc.reset() self.irc.reset()
self.failIf(self.irc.state.history) self.assertFalse(self.irc.state.history)
self.failIf(self.irc.state.channels) self.assertFalse(self.irc.state.channels)
self.failIf(self.irc.outstandingPing) self.assertFalse(self.irc.outstandingPing)
def testHistory(self): def testHistory(self):
self.irc.reset() self.irc.reset()
@ -691,21 +691,21 @@ class SaslTestCase(SupyTestCase):
def startCapNegociation(self, caps='sasl'): def startCapNegociation(self, caps='sasl'):
m = self.irc.takeMsg() m = self.irc.takeMsg()
self.failUnless(m.command == 'CAP', 'Expected CAP, got %r.' % m) self.assertTrue(m.command == 'CAP', 'Expected CAP, got %r.' % m)
self.failUnless(m.args == ('LS', '302'), 'Expected CAP LS 302, got %r.' % m) self.assertTrue(m.args == ('LS', '302'), 'Expected CAP LS 302, got %r.' % m)
m = self.irc.takeMsg() m = self.irc.takeMsg()
self.failUnless(m.command == 'NICK', 'Expected NICK, got %r.' % m) self.assertTrue(m.command == 'NICK', 'Expected NICK, got %r.' % m)
m = self.irc.takeMsg() m = self.irc.takeMsg()
self.failUnless(m.command == 'USER', 'Expected USER, got %r.' % m) self.assertTrue(m.command == 'USER', 'Expected USER, got %r.' % m)
self.irc.feedMsg(ircmsgs.IrcMsg(command='CAP', self.irc.feedMsg(ircmsgs.IrcMsg(command='CAP',
args=('*', 'LS', caps))) args=('*', 'LS', caps)))
if caps: if caps:
m = self.irc.takeMsg() m = self.irc.takeMsg()
self.failUnless(m.command == 'CAP', 'Expected CAP, got %r.' % m) self.assertTrue(m.command == 'CAP', 'Expected CAP, got %r.' % m)
self.assertEqual(m.args[0], 'REQ', m) self.assertEqual(m.args[0], 'REQ', m)
self.assertEqual(m.args[1], 'sasl') self.assertEqual(m.args[1], 'sasl')
@ -714,7 +714,7 @@ class SaslTestCase(SupyTestCase):
def endCapNegociation(self): def endCapNegociation(self):
m = self.irc.takeMsg() m = self.irc.takeMsg()
self.failUnless(m.command == 'CAP', 'Expected CAP, got %r.' % m) self.assertTrue(m.command == 'CAP', 'Expected CAP, got %r.' % m)
self.assertEqual(m.args, ('END',), m) self.assertEqual(m.args, ('END',), m)
def testPlain(self): def testPlain(self):
@ -850,7 +850,7 @@ class SaslTestCase(SupyTestCase):
conf.supybot.networks.test.sasl.password.setValue('') conf.supybot.networks.test.sasl.password.setValue('')
m = self.irc.takeMsg() m = self.irc.takeMsg()
self.failUnless(m.command == 'CAP', 'Expected CAP, got %r.' % m) self.assertTrue(m.command == 'CAP', 'Expected CAP, got %r.' % m)
self.assertEqual(m.args[0], 'REQ', m) self.assertEqual(m.args[0], 'REQ', m)
self.assertEqual(m.args[1], 'sasl') self.assertEqual(m.args[1], 'sasl')
self.irc.feedMsg(ircmsgs.IrcMsg(command='CAP', self.irc.feedMsg(ircmsgs.IrcMsg(command='CAP',

View File

@ -47,7 +47,7 @@ class IrcMsgTestCase(SupyTestCase):
for msg in msgs: for msg in msgs:
if msg.prefix: if msg.prefix:
strmsg = str(msg) strmsg = str(msg)
self.failIf(len(msg) != len(strmsg) and \ self.assertFalse(len(msg) != len(strmsg) and \
strmsg.replace(':', '') == strmsg) strmsg.replace(':', '') == strmsg)
def testRepr(self): def testRepr(self):
@ -58,17 +58,17 @@ class IrcMsgTestCase(SupyTestCase):
def testStr(self): def testStr(self):
for (rawmsg, msg) in zip(rawmsgs, msgs): for (rawmsg, msg) in zip(rawmsgs, msgs):
strmsg = str(msg).strip() strmsg = str(msg).strip()
self.failIf(rawmsg != strmsg and \ self.assertFalse(rawmsg != strmsg and \
strmsg.replace(':', '') == strmsg) strmsg.replace(':', '') == strmsg)
def testEq(self): def testEq(self):
for msg in msgs: for msg in msgs:
self.assertEqual(msg, msg) self.assertEqual(msg, msg)
self.failIf(msgs and msgs[0] == []) # Comparison to unhashable type. self.assertFalse(msgs and msgs[0] == []) # Comparison to unhashable type.
def testNe(self): def testNe(self):
for msg in msgs: for msg in msgs:
self.failIf(msg != msg) self.assertFalse(msg != msg)
## def testImmutability(self): ## def testImmutability(self):
## s = 'something else' ## s = 'something else'
@ -111,7 +111,7 @@ class IrcMsgTestCase(SupyTestCase):
for msg in msgs: for msg in msgs:
if hash(msg) == 0: if hash(msg) == 0:
zeroes += 1 zeroes += 1
self.failIf(zeroes > (len(msgs)/10), 'Too many zero hashes.') self.assertFalse(zeroes > (len(msgs)/10), 'Too many zero hashes.')
def testMsgKeywordHandledProperly(self): def testMsgKeywordHandledProperly(self):
msg = ircmsgs.notice('foo', 'bar') msg = ircmsgs.notice('foo', 'bar')
@ -126,11 +126,11 @@ class IrcMsgTestCase(SupyTestCase):
def testTags(self): def testTags(self):
m = ircmsgs.privmsg('foo', 'bar') m = ircmsgs.privmsg('foo', 'bar')
self.failIf(m.repliedTo) self.assertFalse(m.repliedTo)
m.tag('repliedTo') m.tag('repliedTo')
self.failUnless(m.repliedTo) self.assertTrue(m.repliedTo)
m.tag('repliedTo') m.tag('repliedTo')
self.failUnless(m.repliedTo) self.assertTrue(m.repliedTo)
m.tag('repliedTo', 12) m.tag('repliedTo', 12)
self.assertEqual(m.repliedTo, 12) self.assertEqual(m.repliedTo, 12)
@ -177,22 +177,22 @@ class FunctionsTestCase(SupyTestCase):
':ACTION resizes angryman\'s terminal to 40x24 (#16)'] ':ACTION resizes angryman\'s terminal to 40x24 (#16)']
msgs = list(map(ircmsgs.IrcMsg, L)) msgs = list(map(ircmsgs.IrcMsg, L))
for msg in msgs: for msg in msgs:
self.failUnless(ircmsgs.isAction(msg)) self.assertTrue(ircmsgs.isAction(msg))
def testIsActionIsntStupid(self): def testIsActionIsntStupid(self):
m = ircmsgs.privmsg('#x', '\x01NOTANACTION foo\x01') m = ircmsgs.privmsg('#x', '\x01NOTANACTION foo\x01')
self.failIf(ircmsgs.isAction(m)) self.assertFalse(ircmsgs.isAction(m))
m = ircmsgs.privmsg('#x', '\x01ACTION foo bar\x01') m = ircmsgs.privmsg('#x', '\x01ACTION foo bar\x01')
self.failUnless(ircmsgs.isAction(m)) self.assertTrue(ircmsgs.isAction(m))
def testIsCtcp(self): def testIsCtcp(self):
self.failUnless(ircmsgs.isCtcp(ircmsgs.privmsg('foo', self.assertTrue(ircmsgs.isCtcp(ircmsgs.privmsg('foo',
'\x01VERSION\x01'))) '\x01VERSION\x01')))
self.failIf(ircmsgs.isCtcp(ircmsgs.privmsg('foo', '\x01'))) self.assertFalse(ircmsgs.isCtcp(ircmsgs.privmsg('foo', '\x01')))
def testIsActionFalseWhenNoSpaces(self): def testIsActionFalseWhenNoSpaces(self):
msg = ircmsgs.IrcMsg('PRIVMSG #foo :\x01ACTIONfoobar\x01') msg = ircmsgs.IrcMsg('PRIVMSG #foo :\x01ACTIONfoobar\x01')
self.failIf(ircmsgs.isAction(msg)) self.assertFalse(ircmsgs.isAction(msg))
def testUnAction(self): def testUnAction(self):
s = 'foo bar baz' s = 'foo bar baz'
@ -259,7 +259,7 @@ class FunctionsTestCase(SupyTestCase):
('#osu,#umich', 'michiganSucks')) ('#osu,#umich', 'michiganSucks'))
def testQuit(self): def testQuit(self):
self.failUnless(ircmsgs.quit(prefix='foo!bar@baz')) self.assertTrue(ircmsgs.quit(prefix='foo!bar@baz'))
def testOps(self): def testOps(self):
m = ircmsgs.ops('#foo', ['foo', 'bar', 'baz']) m = ircmsgs.ops('#foo', ['foo', 'bar', 'baz'])
@ -294,15 +294,15 @@ class FunctionsTestCase(SupyTestCase):
m = ircmsgs.IrcMsg(prefix="caker!~caker@ns.theshore.net", m = ircmsgs.IrcMsg(prefix="caker!~caker@ns.theshore.net",
command="QUIT", command="QUIT",
args=('jupiter.oftc.net quasar.oftc.net',)) args=('jupiter.oftc.net quasar.oftc.net',))
self.failUnless(ircmsgs.isSplit(m)) self.assertTrue(ircmsgs.isSplit(m))
m = ircmsgs.IrcMsg(prefix="bzbot!Brad2901@ACC87473.ipt.aol.com", m = ircmsgs.IrcMsg(prefix="bzbot!Brad2901@ACC87473.ipt.aol.com",
command="QUIT", command="QUIT",
args=('Read error: 110 (Connection timed out)',)) args=('Read error: 110 (Connection timed out)',))
self.failIf(ircmsgs.isSplit(m)) self.assertFalse(ircmsgs.isSplit(m))
m = ircmsgs.IrcMsg(prefix="JibberJim!~none@8212cl.b0nwbeoe.co.uk", m = ircmsgs.IrcMsg(prefix="JibberJim!~none@8212cl.b0nwbeoe.co.uk",
command="QUIT", command="QUIT",
args=('"Bye!"',)) args=('"Bye!"',))
self.failIf(ircmsgs.isSplit(m)) self.assertFalse(ircmsgs.isSplit(m))
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:

View File

@ -47,47 +47,47 @@ class FunctionsTestCase(SupyTestCase):
for msg in msgs: for msg in msgs:
if msg.prefix and ircutils.isUserHostmask(msg.prefix): if msg.prefix and ircutils.isUserHostmask(msg.prefix):
s = msg.prefix s = msg.prefix
self.failUnless(ircutils.hostmaskPatternEqual(s, s), self.assertTrue(ircutils.hostmaskPatternEqual(s, s),
'%r did not match itself.' % s) '%r did not match itself.' % s)
banmask = ircutils.banmask(s) banmask = ircutils.banmask(s)
self.failUnless(ircutils.hostmaskPatternEqual(banmask, s), self.assertTrue(ircutils.hostmaskPatternEqual(banmask, s),
'%r did not match %r' % (s, banmask)) '%r did not match %r' % (s, banmask))
s = 'supybot!~supybot@dhcp065-024-075-056.columbus.rr.com' s = 'supybot!~supybot@dhcp065-024-075-056.columbus.rr.com'
self.failUnless(ircutils.hostmaskPatternEqual(s, s)) self.assertTrue(ircutils.hostmaskPatternEqual(s, s))
s = 'jamessan|work!~jamessan@209-6-166-196.c3-0.' \ s = 'jamessan|work!~jamessan@209-6-166-196.c3-0.' \
'abr-ubr1.sbo-abr.ma.cable.rcn.com' 'abr-ubr1.sbo-abr.ma.cable.rcn.com'
self.failUnless(ircutils.hostmaskPatternEqual(s, s)) self.assertTrue(ircutils.hostmaskPatternEqual(s, s))
def testIsUserHostmask(self): def testIsUserHostmask(self):
self.failUnless(ircutils.isUserHostmask(self.hostmask)) self.assertTrue(ircutils.isUserHostmask(self.hostmask))
self.failUnless(ircutils.isUserHostmask('a!b@c')) self.assertTrue(ircutils.isUserHostmask('a!b@c'))
self.failIf(ircutils.isUserHostmask('!bar@baz')) self.assertFalse(ircutils.isUserHostmask('!bar@baz'))
self.failIf(ircutils.isUserHostmask('!@baz')) self.assertFalse(ircutils.isUserHostmask('!@baz'))
self.failIf(ircutils.isUserHostmask('!bar@')) self.assertFalse(ircutils.isUserHostmask('!bar@'))
self.failIf(ircutils.isUserHostmask('!@')) self.assertFalse(ircutils.isUserHostmask('!@'))
self.failIf(ircutils.isUserHostmask('foo!@baz')) self.assertFalse(ircutils.isUserHostmask('foo!@baz'))
self.failIf(ircutils.isUserHostmask('foo!bar@')) self.assertFalse(ircutils.isUserHostmask('foo!bar@'))
self.failIf(ircutils.isUserHostmask('')) self.assertFalse(ircutils.isUserHostmask(''))
self.failIf(ircutils.isUserHostmask('!')) self.assertFalse(ircutils.isUserHostmask('!'))
self.failIf(ircutils.isUserHostmask('@')) self.assertFalse(ircutils.isUserHostmask('@'))
self.failIf(ircutils.isUserHostmask('!bar@baz')) self.assertFalse(ircutils.isUserHostmask('!bar@baz'))
def testIsChannel(self): def testIsChannel(self):
self.failUnless(ircutils.isChannel('#')) self.assertTrue(ircutils.isChannel('#'))
self.failUnless(ircutils.isChannel('&')) self.assertTrue(ircutils.isChannel('&'))
self.failIf(ircutils.isChannel('+')) self.assertFalse(ircutils.isChannel('+'))
self.failUnless(ircutils.isChannel('+', chantypes='#&+!')) self.assertTrue(ircutils.isChannel('+', chantypes='#&+!'))
self.failUnless(ircutils.isChannel('!')) self.assertTrue(ircutils.isChannel('!'))
self.failUnless(ircutils.isChannel('#foo')) self.assertTrue(ircutils.isChannel('#foo'))
self.failUnless(ircutils.isChannel('&foo')) self.assertTrue(ircutils.isChannel('&foo'))
self.failIf(ircutils.isChannel('+foo')) self.assertFalse(ircutils.isChannel('+foo'))
self.failUnless(ircutils.isChannel('+foo', chantypes='#&+!')) self.assertTrue(ircutils.isChannel('+foo', chantypes='#&+!'))
self.failUnless(ircutils.isChannel('!foo')) self.assertTrue(ircutils.isChannel('!foo'))
self.failIf(ircutils.isChannel('#foo bar')) self.assertFalse(ircutils.isChannel('#foo bar'))
self.failIf(ircutils.isChannel('#foo,bar')) self.assertFalse(ircutils.isChannel('#foo,bar'))
self.failIf(ircutils.isChannel('#foobar\x07')) self.assertFalse(ircutils.isChannel('#foobar\x07'))
self.failIf(ircutils.isChannel('foo')) self.assertFalse(ircutils.isChannel('foo'))
self.failIf(ircutils.isChannel('')) self.assertFalse(ircutils.isChannel(''))
def testBold(self): def testBold(self):
s = ircutils.bold('foo') s = ircutils.bold('foo')
@ -249,22 +249,22 @@ class FunctionsTestCase(SupyTestCase):
try: try:
original = conf.supybot.protocols.irc.strictRfc() original = conf.supybot.protocols.irc.strictRfc()
conf.supybot.protocols.irc.strictRfc.setValue(True) conf.supybot.protocols.irc.strictRfc.setValue(True)
self.failUnless(ircutils.isNick('jemfinch')) self.assertTrue(ircutils.isNick('jemfinch'))
self.failUnless(ircutils.isNick('jemfinch0')) self.assertTrue(ircutils.isNick('jemfinch0'))
self.failUnless(ircutils.isNick('[0]')) self.assertTrue(ircutils.isNick('[0]'))
self.failUnless(ircutils.isNick('{jemfinch}')) self.assertTrue(ircutils.isNick('{jemfinch}'))
self.failUnless(ircutils.isNick('[jemfinch]')) self.assertTrue(ircutils.isNick('[jemfinch]'))
self.failUnless(ircutils.isNick('jem|finch')) self.assertTrue(ircutils.isNick('jem|finch'))
self.failUnless(ircutils.isNick('\\```')) self.assertTrue(ircutils.isNick('\\```'))
self.failUnless(ircutils.isNick('`')) self.assertTrue(ircutils.isNick('`'))
self.failUnless(ircutils.isNick('A')) self.assertTrue(ircutils.isNick('A'))
self.failIf(ircutils.isNick('')) self.assertFalse(ircutils.isNick(''))
self.failIf(ircutils.isNick('8foo')) self.assertFalse(ircutils.isNick('8foo'))
self.failIf(ircutils.isNick('10')) self.assertFalse(ircutils.isNick('10'))
self.failIf(ircutils.isNick('-')) self.assertFalse(ircutils.isNick('-'))
self.failIf(ircutils.isNick('-foo')) self.assertFalse(ircutils.isNick('-foo'))
conf.supybot.protocols.irc.strictRfc.setValue(False) conf.supybot.protocols.irc.strictRfc.setValue(False)
self.failUnless(ircutils.isNick('services@something.undernet.net')) self.assertTrue(ircutils.isNick('services@something.undernet.net'))
finally: finally:
conf.supybot.protocols.irc.strictRfc.setValue(original) conf.supybot.protocols.irc.strictRfc.setValue(original)
@ -272,9 +272,9 @@ class FunctionsTestCase(SupyTestCase):
try: try:
original = conf.supybot.protocols.irc.strictRfc() original = conf.supybot.protocols.irc.strictRfc()
conf.supybot.protocols.irc.strictRfc.setValue(True) conf.supybot.protocols.irc.strictRfc.setValue(True)
self.failIf(ircutils.isNick('foo bar')) self.assertFalse(ircutils.isNick('foo bar'))
conf.supybot.protocols.irc.strictRfc.setValue(False) conf.supybot.protocols.irc.strictRfc.setValue(False)
self.failIf(ircutils.isNick('foo bar')) self.assertFalse(ircutils.isNick('foo bar'))
finally: finally:
conf.supybot.protocols.irc.strictRfc.setValue(original) conf.supybot.protocols.irc.strictRfc.setValue(original)
@ -306,7 +306,7 @@ class FunctionsTestCase(SupyTestCase):
for msg in msgs: for msg in msgs:
if ircutils.isUserHostmask(msg.prefix): if ircutils.isUserHostmask(msg.prefix):
banmask = ircutils.banmask(msg.prefix) banmask = ircutils.banmask(msg.prefix)
self.failUnless(ircutils.hostmaskPatternEqual(banmask, self.assertTrue(ircutils.hostmaskPatternEqual(banmask,
msg.prefix), msg.prefix),
'%r didn\'t match %r' % (msg.prefix, banmask)) '%r didn\'t match %r' % (msg.prefix, banmask))
self.assertEqual(ircutils.banmask('foobar!user@host'), '*!*@host') self.assertEqual(ircutils.banmask('foobar!user@host'), '*!*@host')
@ -402,9 +402,9 @@ class IrcDictTestCase(SupyTestCase):
def testContains(self): def testContains(self):
d = ircutils.IrcDict() d = ircutils.IrcDict()
d['#FOO'] = None d['#FOO'] = None
self.failUnless('#foo' in d) self.assertTrue('#foo' in d)
d['#fOOBAR[]'] = None d['#fOOBAR[]'] = None
self.failUnless('#foobar{}' in d) self.assertTrue('#foobar{}' in d)
def testGetSetItem(self): def testGetSetItem(self):
d = ircutils.IrcDict() d = ircutils.IrcDict()
@ -416,8 +416,8 @@ class IrcDictTestCase(SupyTestCase):
def testCopyable(self): def testCopyable(self):
d = ircutils.IrcDict() d = ircutils.IrcDict()
d['foo'] = 'bar' d['foo'] = 'bar'
self.failUnless(d == copy.copy(d)) self.assertTrue(d == copy.copy(d))
self.failUnless(d == copy.deepcopy(d)) self.assertTrue(d == copy.deepcopy(d))
class IrcSetTestCase(SupyTestCase): class IrcSetTestCase(SupyTestCase):
@ -425,30 +425,30 @@ class IrcSetTestCase(SupyTestCase):
s = ircutils.IrcSet() s = ircutils.IrcSet()
s.add('foo') s.add('foo')
s.add('bar') s.add('bar')
self.failUnless('foo' in s) self.assertTrue('foo' in s)
self.failUnless('FOO' in s) self.assertTrue('FOO' in s)
s.discard('alfkj') s.discard('alfkj')
s.remove('FOo') s.remove('FOo')
self.failIf('foo' in s) self.assertFalse('foo' in s)
self.failIf('FOo' in s) self.assertFalse('FOo' in s)
def testCopy(self): def testCopy(self):
s = ircutils.IrcSet() s = ircutils.IrcSet()
s.add('foo') s.add('foo')
s.add('bar') s.add('bar')
s1 = copy.deepcopy(s) s1 = copy.deepcopy(s)
self.failUnless('foo' in s) self.assertTrue('foo' in s)
self.failUnless('FOO' in s) self.assertTrue('FOO' in s)
s.discard('alfkj') s.discard('alfkj')
s.remove('FOo') s.remove('FOo')
self.failIf('foo' in s) self.assertFalse('foo' in s)
self.failIf('FOo' in s) self.assertFalse('FOo' in s)
self.failUnless('foo' in s1) self.assertTrue('foo' in s1)
self.failUnless('FOO' in s1) self.assertTrue('FOO' in s1)
s1.discard('alfkj') s1.discard('alfkj')
s1.remove('FOo') s1.remove('FOo')
self.failIf('foo' in s1) self.assertFalse('foo' in s1)
self.failIf('FOo' in s1) self.assertFalse('FOo' in s1)
class IrcStringTestCase(SupyTestCase): class IrcStringTestCase(SupyTestCase):
@ -463,8 +463,8 @@ class IrcStringTestCase(SupyTestCase):
def testInequality(self): def testInequality(self):
s1 = 'supybot' s1 = 'supybot'
s2 = ircutils.IrcString('Supybot') s2 = ircutils.IrcString('Supybot')
self.failUnless(s1 == s2) self.assertTrue(s1 == s2)
self.failIf(s1 != s2) self.assertFalse(s1 != s2)
class AuthenticateTestCase(SupyTestCase): class AuthenticateTestCase(SupyTestCase):
PAIRS = [ PAIRS = [

View File

@ -34,10 +34,10 @@ import supybot.plugin as plugin
class FunctionsTestCase(SupyTestCase): class FunctionsTestCase(SupyTestCase):
def testLoadPluginModule(self): def testLoadPluginModule(self):
self.assertRaises(ImportError, plugin.loadPluginModule, 'asldj') self.assertRaises(ImportError, plugin.loadPluginModule, 'asldj')
self.failUnless(plugin.loadPluginModule('Owner')) self.assertTrue(plugin.loadPluginModule('Owner'))
# I haven't yet figured out a way to get case-insensitivity back for # I haven't yet figured out a way to get case-insensitivity back for
# "directoried" plugins. # "directoried" plugins.
#self.failUnless(plugin.loadPluginModule('owner')) #self.assertTrue(plugin.loadPluginModule('owner'))
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:

View File

@ -74,25 +74,25 @@ class FunctionsTestCase(SupyTestCase):
class ValuesTestCase(SupyTestCase): class ValuesTestCase(SupyTestCase):
def testBoolean(self): def testBoolean(self):
v = registry.Boolean(True, """Help""") v = registry.Boolean(True, """Help""")
self.failUnless(v()) self.assertTrue(v())
v.setValue(False) v.setValue(False)
self.failIf(v()) self.assertFalse(v())
v.set('True') v.set('True')
self.failUnless(v()) self.assertTrue(v())
v.set('False') v.set('False')
self.failIf(v()) self.assertFalse(v())
v.set('On') v.set('On')
self.failUnless(v()) self.assertTrue(v())
v.set('Off') v.set('Off')
self.failIf(v()) self.assertFalse(v())
v.set('enable') v.set('enable')
self.failUnless(v()) self.assertTrue(v())
v.set('disable') v.set('disable')
self.failIf(v()) self.assertFalse(v())
v.set('toggle') v.set('toggle')
self.failUnless(v()) self.assertTrue(v())
v.set('toggle') v.set('toggle')
self.failIf(v()) self.assertFalse(v())
def testInteger(self): def testInteger(self):
v = registry.Integer(1, 'help') v = registry.Integer(1, 'help')
@ -179,7 +179,7 @@ class ValuesTestCase(SupyTestCase):
v = registry.Regexp(None, 'help') v = registry.Regexp(None, 'help')
self.assertEqual(v(), None) self.assertEqual(v(), None)
v.set('m/foo/') v.set('m/foo/')
self.failUnless(v().match('foo')) self.assertTrue(v().match('foo'))
v.set('') v.set('')
self.assertEqual(v(), None) self.assertEqual(v(), None)
self.assertRaises(registry.InvalidRegistryValue, self.assertRaises(registry.InvalidRegistryValue,

View File

@ -73,12 +73,12 @@ class FunctionsTestCase(SupyTestCase):
self.assertNotEqual(f(irc, msg, '$today'), '$today') self.assertNotEqual(f(irc, msg, '$today'), '$today')
self.assertNotEqual(f(irc, msg, '$now'), '$now') self.assertNotEqual(f(irc, msg, '$now'), '$now')
n = f(irc, msg, '$randnick') n = f(irc, msg, '$randnick')
self.failUnless(n in irc.state.channels['#foo'].users) self.assertTrue(n in irc.state.channels['#foo'].users)
n = f(irc, msg, '$randomnick') n = f(irc, msg, '$randomnick')
self.failUnless(n in irc.state.channels['#foo'].users) self.assertTrue(n in irc.state.channels['#foo'].users)
n = f(irc, msg, '$randomnick '*100) n = f(irc, msg, '$randomnick '*100)
L = n.split() L = n.split()
self.failIf(all(L[0].__eq__, L), 'all $randomnicks were the same') self.assertFalse(all(L[0].__eq__, L), 'all $randomnicks were the same')
c = f(irc, msg, '$channel') c = f(irc, msg, '$channel')
self.assertEqual(c, msg.args[0]) self.assertEqual(c, msg.args[0])

View File

@ -76,7 +76,7 @@ class GenTest(SupyTestCase):
def testInsensitivePreservingDict(self): def testInsensitivePreservingDict(self):
ipd = utils.InsensitivePreservingDict ipd = utils.InsensitivePreservingDict
d = ipd(dict(Foo=10)) d = ipd(dict(Foo=10))
self.failUnless(d['foo'] == 10) self.assertTrue(d['foo'] == 10)
self.assertEqual(d.keys(), ['Foo']) self.assertEqual(d.keys(), ['Foo'])
self.assertEqual(d.get('foo'), 10) self.assertEqual(d.get('foo'), 10)
self.assertEqual(d.get('Foo'), 10) self.assertEqual(d.get('Foo'), 10)
@ -84,7 +84,7 @@ class GenTest(SupyTestCase):
def testFindBinaryInPath(self): def testFindBinaryInPath(self):
if os.name == 'posix': if os.name == 'posix':
self.assertEqual(None, utils.findBinaryInPath('asdfhjklasdfhjkl')) self.assertEqual(None, utils.findBinaryInPath('asdfhjklasdfhjkl'))
self.failUnless(utils.findBinaryInPath('sh').endswith('/bin/sh')) self.assertTrue(utils.findBinaryInPath('sh').endswith('/bin/sh'))
def testExnToString(self): def testExnToString(self):
try: try:
@ -124,11 +124,11 @@ class GenTest(SupyTestCase):
for (k, v) in self.L: for (k, v) in self.L:
yield (k, v) yield (k, v)
AL = alist() AL = alist()
self.failIf(AL) self.assertFalse(AL)
AL[1] = 2 AL[1] = 2
AL[2] = 3 AL[2] = 3
AL[3] = 4 AL[3] = 4
self.failUnless(AL) self.assertTrue(AL)
self.assertEqual(list(AL.items()), [(1, 2), (2, 3), (3, 4)]) self.assertEqual(list(AL.items()), [(1, 2), (2, 3), (3, 4)])
self.assertEqual(list(AL.items()), [(1, 2), (2, 3), (3, 4)]) self.assertEqual(list(AL.items()), [(1, 2), (2, 3), (3, 4)])
self.assertEqual(list(AL.keys()), [1, 2, 3]) self.assertEqual(list(AL.keys()), [1, 2, 3])
@ -271,25 +271,25 @@ class StrTest(SupyTestCase):
for s in L: for s in L:
r = utils.str.dqrepr(s) r = utils.str.dqrepr(s)
self.assertEqual(s, eval(r), s) self.assertEqual(s, eval(r), s)
self.failUnless(r[0] == '"' and r[-1] == '"', s) self.assertTrue(r[0] == '"' and r[-1] == '"', s)
def testPerlReToPythonRe(self): def testPerlReToPythonRe(self):
f = utils.str.perlReToPythonRe f = utils.str.perlReToPythonRe
r = f('m/foo/') r = f('m/foo/')
self.failUnless(r.search('foo')) self.assertTrue(r.search('foo'))
r = f('/foo/') r = f('/foo/')
self.failUnless(r.search('foo')) self.assertTrue(r.search('foo'))
r = f('m/\\//') r = f('m/\\//')
self.failUnless(r.search('/')) self.assertTrue(r.search('/'))
r = f('m/cat/i') r = f('m/cat/i')
self.failUnless(r.search('CAT')) self.assertTrue(r.search('CAT'))
self.assertRaises(ValueError, f, 'm/?/') self.assertRaises(ValueError, f, 'm/?/')
def testP2PReDifferentSeparator(self): def testP2PReDifferentSeparator(self):
r = utils.str.perlReToPythonRe('m!foo!') r = utils.str.perlReToPythonRe('m!foo!')
self.failUnless(r.search('foo')) self.assertTrue(r.search('foo'))
r = utils.str.perlReToPythonRe('m{cat}') r = utils.str.perlReToPythonRe('m{cat}')
self.failUnless(r.search('cat')) self.assertTrue(r.search('cat'))
def testPerlReToReplacer(self): def testPerlReToReplacer(self):
PRTR = utils.str.perlReToReplacer PRTR = utils.str.perlReToReplacer
@ -350,7 +350,7 @@ class StrTest(SupyTestCase):
self.assertEqual(f(L, comma=';', And='or'), self.assertEqual(f(L, comma=';', And='or'),
'foo; bar; or baz') 'foo; bar; or baz')
self.assertEqual(L, original) self.assertEqual(L, original)
self.failUnless(f(set(L))) self.assertTrue(f(set(L)))
def testCommaAndifyRaisesTypeError(self): def testCommaAndifyRaisesTypeError(self):
L = [(2,)] L = [(2,)]
@ -401,8 +401,8 @@ class StrTest(SupyTestCase):
def testEllipsisify(self): def testEllipsisify(self):
f = utils.str.ellipsisify f = utils.str.ellipsisify
self.assertEqual(f('x'*30, 30), 'x'*30) self.assertEqual(f('x'*30, 30), 'x'*30)
self.failUnless(len(f('x'*35, 30)) <= 30) self.assertTrue(len(f('x'*35, 30)) <= 30)
self.failUnless(f(' '.join(['xxxx']*10), 30)[:-3].endswith('xxxx')) self.assertTrue(f(' '.join(['xxxx']*10), 30)[:-3].endswith('xxxx'))
class IterTest(SupyTestCase): class IterTest(SupyTestCase):
@ -443,18 +443,18 @@ class IterTest(SupyTestCase):
def testAny(self): def testAny(self):
any = utils.iter.any any = utils.iter.any
self.failUnless(any(lambda i: i == 0, range(10))) self.assertTrue(any(lambda i: i == 0, range(10)))
self.failIf(any(None, range(1))) self.assertFalse(any(None, range(1)))
self.failUnless(any(None, range(2))) self.assertTrue(any(None, range(2)))
self.failIf(any(None, [])) self.assertFalse(any(None, []))
def testAll(self): def testAll(self):
all = utils.iter.all all = utils.iter.all
self.failIf(all(lambda i: i == 0, range(10))) self.assertFalse(all(lambda i: i == 0, range(10)))
self.failIf(all(lambda i: i % 2, range(2))) self.assertFalse(all(lambda i: i % 2, range(2)))
self.failIf(all(lambda i: i % 2 == 0, [1, 3, 5])) self.assertFalse(all(lambda i: i % 2 == 0, [1, 3, 5]))
self.failUnless(all(lambda i: i % 2 == 0, [2, 4, 6])) self.assertTrue(all(lambda i: i % 2 == 0, [2, 4, 6]))
self.failUnless(all(None, ())) self.assertTrue(all(None, ()))
def testPartition(self): def testPartition(self):
partition = utils.iter.partition partition = utils.iter.partition
@ -513,9 +513,9 @@ class FileTest(SupyTestCase):
def testMktemp(self): def testMktemp(self):
# This is mostly to test that it actually halts. # This is mostly to test that it actually halts.
self.failUnless(utils.file.mktemp()) self.assertTrue(utils.file.mktemp())
self.failUnless(utils.file.mktemp()) self.assertTrue(utils.file.mktemp())
self.failUnless(utils.file.mktemp()) self.assertTrue(utils.file.mktemp())
def testSanitizeName(self): def testSanitizeName(self):
self.assertEqual(utils.file.sanitizeName('#foo'), '#foo') self.assertEqual(utils.file.sanitizeName('#foo'), '#foo')
@ -525,22 +525,22 @@ class FileTest(SupyTestCase):
class NetTest(SupyTestCase): class NetTest(SupyTestCase):
def testEmailRe(self): def testEmailRe(self):
emailRe = utils.net.emailRe emailRe = utils.net.emailRe
self.failUnless(emailRe.match('jemfinch@supybot.com')) self.assertTrue(emailRe.match('jemfinch@supybot.com'))
def testIsIP(self): def testIsIP(self):
isIP = utils.net.isIP isIP = utils.net.isIP
self.failIf(isIP('a.b.c')) self.assertFalse(isIP('a.b.c'))
self.failIf(isIP('256.0.0.0')) self.assertFalse(isIP('256.0.0.0'))
self.failIf(isIP('127.0.0.1 127.0.0.1')) self.assertFalse(isIP('127.0.0.1 127.0.0.1'))
self.failUnless(isIP('0.0.0.0')) self.assertTrue(isIP('0.0.0.0'))
self.failUnless(isIP('100.100.100.100')) self.assertTrue(isIP('100.100.100.100'))
self.failUnless(isIP('255.255.255.255')) self.assertTrue(isIP('255.255.255.255'))
def testIsIPV6(self): def testIsIPV6(self):
f = utils.net.isIPV6 f = utils.net.isIPV6
self.failIf(f('2001:: 2001::')) self.assertFalse(f('2001:: 2001::'))
self.failUnless(f('2001::')) self.assertTrue(f('2001::'))
self.failUnless(f('2001:888:0:1::666')) self.assertTrue(f('2001:888:0:1::666'))
class WebTest(SupyTestCase): class WebTest(SupyTestCase):
def testGetDomain(self): def testGetDomain(self):
@ -550,7 +550,7 @@ class WebTest(SupyTestCase):
if network: if network:
def testGetUrlWithSize(self): def testGetUrlWithSize(self):
url = 'http://slashdot.org/' url = 'http://slashdot.org/'
self.failUnless(len(utils.web.getUrl(url, 1024)) == 1024) self.assertTrue(len(utils.web.getUrl(url, 1024)) == 1024)
class FormatTestCase(SupyTestCase): class FormatTestCase(SupyTestCase):
def testNormal(self): def testNormal(self):
@ -594,9 +594,9 @@ class RingBufferTestCase(SupyTestCase):
def testNonzero(self): def testNonzero(self):
b = RingBuffer(3) b = RingBuffer(3)
self.failIf(b) self.assertFalse(b)
b.append(1) b.append(1)
self.failUnless(b) self.assertTrue(b)
def testAppend(self): def testAppend(self):
b = RingBuffer(3) b = RingBuffer(3)
@ -616,10 +616,10 @@ class RingBufferTestCase(SupyTestCase):
def testContains(self): def testContains(self):
b = RingBuffer(3, range(3)) b = RingBuffer(3, range(3))
self.failUnless(0 in b) self.assertTrue(0 in b)
self.failUnless(1 in b) self.assertTrue(1 in b)
self.failUnless(2 in b) self.assertTrue(2 in b)
self.failIf(3 in b) self.assertFalse(3 in b)
def testGetitem(self): def testGetitem(self):
L = range(10) L = range(10)
@ -674,11 +674,11 @@ class RingBufferTestCase(SupyTestCase):
b = RingBuffer(len(L), [0]*len(L)) b = RingBuffer(len(L), [0]*len(L))
self.assertRaises(ValueError, b.__setitem__, slice(0, 10), []) self.assertRaises(ValueError, b.__setitem__, slice(0, 10), [])
b[2:4] = L[2:4] b[2:4] = L[2:4]
self.assertEquals(b[2:4], L[2:4]) self.assertEqual(b[2:4], L[2:4])
for _ in range(len(b)): for _ in range(len(b)):
b.append(0) b.append(0)
b[2:4] = L[2:4] b[2:4] = L[2:4]
self.assertEquals(b[2:4], L[2:4]) self.assertEqual(b[2:4], L[2:4])
def testExtend(self): def testExtend(self):
b = RingBuffer(3, range(3)) b = RingBuffer(3, range(3))
@ -708,18 +708,18 @@ class RingBufferTestCase(SupyTestCase):
def testEq(self): def testEq(self):
b = RingBuffer(3, range(3)) b = RingBuffer(3, range(3))
self.failIf(b == list(range(3))) self.assertFalse(b == list(range(3)))
b1 = RingBuffer(3) b1 = RingBuffer(3)
self.failIf(b == b1) self.assertFalse(b == b1)
b1.append(0) b1.append(0)
self.failIf(b == b1) self.assertFalse(b == b1)
b1.append(1) b1.append(1)
self.failIf(b == b1) self.assertFalse(b == b1)
b1.append(2) b1.append(2)
self.failUnless(b == b1) self.assertTrue(b == b1)
b = RingBuffer(100, range(10)) b = RingBuffer(100, range(10))
b1 = RingBuffer(10, range(10)) b1 = RingBuffer(10, range(10))
self.failIf(b == b1) self.assertFalse(b == b1)
def testIter(self): def testIter(self):
b = RingBuffer(3, range(3)) b = RingBuffer(3, range(3))
@ -771,11 +771,11 @@ class QueueTest(SupyTestCase):
def testNonzero(self): def testNonzero(self):
q = queue() q = queue()
self.failIf(q, 'queue not zero after initialization') self.assertFalse(q, 'queue not zero after initialization')
q.enqueue(1) q.enqueue(1)
self.failUnless(q, 'queue zero after adding element') self.assertTrue(q, 'queue zero after adding element')
q.dequeue() q.dequeue()
self.failIf(q, 'queue not zero after dequeue of only element') self.assertFalse(q, 'queue not zero after dequeue of only element')
def testLen(self): def testLen(self):
q = queue() q = queue()
@ -796,24 +796,24 @@ class QueueTest(SupyTestCase):
def testEq(self): def testEq(self):
q1 = queue() q1 = queue()
q2 = queue() q2 = queue()
self.failUnless(q1 == q1, 'queue not equal to itself') self.assertTrue(q1 == q1, 'queue not equal to itself')
self.failUnless(q2 == q2, 'queue not equal to itself') self.assertTrue(q2 == q2, 'queue not equal to itself')
self.failUnless(q1 == q2, 'initialized queues not equal') self.assertTrue(q1 == q2, 'initialized queues not equal')
q1.enqueue(1) q1.enqueue(1)
self.failUnless(q1 == q1, 'queue not equal to itself') self.assertTrue(q1 == q1, 'queue not equal to itself')
self.failUnless(q2 == q2, 'queue not equal to itself') self.assertTrue(q2 == q2, 'queue not equal to itself')
q2.enqueue(1) q2.enqueue(1)
self.failUnless(q1 == q1, 'queue not equal to itself') self.assertTrue(q1 == q1, 'queue not equal to itself')
self.failUnless(q2 == q2, 'queue not equal to itself') self.assertTrue(q2 == q2, 'queue not equal to itself')
self.failUnless(q1 == q2, 'queues not equal after identical enqueue') self.assertTrue(q1 == q2, 'queues not equal after identical enqueue')
q1.dequeue() q1.dequeue()
self.failUnless(q1 == q1, 'queue not equal to itself') self.assertTrue(q1 == q1, 'queue not equal to itself')
self.failUnless(q2 == q2, 'queue not equal to itself') self.assertTrue(q2 == q2, 'queue not equal to itself')
self.failIf(q1 == q2, 'queues equal after one dequeue') self.assertFalse(q1 == q2, 'queues equal after one dequeue')
q2.dequeue() q2.dequeue()
self.failUnless(q1 == q2, 'queues not equal after both are dequeued') self.assertTrue(q1 == q2, 'queues not equal after both are dequeued')
self.failUnless(q1 == q1, 'queue not equal to itself') self.assertTrue(q1 == q1, 'queue not equal to itself')
self.failUnless(q2 == q2, 'queue not equal to itself') self.assertTrue(q2 == q2, 'queue not equal to itself')
def testInit(self): def testInit(self):
self.assertEqual(len(queue()), 0, 'queue len not 0 after init') self.assertEqual(len(queue()), 0, 'queue len not 0 after init')
@ -873,17 +873,17 @@ class QueueTest(SupyTestCase):
def testContains(self): def testContains(self):
q = queue() q = queue()
self.failIf(1 in q, 'empty queue cannot have elements') self.assertFalse(1 in q, 'empty queue cannot have elements')
q.enqueue(1) q.enqueue(1)
self.failUnless(1 in q, 'recent enqueued element not in q') self.assertTrue(1 in q, 'recent enqueued element not in q')
q.enqueue(2) q.enqueue(2)
self.failUnless(1 in q, 'original enqueued element not in q') self.assertTrue(1 in q, 'original enqueued element not in q')
self.failUnless(2 in q, 'second enqueued element not in q') self.assertTrue(2 in q, 'second enqueued element not in q')
q.dequeue() q.dequeue()
self.failIf(1 in q, 'dequeued element in q') self.assertFalse(1 in q, 'dequeued element in q')
self.failUnless(2 in q, 'not dequeued element not in q') self.assertTrue(2 in q, 'not dequeued element not in q')
q.dequeue() q.dequeue()
self.failIf(2 in q, 'dequeued element in q') self.assertFalse(2 in q, 'dequeued element in q')
def testIter(self): def testIter(self):
q1 = queue((1, 2, 3)) q1 = queue((1, 2, 3))
@ -936,11 +936,11 @@ class SmallQueueTest(SupyTestCase):
def testNonzero(self): def testNonzero(self):
q = queue() q = queue()
self.failIf(q, 'queue not zero after initialization') self.assertFalse(q, 'queue not zero after initialization')
q.enqueue(1) q.enqueue(1)
self.failUnless(q, 'queue zero after adding element') self.assertTrue(q, 'queue zero after adding element')
q.dequeue() q.dequeue()
self.failIf(q, 'queue not zero after dequeue of only element') self.assertFalse(q, 'queue not zero after dequeue of only element')
def testLen(self): def testLen(self):
q = queue() q = queue()
@ -961,24 +961,24 @@ class SmallQueueTest(SupyTestCase):
def testEq(self): def testEq(self):
q1 = queue() q1 = queue()
q2 = queue() q2 = queue()
self.failUnless(q1 == q1, 'queue not equal to itself') self.assertTrue(q1 == q1, 'queue not equal to itself')
self.failUnless(q2 == q2, 'queue not equal to itself') self.assertTrue(q2 == q2, 'queue not equal to itself')
self.failUnless(q1 == q2, 'initialized queues not equal') self.assertTrue(q1 == q2, 'initialized queues not equal')
q1.enqueue(1) q1.enqueue(1)
self.failUnless(q1 == q1, 'queue not equal to itself') self.assertTrue(q1 == q1, 'queue not equal to itself')
self.failUnless(q2 == q2, 'queue not equal to itself') self.assertTrue(q2 == q2, 'queue not equal to itself')
q2.enqueue(1) q2.enqueue(1)
self.failUnless(q1 == q1, 'queue not equal to itself') self.assertTrue(q1 == q1, 'queue not equal to itself')
self.failUnless(q2 == q2, 'queue not equal to itself') self.assertTrue(q2 == q2, 'queue not equal to itself')
self.failUnless(q1 == q2, 'queues not equal after identical enqueue') self.assertTrue(q1 == q2, 'queues not equal after identical enqueue')
q1.dequeue() q1.dequeue()
self.failUnless(q1 == q1, 'queue not equal to itself') self.assertTrue(q1 == q1, 'queue not equal to itself')
self.failUnless(q2 == q2, 'queue not equal to itself') self.assertTrue(q2 == q2, 'queue not equal to itself')
self.failIf(q1 == q2, 'queues equal after one dequeue') self.assertFalse(q1 == q2, 'queues equal after one dequeue')
q2.dequeue() q2.dequeue()
self.failUnless(q1 == q2, 'queues not equal after both are dequeued') self.assertTrue(q1 == q2, 'queues not equal after both are dequeued')
self.failUnless(q1 == q1, 'queue not equal to itself') self.assertTrue(q1 == q1, 'queue not equal to itself')
self.failUnless(q2 == q2, 'queue not equal to itself') self.assertTrue(q2 == q2, 'queue not equal to itself')
def testInit(self): def testInit(self):
self.assertEqual(len(queue()), 0, 'queue len not 0 after init') self.assertEqual(len(queue()), 0, 'queue len not 0 after init')
@ -1038,17 +1038,17 @@ class SmallQueueTest(SupyTestCase):
def testContains(self): def testContains(self):
q = queue() q = queue()
self.failIf(1 in q, 'empty queue cannot have elements') self.assertFalse(1 in q, 'empty queue cannot have elements')
q.enqueue(1) q.enqueue(1)
self.failUnless(1 in q, 'recent enqueued element not in q') self.assertTrue(1 in q, 'recent enqueued element not in q')
q.enqueue(2) q.enqueue(2)
self.failUnless(1 in q, 'original enqueued element not in q') self.assertTrue(1 in q, 'original enqueued element not in q')
self.failUnless(2 in q, 'second enqueued element not in q') self.assertTrue(2 in q, 'second enqueued element not in q')
q.dequeue() q.dequeue()
self.failIf(1 in q, 'dequeued element in q') self.assertFalse(1 in q, 'dequeued element in q')
self.failUnless(2 in q, 'not dequeued element not in q') self.assertTrue(2 in q, 'not dequeued element not in q')
q.dequeue() q.dequeue()
self.failIf(2 in q, 'dequeued element in q') self.assertFalse(2 in q, 'dequeued element in q')
def testIter(self): def testIter(self):
q1 = queue((1, 2, 3)) q1 = queue((1, 2, 3))
@ -1089,28 +1089,28 @@ class MaxLengthQueueTestCase(SupyTestCase):
class TwoWayDictionaryTestCase(SupyTestCase): class TwoWayDictionaryTestCase(SupyTestCase):
def testInit(self): def testInit(self):
d = TwoWayDictionary(foo='bar') d = TwoWayDictionary(foo='bar')
self.failUnless('foo' in d) self.assertTrue('foo' in d)
self.failUnless('bar' in d) self.assertTrue('bar' in d)
d = TwoWayDictionary({1: 2}) d = TwoWayDictionary({1: 2})
self.failUnless(1 in d) self.assertTrue(1 in d)
self.failUnless(2 in d) self.assertTrue(2 in d)
def testSetitem(self): def testSetitem(self):
d = TwoWayDictionary() d = TwoWayDictionary()
d['foo'] = 'bar' d['foo'] = 'bar'
self.failUnless('foo' in d) self.assertTrue('foo' in d)
self.failUnless('bar' in d) self.assertTrue('bar' in d)
def testDelitem(self): def testDelitem(self):
d = TwoWayDictionary(foo='bar') d = TwoWayDictionary(foo='bar')
del d['foo'] del d['foo']
self.failIf('foo' in d) self.assertFalse('foo' in d)
self.failIf('bar' in d) self.assertFalse('bar' in d)
d = TwoWayDictionary(foo='bar') d = TwoWayDictionary(foo='bar')
del d['bar'] del d['bar']
self.failIf('bar' in d) self.assertFalse('bar' in d)
self.failIf('foo' in d) self.assertFalse('foo' in d)
class TestTimeoutQueue(SupyTestCase): class TestTimeoutQueue(SupyTestCase):
@ -1143,18 +1143,18 @@ class TestTimeoutQueue(SupyTestCase):
def testContains(self): def testContains(self):
q = TimeoutQueue(1) q = TimeoutQueue(1)
q.enqueue(1) q.enqueue(1)
self.failUnless(1 in q) self.assertTrue(1 in q)
self.failUnless(1 in q) # For some reason, the second one might fail. self.assertTrue(1 in q) # For some reason, the second one might fail.
self.failIf(2 in q) self.assertFalse(2 in q)
timeFastForward(1.1) timeFastForward(1.1)
self.failIf(1 in q) self.assertFalse(1 in q)
def testReset(self): def testReset(self):
q = TimeoutQueue(10) q = TimeoutQueue(10)
q.enqueue(1) q.enqueue(1)
self.failUnless(1 in q) self.assertTrue(1 in q)
q.reset() q.reset()
self.failIf(1 in q) self.assertFalse(1 in q)
class TestCacheDict(SupyTestCase): class TestCacheDict(SupyTestCase):
def testMaxNeverExceeded(self): def testMaxNeverExceeded(self):
@ -1162,22 +1162,22 @@ class TestCacheDict(SupyTestCase):
d = CacheDict(10) d = CacheDict(10)
for i in xrange(max**2): for i in xrange(max**2):
d[i] = i d[i] = i
self.failUnless(len(d) <= max) self.assertTrue(len(d) <= max)
self.failUnless(i in d) self.assertTrue(i in d)
self.failUnless(d[i] == i) self.assertTrue(d[i] == i)
class TestTruncatableSet(SupyTestCase): class TestTruncatableSet(SupyTestCase):
def testBasics(self): def testBasics(self):
s = TruncatableSet(['foo', 'bar', 'baz', 'qux']) s = TruncatableSet(['foo', 'bar', 'baz', 'qux'])
self.assertEqual(s, set(['foo', 'bar', 'baz', 'qux'])) self.assertEqual(s, set(['foo', 'bar', 'baz', 'qux']))
self.failUnless('foo' in s) self.assertTrue('foo' in s)
self.failUnless('bar' in s) self.assertTrue('bar' in s)
self.failIf('quux' in s) self.assertFalse('quux' in s)
s.discard('baz') s.discard('baz')
self.failUnless('foo' in s) self.assertTrue('foo' in s)
self.failIf('baz' in s) self.assertFalse('baz' in s)
s.add('quux') s.add('quux')
self.failUnless('quux' in s) self.assertTrue('quux' in s)
def testTruncate(self): def testTruncate(self):
s = TruncatableSet(['foo', 'bar']) s = TruncatableSet(['foo', 'bar'])