mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-02-17 06:00:42 +01:00
Made sure the data directory is pristine before each test. And fixed a typo.
This commit is contained in:
parent
37f88d5e21
commit
22fcd451e8
31
test/test.py
31
test/test.py
@ -106,6 +106,8 @@ class PluginTestCase(unittest.TestCase):
|
|||||||
timeout = 10
|
timeout = 10
|
||||||
plugins = ()
|
plugins = ()
|
||||||
def setUp(self, nick='test'):
|
def setUp(self, nick='test'):
|
||||||
|
for filename in os.listdir(conf.dataDir):
|
||||||
|
os.remove(os.path.join(conf.dataDir, filename))
|
||||||
if not self.plugins:
|
if not self.plugins:
|
||||||
raise ValueError, 'PluginTestCase must have a "plugins" attribute.'
|
raise ValueError, 'PluginTestCase must have a "plugins" attribute.'
|
||||||
self.nick = nick
|
self.nick = nick
|
||||||
@ -113,7 +115,7 @@ class PluginTestCase(unittest.TestCase):
|
|||||||
self.irc = irclib.Irc(nick)
|
self.irc = irclib.Irc(nick)
|
||||||
while self.irc.takeMsg():
|
while self.irc.takeMsg():
|
||||||
pass
|
pass
|
||||||
if isinstance(plugins, str):
|
if isinstance(self.plugins, str):
|
||||||
module = __import__(name)
|
module = __import__(name)
|
||||||
plugin = module.Class()
|
plugin = module.Class()
|
||||||
self.irc.addCallback(plugin)
|
self.irc.addCallback(plugin)
|
||||||
@ -206,6 +208,33 @@ class PluginTestCase(unittest.TestCase):
|
|||||||
for (m, expected) in zip(responses, expectedResponses):
|
for (m, expected) in zip(responses, expectedResponses):
|
||||||
self.assertEqual(m.args[1], expected)
|
self.assertEqual(m.args[1], expected)
|
||||||
|
|
||||||
|
class ChannelPluginTestCase(PluginTestCase):
|
||||||
|
channel = '#test'
|
||||||
|
def _feedMsg(self, query, timeout=None):
|
||||||
|
if timeout is None:
|
||||||
|
timeout = self.timeout
|
||||||
|
if query[0] not in conf.prefixChars:
|
||||||
|
query = conf.prefixChars[0] + query
|
||||||
|
self.irc.feedMsg(ircmsgs.privmsg(self.channel, query,
|
||||||
|
prefix=self.prefix))
|
||||||
|
fed = time.time()
|
||||||
|
response = self.irc.takeMsg()
|
||||||
|
while response is None and time.time() - fed < timeout:
|
||||||
|
drivers.run()
|
||||||
|
response = self.irc.takeMsg()
|
||||||
|
if response is not None:
|
||||||
|
args = list(response.args)
|
||||||
|
# Strip off nick: at beginning of response.
|
||||||
|
args[1] = args[1].split(None, 1)[1]
|
||||||
|
return ircmsgs.privmsg(*args)
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
|
def feedMsg(self, query):
|
||||||
|
"""Just feeds it a message, that's all."""
|
||||||
|
self.irc.feedMsg(ircmsgs.privmsg(self.channel, query,
|
||||||
|
prefix=self.prefix))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
world.testing = True
|
world.testing = True
|
||||||
|
Loading…
x
Reference in New Issue
Block a user