Browse Source

Cleanup; ensure unit tests are functional

tags/v0.1^2
Ben Kurtovic 12 years ago
parent
commit
e54db76757
3 changed files with 15 additions and 12 deletions
  1. +2
    -2
      earwigbot/__init__.py
  2. +2
    -2
      earwigbot/irc/watcher.py
  3. +11
    -8
      earwigbot/tests/__init__.py

+ 2
- 2
earwigbot/__init__.py View File

@@ -32,6 +32,6 @@ __version__ = "0.1.dev"
__email__ = "ben.kurtovic@verizon.net" __email__ = "ben.kurtovic@verizon.net"


from earwigbot import ( from earwigbot import (
blowfish, config, classes, commands, config, frontend, main, rules, tasks,
tests, watcher, wiki
blowfish, config, classes, commands, config, irc, main, rules, runner,
tasks, tests, wiki
) )

+ 2
- 2
earwigbot/irc/watcher.py View File

@@ -40,13 +40,13 @@ class Watcher(IRCConnection):
""" """


def __init__(self, frontend=None): def __init__(self, frontend=None):
logger = logging.getLogger("earwigbot.watcher")
self.logger = logging.getLogger("earwigbot.watcher")
cf = config.irc["watcher"] cf = config.irc["watcher"]
base = super(Frontend, self) base = super(Frontend, self)
base.__init__(cf["host"], cf["port"], cf["nick"], cf["ident"], base.__init__(cf["host"], cf["port"], cf["nick"], cf["ident"],
cf["realname"], self.logger) cf["realname"], self.logger)
self._connect()
self.frontend = frontend self.frontend = frontend
self._connect()


def _process_message(self, line): def _process_message(self, line):
"""Process a single message from IRC.""" """Process a single message from IRC."""


+ 11
- 8
earwigbot/tests/__init__.py View File

@@ -34,18 +34,18 @@ instead of a socket for data.
import re import re
from unittest import TestCase from unittest import TestCase


from earwigbot.classes import Connection, Data
from earwigbot.irc import IRCConnection, Data


class CommandTestCase(TestCase): class CommandTestCase(TestCase):
re_sender = re.compile(":(.*?)!(.*?)@(.*?)\Z") re_sender = re.compile(":(.*?)!(.*?)@(.*?)\Z")


def setUp(self, command): def setUp(self, command):
self.connection = FakeConnection() self.connection = FakeConnection()
self.connection.connect()
self.connection._connect()
self.command = command(self.connection) self.command = command(self.connection)


def get_single(self): def get_single(self):
data = self.connection.get().split("\n")
data = self.connection._get().split("\n")
line = data.pop(0) line = data.pop(0)
for remaining in data[1:]: for remaining in data[1:]:
self.connection.send(remaining) self.connection.send(remaining)
@@ -92,16 +92,19 @@ class CommandTestCase(TestCase):
line = ":Foo!bar@example.com JOIN :#channel".strip().split() line = ":Foo!bar@example.com JOIN :#channel".strip().split()
return self.maker(line, line[2][1:]) return self.maker(line, line[2][1:])


class FakeConnection(Connection):
def connect(self):
class FakeConnection(IRCConnection):
def __init__(self):
pass

def _connect(self):
self._buffer = "" self._buffer = ""


def close(self):
def _close(self):
pass pass


def get(self, size=4096):
def _get(self, size=4096):
data, self._buffer = self._buffer, "" data, self._buffer = self._buffer, ""
return data return data


def send(self, msg):
def _send(self, msg):
self._buffer += msg + "\n" self._buffer += msg + "\n"

Loading…
Cancel
Save