def setUp(self): server["log_config"] = {} ircbot_factory = ircbot.IRCBotFactory(server) ircbot.logger.setLevel("error") self.bot = bot = ircbot.IrcBot() bot.factory = ircbot_factory bot.config = ircbot_factory.config bot.encoding_server = server['encoding'] bot.encoding_channels = {} self.results = [] class FakeModule(object): class TestClass(object): def __init__(innerself, params, loglvl): self.results.append(("__init__", params, loglvl)) def init(innerself, config): self.results.append(("init", config)) self.original_import = __import__ def fake_import(modname, *args, **kwargs): if modname == "testme": return FakeModule return self.original_import(modname, *args, **kwargs) __builtins__["__import__"] = fake_import
def setUp(self): ircbot_factory = ircbot.IRCBotFactory(server) ircbot.logger.setLevel(logging.ERROR) self.bot = bot = ircbot.IrcBot() bot.factory = ircbot_factory bot.server_config = ircbot_factory.config bot.encoding_server = server['encoding'] bot.encoding_channels = {} self.results = [] def load_plugin(plugin, config, params, channel=None): self.results.append((plugin, config, channel)) bot.load_plugin = load_plugin
def init(self, client_plugin=None, server_plugin=None): if client_plugin is not None: (plugin_name, config, channel) = client_plugin self.test_server["channels"] = { channel: { 'plugins': { plugin_name: config } } } if server_plugin is not None: (plugin_name, config) = server_plugin self.test_server["plugins"] = {plugin_name: config} self.test_server["log_config"] = {plugin_name: "ERROR"} ircbot.logger.setLevel(logging.ERROR) ircbot_factory = ircbot.IRCBotFactory(self.test_server) self.bot = ircbot.IrcBot() self.bot.factory = ircbot_factory self.bot.config = self.test_server self.bot.nickname = "TestBot" self.bot.encoding_server = "utf-8" self.bot.encoding_channels = {} if client_plugin is not None: (plugin_name, config, channel) = client_plugin self.bot.load_channel_plugins(channel) if server_plugin is not None: self.bot.load_server_plugins() # configure the dispatcher self.bot.dispatcher.init(self.bot.config) self.answer = [] def g(towhere, msg, _): self.answer.append((towhere, msg.decode("utf8"))) self.bot.msg = g self.disp = self.bot.dispatcher for plugin in self.bot.dispatcher._plugins.keys(): fullname = "%s.%s" % (plugin.__module__, plugin.__class__.__name__) if fullname == plugin_name: self.plugin = plugin break else: raise ValueError("The searched plugin does not exist!")
def setUp(self): ircbot_factory = ircbot.IRCBotFactory(server.copy()) ircbot.logger.setLevel("error") self.bot = bot = ircbot.IrcBot() bot.factory = ircbot_factory bot.config = ircbot_factory.config bot.encoding_server = server['encoding'] bot.encoding_channels = {} bot.command_char = '@' # don't load plugins bot.load_plugin = lambda *a: None # record what is pushed self.pushed = [] bot.dispatcher.push = lambda *a: self.pushed.append(a)
def setUp(self): server = dict( encoding='utf8', host="0.0.0.0", port=6667, nickname="test", channels=defaultdict(lambda: {}), plugins={}, ) ircbot_factory = ircbot.IRCBotFactory(server) ircbot.logger.setLevel(logging.ERROR) self.bot = ircbot.IrcBot() self.bot.factory = ircbot_factory self.bot.config = ircbot_factory.config self.bot.msg = lambda *a:None
host="0.0.0.0", port=6667, nickname="test", channels={"channel": {}}, plugins={}, ) class FakeTransport(object): def write(*a): pass ircbot_factory = ircbot.IRCBotFactory(server) ircbot.logger.setLevel("error") bot = ircbot.IrcBot() bot.factory = ircbot_factory bot.msg = lambda *a: None bot.transport = FakeTransport() MY_NICKNAME = server['nickname'] class EasyDeferredTests(TwistedTestCase): def setUp(self): self.deferred = defer.Deferred() self.timeout = 1 def deferredAssertEqual(self, a, b): def f(_): self.assertEqual(a, b)