diff options
author | Joachim Filip Ignacy Bartosik <jbartosik@gmail.com> | 2011-06-13 18:25:17 +0200 |
---|---|---|
committer | Joachim Filip Ignacy Bartosik <jbartosik@gmail.com> | 2011-06-13 18:25:17 +0200 |
commit | e2ff317cf9c8832a98d805e7a04e1a2b3ed5520c (patch) | |
tree | c36c3a650a25936477cdb9b8c69bc910578a2f0d | |
parent | Show slacking information in the application (diff) | |
download | council-webapp-e2ff317cf9c8832a98d805e7a04e1a2b3ed5520c.tar.gz council-webapp-e2ff317cf9c8832a98d805e7a04e1a2b3ed5520c.tar.bz2 council-webapp-e2ff317cf9c8832a98d805e7a04e1a2b3ed5520c.zip |
Make Meetbot tests cleaner, fix one bug found in the process
-rw-r--r-- | bot/ircmeeting/agenda.py | 2 | ||||
-rw-r--r-- | bot/tests/run_test.py | 56 | ||||
-rw-r--r-- | bot/tests/test_meeting.py | 61 |
3 files changed, 75 insertions, 44 deletions
diff --git a/bot/ircmeeting/agenda.py b/bot/ircmeeting/agenda.py index 2269f6f..e3f456c 100644 --- a/bot/ircmeeting/agenda.py +++ b/bot/ircmeeting/agenda.py @@ -60,7 +60,7 @@ class Agenda(object): def end_vote(self): if self._vote_open: self._vote_open = False - return voting_already_closed_msg + return self.voting_already_closed_msg return voting_close_msg def get_data(self): diff --git a/bot/tests/run_test.py b/bot/tests/run_test.py index f304a2b..79bb9d7 100644 --- a/bot/tests/run_test.py +++ b/bot/tests/run_test.py @@ -7,19 +7,14 @@ import shutil import sys import tempfile import unittest -import time os.environ['MEETBOT_RUNNING_TESTS'] = '1' import ircmeeting.meeting as meeting import ircmeeting.writers as writers -running_tests = True +import test_meeting -def parse_time(time_): - try: return time.strptime(time_, "%H:%M:%S") - except ValueError: pass - try: return time.strptime(time_, "%H:%M") - except ValueError: pass +running_tests = True def process_meeting(contents, extraConfig={}, dontSave=True, filename='/dev/null'): @@ -347,21 +342,13 @@ class MeetBotTest(unittest.TestCase): def test_agenda(self): """ Test agenda management """ - logline_re = re.compile(r'\[?([0-9: ]*)\]? *<[@+]?([^>]+)> *(.*)') - loglineAction_re = re.compile(r'\[?([0-9: ]*)\]? *\* *([^ ]+) *(.*)') - - M = process_meeting('#startmeeting') - log = [] - M._sendReply = lambda x: log.append(x) - M.config.agenda._voters = ['x', 'z'] - M.config.agenda._agenda = [['first item', ['opt1', 'opt2']], ['second item', []]] - M.config.agenda._votes = { } - for i in M.config.agenda._agenda: - M.config.agenda._votes[i[0]] = { } - - M.starttime = time.gmtime(0) - contents = """20:13:50 <x> #nextitem + test = test_meeting.TestMeeting() + test.set_voters(['x', 'z']) + test.set_agenda([['first item', ['opt1', 'opt2']], ['second item', []]]) + test.process(""" + 20:13:50 <x> #startmeeting + 20:13:50 <x> #nextitem 20:13:50 <x> #nextitem 20:13:50 <x> #previtem 20:13:50 <x> #previtem @@ -371,27 +358,8 @@ class MeetBotTest(unittest.TestCase): 20:13:50 <y> #vote 0 20:13:50 <z> #vote 0 20:13:50 <x> #endvote - 20:13:50 <x> #endmeeting""" - - for line in contents.split('\n'): - # match regular spoken lines: - m = logline_re.match(line) - if m: - time_ = parse_time(m.group(1).strip()) - nick = m.group(2).strip() - line = m.group(3).strip() - if M.owner is None: - M.owner = nick ; M.chairs = {nick:True} - M.addline(nick, line, time_=time_) - # match /me lines - m = loglineAction_re.match(line) - if m: - time_ = parse_time(m.group(1).strip()) - nick = m.group(2).strip() - line = m.group(3).strip() - M.addline(nick, "ACTION "+line, time_=time_) - - self.assert_(M.config.agenda._votes == {'first item': {u'x': 'opt2', u'z': 'opt1'}, 'second item': {}}) + 20:13:50 <x> #endmeeting""") + answers = ['Current agenda item is second item.', 'Current agenda item is second item.', @@ -406,7 +374,9 @@ class MeetBotTest(unittest.TestCase): "You voted for #1 - ['opt1', 'opt2']", 'You can not vote. Only x, z can vote', 'You voted for #0 - first item'] - self.assert_(log[0:len(answers)] == answers) + + self.assert_(test.votes == {'first item': {u'x': 'opt2', u'z': 'opt1'}, 'second item': {}}) + self.assert_(test.log[0:len(answers)] == answers) if __name__ == '__main__': os.chdir(os.path.join(os.path.dirname(__file__), '.')) diff --git a/bot/tests/test_meeting.py b/bot/tests/test_meeting.py new file mode 100644 index 0000000..9315b63 --- /dev/null +++ b/bot/tests/test_meeting.py @@ -0,0 +1,61 @@ +import ircmeeting.meeting as meeting +import ircmeeting.writers as writers +import re +import time +def process_meeting(contents, extraConfig={}, dontSave=True, + filename='/dev/null'): + """Take a test script, return Meeting object of that meeting. + + To access the results (a dict keyed by extensions), use M.save(), + with M being the return of this function. + """ +class TestMeeting: + logline_re = re.compile(r'\[?([0-9: ]*)\]? *<[@+]?([^>]+)> *(.*)') + loglineAction_re = re.compile(r'\[?([0-9: ]*)\]? *\* *([^ ]+) *(.*)') + M = meeting.process_meeting(contents = '', + channel = "#none", filename = '/dev/null', + dontSave = True, safeMode = False, + extraConfig = {}) + log = [] + + def __init__(self): + self.M._sendReply = lambda x: self.log.append(x) + self.M.starttime = time.gmtime(0) + + def set_voters(self, voters): + self.M.config.agenda._voters = voters + + def set_agenda(self, agenda): + self.M.config.agenda._agenda = agenda + self.M.config.agenda._votes = { } + for i in agenda: + self.M.config.agenda._votes[i[0]] = { } + + + def parse_time(self, time_): + try: return time.strptime(time_, "%H:%M:%S") + except ValueError: pass + try: return time.strptime(time_, "%H:%M") + except ValueError: pass + + def process(self, content): + for line in content.split('\n'): + # match regular spoken lines: + m = self.logline_re.match(line) + if m: + time_ = self.parse_time(m.group(1).strip()) + nick = m.group(2).strip() + line = m.group(3).strip() + if self.M.owner is None: + self.M.owner = nick ; self.M.chairs = {nick:True} + self.M.addline(nick, line, time_=time_) + # match /me lines + self.m = self.loglineAction_re.match(line) + if m: + time_ = self.parse_time(m.group(1).strip()) + nick = m.group(2).strip() + line = m.group(3).strip() + self.M.addline(nick, "ACTION "+line, time_=time_) + + def votes(self): + return(self.M.config.agenda._votes) |