Beispiel #1
0
class TestYakrBot(unittest.TestCase):
    def setUp(self):
        #Net queues are the queues going into the bot
        #from the "network"
        #net_write is what you write to when simulating
        #data going into the bot.
        #net_read is what the bot outputs to
        self.net_write = Queue(10)
        self.net_read = Queue(10)
        self.bot = Bot((self.net_read, self.net_write))
        self.bot_process = Thread(target=self.bot.run)
        self.bot_process.start()

    def tearDown(self):
        if self.bot_process.is_alive():
            self.net_write.put(None)
            self.bot_process.join()

    def test_handshake(self):
        nick_line = self.net_read.get(True, .01)
        assert nick_line.startswith("NICK")

        user_line = self.net_read.get(True, .01)
        assert user_line.startswith("USER")

        try:
            data = self.net_read.get(True, .01)
            assert False, "Expected no data, got:" + repr(data)
        except Empty:
            pass

    @skip_handshake
    def test_pingpong(self):
        self.net_write.put("PING 1234")

        response = self.net_read.get(True, .01)
        assert response == "PONG 1234", "Espected 'PONG 1234', got:" + repr(
            response)

    def test_loading(self):
        self.bot.load("TestPlugin")
        assert "TestPlugin" in self.bot.plugin_map
        self.bot.unload("TestPlugin")
        assert "TestPlugin" not in self.bot.plugin_map
        self.bot.cycle("TestPlugin")
        assert "TestPlugin" in self.bot.plugin_map

    @skip_handshake
    def test_ready(self):
        self.bot.load("Plugin1")
        plugin1 = self.bot.plugin_map["Plugin1"]
        self.net_write.put(":server.com 001 Dot :" +
                           "Welcome to the TestIrc Network Dot!Dot@localhost")
        msg = plugin1.write_queue.get()
        assert msg == "::STATE:READY", "expected ::STATE:READY, got: " + msg
        plugin1.write_queue.get()

        self.bot.load("Plugin2")
        msg = self.bot.plugin_map["Plugin2"].write_queue.get()
        assert msg == "::STATE:READY", "expected ::STATE:READY, got: " + msg
Beispiel #2
0
class TestYakrBot(unittest.TestCase):
    def setUp(self):
        #Net queues are the queues going into the bot
        #from the "network"
        #net_write is what you write to when simulating
        #data going into the bot.
        #net_read is what the bot outputs to
        self.net_write = Queue(10)
        self.net_read = Queue(10)
        self.bot = Bot((self.net_read, self.net_write))
        self.bot_process = Thread(target =self.bot.run)
        self.bot_process.start()

    def tearDown(self):
        if self.bot_process.is_alive():
            self.net_write.put(None)
            self.bot_process.join()

    def test_handshake(self):
        nick_line = self.net_read.get(True, .01)  
        assert nick_line.startswith("NICK")

        user_line = self.net_read.get(True, .01)  
        assert user_line.startswith("USER")

        try:
            data = self.net_read.get(True, .01)
            assert False, "Expected no data, got:" + repr(data)
        except Empty:
            pass

    @skip_handshake
    def test_pingpong(self):
        self.net_write.put("PING 1234")
        
        response = self.net_read.get(True, .01)
        assert response == "PONG 1234", "Espected 'PONG 1234', got:" + repr(response)
   
    def test_loading(self):
        self.bot.load("TestPlugin")
        assert "TestPlugin" in self.bot.plugin_map
        self.bot.unload("TestPlugin")
        assert "TestPlugin" not in self.bot.plugin_map
        self.bot.cycle("TestPlugin")
        assert "TestPlugin" in self.bot.plugin_map

    @skip_handshake
    def test_ready(self):
        self.bot.load("Plugin1")
        plugin1 = self.bot.plugin_map["Plugin1"]
        self.net_write.put(":server.com 001 Dot :"
            + "Welcome to the TestIrc Network Dot!Dot@localhost")
        msg = plugin1.write_queue.get()
        assert msg == "::STATE:READY", "expected ::STATE:READY, got: "+msg
        plugin1.write_queue.get()

        self.bot.load("Plugin2")
        msg = self.bot.plugin_map["Plugin2"].write_queue.get()
        assert msg == "::STATE:READY", "expected ::STATE:READY, got: "+msg
Beispiel #3
0
 def setUp(self):
     #Net queues are the queues going into the bot
     #from the "network"
     #net_write is what you write to when simulating
     #data going into the bot.
     #net_read is what the bot outputs to
     self.net_write = Queue(10)
     self.net_read = Queue(10)
     self.bot = Bot((self.net_read, self.net_write))
     self.bot_process = Thread(target=self.bot.run)
     self.bot_process.start()
Beispiel #4
0
 def setUp(self):
     #Net queues are the queues going into the bot
     #from the "network"
     #net_write is what you write to when simulating
     #data going into the bot.
     #net_read is what the bot outputs to
     self.net_write = Queue(10)
     self.net_read = Queue(10)
     self.bot = Bot((self.net_read, self.net_write))
     self.bot_process = Thread(target =self.bot.run)
     self.bot_process.start()
Beispiel #5
0
    if sys.argv[1] == "record":
        conn = simple_connect((connect_host, connect_port))
        net = record(conn, "RECORD")
    if sys.argv[1] == "replay":
        net = replay("RECORD")
    if sys.argv[1] == "test":
        import unittest
        result = unittest.TextTestRunner(verbosity=2).run(unittest.defaultTestLoader.discover('tests'))
        exit_code = 0
        if result.failures:
            exit_code += 1
        if result.errors:
            exit_code += 2
        exit(exit_code)
    if sys.argv[1] == "plugin":
        import yakr.plugin_maker
        yakr.plugin_maker.interactive()
        exit(0)
else:
    net = simple_connect((connect_host, connect_port))

b = Bot(net)
b.nick = nick
b.real_name = name
map(b.load, plugins)
try:
    b.run()
except:
    b.stop()
    raise
Beispiel #6
0
connect_port = int(config["connection"]["port"])
nick = config["bot"]["nick"]
name = config["bot"]["name"]


net = None
if len(sys.argv) == 2:
    if sys.argv[1] == "record":
        conn = simple_connect((connect_host, connect_port))
        net = record(conn, "RECORD")
    if sys.argv[1] == "replay":
        net = replay("RECORD")
else:
    net = simple_connect((connect_host, connect_port))

b = Bot(net)
b.nick = nick
b.real_name = name
plugins = """alias
alarm
chance
colorize
date
fortune
gayify
google.define
google.search
google.youtube
invite
joiner
m528
Beispiel #7
0
net = None
if len(sys.argv) >= 2:
    if sys.argv[1] == "record":
        conn = simple_connect((connect_host, connect_port))
        net = record(conn, "RECORD")
    if sys.argv[1] == "replay":
        net = replay("RECORD")
    if sys.argv[1] == "test":
        import unittest
        result = unittest.TextTestRunner(verbosity=2).run(unittest.defaultTestLoader.discover('tests'))
        exit_code = 0
        if result.failures:
            exit_code += 1
        if result.errors:
            exit_code += 2
        exit(exit_code)
    if sys.argv[1] == "plugin":
        import yakr.plugin_maker
        yakr.plugin_maker.interactive()
        exit(0)
else:
    net = simple_connect((connect_host, connect_port))

b = Bot(net)
b.nick = nick
b.password = password
b.real_name = name
map(b.load, plugins)
b.run()