aboutsummaryrefslogtreecommitdiff
blob: 136e135e8ccf3e629fb34d85fcaef445ede17f3d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
# Richard Darst, 2009

import glob
import os
import re
import shutil
import sys
import tempfile
import time
import threading
import unittest

os.environ['MEETBOT_RUNNING_TESTS'] = '1'
import ircmeeting.meeting as meeting
import ircmeeting.writers as writers

import test_meeting

running_tests = True

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.
    """
    return meeting.process_meeting(contents=contents,
                                channel="#none",  filename=filename,
                                dontSave=dontSave, safeMode=False,
                                extraConfig=extraConfig)

class MeetBotTest(unittest.TestCase):

    def test_replay(self):
        """Replay of a meeting, using 'meeting.py replay'.
        """
        old_argv = sys.argv[:]
        sys.argv[1:] = ["replay", "test-script-1.log.txt"]
        sys.path.insert(0, "../ircmeeting")
        try:
            gbls = {"__name__":"__main__",
                    "__file__":"../ircmeeting/meeting.py"}
            execfile("../ircmeeting/meeting.py", gbls)
            assert "M" in gbls, "M object not in globals: did it run?"
        finally:
            del sys.path[0]
            sys.argv[:] = old_argv

    def test_supybottests(self):
        """Test by sending input to supybot, check responses.

        Uses the external supybot-test command.  Unfortunantly, that
        doesn't have a useful status code, so I need to parse the
        output.
        """
        os.symlink("../MeetBot", "MeetBot")
        os.symlink("../ircmeeting", "ircmeeting")
        sys.path.insert(0, ".")
        try:
            output = os.popen("supybot-test ./MeetBot 2>&1").read()
            assert 'FAILED' not in output, "supybot-based tests failed."
            assert '\nOK\n'     in output, "supybot-based tests failed."
        finally:
            os.unlink("MeetBot")
            os.unlink("ircmeeting")
            del sys.path[0]

    trivial_contents = """
    10:10:10 <x> #startmeeting
    10:10:10 <x> blah
    10:10:10 <x> #endmeeting
    """

    full_writer_map = {
        '.log.txt':     writers.TextLog,
        '.log.1.html':  writers.HTMLlog1,
        '.log.html':    writers.HTMLlog2,
        '.1.html':      writers.HTML1,
        '.html':        writers.HTML2,
        '.rst':         writers.ReST,
        '.rst.html':    writers.HTMLfromReST,
        '.txt':         writers.Text,
        '.mw':          writers.MediaWiki,
        '.pmw':         writers.PmWiki,
        '.tmp.txt|template=+template.txt':   writers.Template,
        '.tmp.html|template=+template.html': writers.Template,
        }

    def M_trivial(self, contents=None, extraConfig={}):
        """Convenience wrapper to process_meeting.
        """
        if contents is None:
            contents = self.trivial_contents
        return process_meeting(contents=contents,
                               extraConfig=extraConfig)

    def test_script_1(self):
        """Run test-script-1.log.txt through the processor.

        - Check all writers
        - Check actual file writing.
        """
        tmpdir = tempfile.mkdtemp(prefix='test-meetbot')
        try:
            process_meeting(contents=file('test-script-1.log.txt').read(),
                            filename=os.path.join(tmpdir, 'meeting'),
                            dontSave=False,
                            extraConfig={'writer_map':self.full_writer_map,
                                         })
            # Test every extension in the full_writer_map to make sure
            # it was written.
            for extension in self.full_writer_map:
                ext = re.search(r'^\.(.*?)($|\|)', extension).group(1)
                files = glob.glob(os.path.join(tmpdir, 'meeting.'+ext))
                assert len(files) > 0, \
                       "Extension did not produce output: '%s'"%extension
        finally:
            shutil.rmtree(tmpdir)

    #def test_script_3(self):
    #   process_meeting(contents=file('test-script-3.log.txt').read(),
    #                   extraConfig={'writer_map':self.full_writer_map})

    all_commands_test_contents = """
    10:10:10 <x> #startmeeting
    10:10:10 <x> #topic h6k4orkac
    10:10:10 <x> #info blaoulrao
    10:10:10 <x> #idea alrkkcao4
    10:10:10 <x> #help ntoircoa5
    10:10:10 <x> #link http://bnatorkcao.net kroacaonteu
    10:10:10 <x> http://jrotjkor.net krotroun
    10:10:10 <x> #action xrceoukrc
    10:10:10 <x> #nick okbtrokr

    # Should not appear in non-log output
    10:10:10 <x> #idea ckmorkont
    10:10:10 <x> #undo

    # Assert that chairs can change the topic, and non-chairs can't.
    10:10:10 <x> #chair y
    10:10:10 <y> #topic topic_doeschange
    10:10:10 <z> #topic topic_doesntchange
    10:10:10 <x> #unchair y
    10:10:10 <y> #topic topic_doesnt2change

    10:10:10 <x> #endmeeting
    """
    def test_contents_test2(self):
        """Ensure that certain input lines do appear in the output.

        This test ensures that the input to certain commands does
        appear in the output.
        """
        M = process_meeting(contents=self.all_commands_test_contents,
                            extraConfig={'writer_map':self.full_writer_map})
        results = M.save()
        for name, output in results.iteritems():
            self.assert_('h6k4orkac' in output, "Topic failed for %s"%name)
            self.assert_('blaoulrao' in output, "Info failed for %s"%name)
            self.assert_('alrkkcao4' in output, "Idea failed for %s"%name)
            self.assert_('ntoircoa5' in output, "Help failed for %s"%name)
            self.assert_('http://bnatorkcao.net' in output,
                                                  "Link(1) failed for %s"%name)
            self.assert_('kroacaonteu' in output, "Link(2) failed for %s"%name)
            self.assert_('http://jrotjkor.net' in output,
                                        "Link detection(1) failed for %s"%name)
            self.assert_('krotroun' in output,
                                        "Link detection(2) failed for %s"%name)
            self.assert_('xrceoukrc' in output, "Action failed for %s"%name)
            self.assert_('okbtrokr' in output, "Nick failed for %s"%name)

            # Things which should only appear or not appear in the
            # notes (not the logs):
            if 'log' not in name:
                self.assert_( 'ckmorkont' not in output,
                              "Undo failed for %s"%name)
                self.assert_('topic_doeschange' in output,
                             "Chair changing topic failed for %s"%name)
                self.assert_('topic_doesntchange' not in output,
                             "Non-chair not changing topic failed for %s"%name)
                self.assert_('topic_doesnt2change' not in output,
                            "Un-chaired was able to chang topic for %s"%name)

    #def test_contents_test(self):
    #    contents = open('test-script-3.log.txt').read()
    #    M = process_meeting(contents=file('test-script-3.log.txt').read(),
    #                        extraConfig={'writer_map':self.full_writer_map})
    #    results = M.save()
    #    for line in contents.split('\n'):
    #        m = re.search(r'#(\w+)\s+(.*)', line)
    #        if not m:
    #            continue
    #        type_ = m.group(1)
    #        text = m.group(2)
    #        text = re.sub('[^\w]+', '', text).lower()
    #
    #        m2 = re.search(t2, re.sub(r'[^\w\n]', '', results['.txt']))
    #        import fitz.interactnow
    #        print m.groups()

    def test_actionNickMatching(self):
        """Test properly detect nicknames in lines

        This checks the 'Action items, per person' list to make sure
        that the nick matching is limited to full words.  For example,
        the nick 'jon' will no longer be assigned lines containing
        'jonathan'.
        """
        script = """
        20:13:50 <x> #startmeeting
        20:13:50 <somenick>
        20:13:50 <someone> #action say somenickLONG
        20:13:50 <someone> #action say the somenicklong
        20:13:50 <somenick> I should not have an item assisgned to me.
        20:13:50 <somenicklong> I should have some things assigned to me.
        20:13:50 <x> #endmeeting
        """
        M = process_meeting(script)
        results = M.save()['.html']
        # This regular expression is:
        # \bsomenick\b   - the nick in a single word
        # (?! \()        - without " (" following it... to not match
        #                  the "People present" section.
        assert not re.search(r'\bsomenick\b(?! \()',
                         results, re.IGNORECASE), \
                         "Nick full-word matching failed"

    def test_urlMatching(self):
        """Test properly detection of URLs in lines
        """
        script = """
        20:13:50 <x> #startmeeting
        20:13:50 <x> #link prefix http://site1.com suffix
        20:13:50 <x> http://site2.com suffix
        20:13:50 <x> ftp://ftpsite1.com suffix
        20:13:50 <x> #link prefix ftp://ftpsite2.com suffix
        20:13:50 <x> irc://ircsite1.com suffix
        20:13:50 <x> mailto://a@mail.com suffix
        20:13:50 <x> #endmeeting
        """
        M = process_meeting(script)
        results = M.save()['.html']
        assert re.search(r'prefix.*href.*http://site1.com.*suffix',
                         results), "URL missing 1"
        assert re.search(r'href.*http://site2.com.*suffix',
                         results), "URL missing 2"
        assert re.search(r'href.*ftp://ftpsite1.com.*suffix',
                         results), "URL missing 3"
        assert re.search(r'prefix.*href.*ftp://ftpsite2.com.*suffix',
                         results), "URL missing 4"
        assert re.search(r'href.*mailto://a@mail.com.*suffix',
                         results), "URL missing 5"

    def t_css(self):
        """Runs all CSS-related tests.
        """
        self.test_css_embed()
        self.test_css_noembed()
        self.test_css_file_embed()
        self.test_css_file()
        self.test_css_none()
    def test_css_embed(self):
        extraConfig={ }
        results = self.M_trivial(extraConfig={}).save()
        self.assert_('<link rel="stylesheet" ' not in results['.html'])
        self.assert_('body {'                      in results['.html'])
        self.assert_('<link rel="stylesheet" ' not in results['.log.html'])
        self.assert_('body {'                      in results['.log.html'])
    def test_css_noembed(self):
        extraConfig={'cssEmbed_minutes':False,
                     'cssEmbed_log':False,}
        M = self.M_trivial(extraConfig=extraConfig)
        results = M.save()
        self.assert_('<link rel="stylesheet" '     in results['.html'])
        self.assert_('body {'                  not in results['.html'])
        self.assert_('<link rel="stylesheet" '     in results['.log.html'])
        self.assert_('body {'                  not in results['.log.html'])
    def test_css_file(self):
        tmpf = tempfile.NamedTemporaryFile()
        magic_string = '546uorck6o45tuo6'
        tmpf.write(magic_string)
        tmpf.flush()
        extraConfig={'cssFile_minutes':  tmpf.name,
                     'cssFile_log':      tmpf.name,}
        M = self.M_trivial(extraConfig=extraConfig)
        results = M.save()
        self.assert_('<link rel="stylesheet" ' not in results['.html'])
        self.assert_(magic_string                  in results['.html'])
        self.assert_('<link rel="stylesheet" ' not in results['.log.html'])
        self.assert_(magic_string                  in results['.log.html'])
    def test_css_file_embed(self):
        tmpf = tempfile.NamedTemporaryFile()
        magic_string = '546uorck6o45tuo6'
        tmpf.write(magic_string)
        tmpf.flush()
        extraConfig={'cssFile_minutes':  tmpf.name,
                     'cssFile_log':      tmpf.name,
                     'cssEmbed_minutes': False,
                     'cssEmbed_log':     False,}
        M = self.M_trivial(extraConfig=extraConfig)
        results = M.save()
        self.assert_('<link rel="stylesheet" '     in results['.html'])
        self.assert_(tmpf.name                     in results['.html'])
        self.assert_('<link rel="stylesheet" '     in results['.log.html'])
        self.assert_(tmpf.name                     in results['.log.html'])
    def test_css_none(self):
        tmpf = tempfile.NamedTemporaryFile()
        magic_string = '546uorck6o45tuo6'
        tmpf.write(magic_string)
        tmpf.flush()
        extraConfig={'cssFile_minutes':  'none',
                     'cssFile_log':      'none',}
        M = self.M_trivial(extraConfig=extraConfig)
        results = M.save()
        self.assert_('<link rel="stylesheet" ' not in results['.html'])
        self.assert_('<style type="text/css" ' not in results['.html'])
        self.assert_('<link rel="stylesheet" ' not in results['.log.html'])
        self.assert_('<style type="text/css" ' not in results['.log.html'])

    def test_filenamevars(self):
        def getM(fnamepattern):
            M = meeting.Meeting(channel='somechannel',
                                network='somenetwork',
                                owner='nobody',
                     extraConfig={'filenamePattern':fnamepattern})
            M.addline('nobody', '#startmeeting')
            return M
        # Test the %(channel)s and %(network)s commands in supybot.
        M = getM('%(channel)s-%(network)s')
        assert M.config.filename().endswith('somechannel-somenetwork'), \
               "Filename not as expected: "+M.config.filename()
        # Test dates in filenames
        M = getM('%(channel)s-%%F')
        import time
        assert M.config.filename().endswith(time.strftime('somechannel-%F')),\
               "Filename not as expected: "+M.config.filename()
        # Test #meetingname in filenames
        M = getM('%(channel)s-%(meetingname)s')
        M.addline('nobody', '#meetingname blah1234')
        assert M.config.filename().endswith('somechannel-blah1234'),\
               "Filename not as expected: "+M.config.filename()

    def get_simple_agenda_test(self):
        test = test_meeting.TestMeeting()
        test.set_voters(['x', 'z'])
        test.set_agenda([['first item', ['opt1', 'opt2'], ''], ['second item', [], ''], ['third item', [], '']])
        test.M.config.manage_agenda = False

        test.answer_should_match("20:13:50 <x> #startmeeting",
        "Meeting started .*\nUseful Commands: #action #agreed #help #info #idea #link #topic.\n")
        test.M.config.manage_agenda = True

        return(test)

    def test_agenda_item_changing(self):
        test = self.get_simple_agenda_test()

        # Test changing item before vote
        test.answer_should_match('20:13:50 <x> #nextitem', 'Current agenda item is second item.')
        test.answer_should_match('20:13:50 <x> #nextitem', 'Current agenda item is third item.')
        test.answer_should_match('20:13:50 <x> #nextitem', 'Current agenda item is third item.')
        test.answer_should_match('20:13:50 <x> #previtem', 'Current agenda item is second item.')
        test.answer_should_match('20:13:50 <x> #previtem', 'Current agenda item is first item.')
        test.answer_should_match('20:13:50 <x> #previtem', 'Current agenda item is first item.')
        test.answer_should_match('20:13:50 <x> #changeitem 2', 'Current agenda item is third item.')
        test.answer_should_match('20:13:50 <x> #changeitem 1', 'Current agenda item is second item.')
        test.answer_should_match('20:13:50 <x> #changeitem 0', 'Current agenda item is first item.')
        test.answer_should_match('20:13:50 <x> #changeitem 10', 'Your choice was out of range!')
        test.answer_should_match('20:13:50 <x> #changeitem puppy', 'Your choice was not recognized as a number. Please retry.')

        # Test changing item during vote
        test.process('20:13:50 <x> #startvote')
        test.answer_should_match('20:13:50 <x> #nextitem', 'Voting is currently ' +\
                                  'open so I didn\'t change item. Please #endvote first')
        test.answer_should_match('20:13:50 <x> #previtem', 'Voting is currently ' +\
                                  'open so I didn\'t change item. Please #endvote first')
        test.answer_should_match('20:13:50 <x> #changeitem 2', 'Voting is currently ' +\
                                  'open so I didn\'t change item. Please #endvote first')

        # Test changing item after vote
        test.process('20:13:50 <x> #endvote')
        test.answer_should_match('20:13:50 <x> #nextitem', 'Current agenda item is second item.')
        test.answer_should_match('20:13:50 <x> #previtem', 'Current agenda item is first item.')
        test.answer_should_match('20:13:50 <x> #changeitem 2', 'Current agenda item is third item.')

    def test_agenda_option_listing(self):
        test = self.get_simple_agenda_test()

        test.answer_should_match('20:13:50 <x> #option list', 'Available voting options ' +\
                                  'are:\n0. opt1\n1. opt2\n')
        test.process('20:13:50 <x> #nextitem')
        test.answer_should_match('20:13:50 <x> #option list', 'No voting options available.')
        test.process('20:13:50 <x> #previtem')
        test.answer_should_match('20:13:50 <x> #option list', 'Available voting options ' +\
                                  'are:\n0. opt1\n1. opt2\n')

    def test_agenda_option_adding(self):
        test = self.get_simple_agenda_test()
        test.process('20:13:50 <x> #nextitem')
        test.answer_should_match('20:13:50 <not_allowed> #option add first option',
                                  'You can not vote or change agenda. Only x, z can.')
        test.answer_should_match('20:13:50 <x> #option add first option',
                                  'You added new voting option: first option')
        test.answer_should_match('20:13:50 <x> #option list', 'Available voting options ' +\
                                  'are:\n0. first option')

    def test_agenda_option_removing(self):
        test = self.get_simple_agenda_test()
        test.answer_should_match('20:13:50 <not_allowed> #option remove 1',
                                  'You can not vote or change agenda. Only x, z can.')
        test.answer_should_match('20:13:50 <x> #option remove 1',
                                  'You removed voting option 1: opt2')
        test.answer_should_match('20:13:50 <x> #option list', 'Available voting options ' +\
                                  'are:\n0. opt1')

    def test_agenda_voting(self):
        test = self.get_simple_agenda_test()
        test.M.config.agenda._voters.append('t')
        test.answer_should_match('20:13:50 <x> #startvote', 'Voting started\. ' +\
                                  'Available voting options are:\n0. opt1\n1. opt2\nVote ' +\
                                  '#vote <option number>.\nEnd voting with #endvote.')
        test.answer_should_match('20:13:50 <x> #startvote', 'Voting is already open. ' +\
                                  'You can end it with #endvote.')
        test.answer_should_match('20:13:50 <x> #vote 10', 'Your choice was out of range\!')
        test.answer_should_match('20:13:50 <x> #vote 0', 'You voted for #0 - opt1')
        test.answer_should_match('20:13:50 <x> #vote 1', 'You voted for #1 - opt2')
        test.answer_should_match('20:13:50 <z> #vote 0', 'You voted for #0 - opt1')
        test.answer_should_match('20:13:50 <x> #option list', 'Available voting options ' +\
                                  'are:\n0. opt1\n1. opt2\n')
        test.answer_should_match('20:13:50 <x> #endvote', 'Voting closed.')
        test.answer_should_match('20:13:50 <x> #endvote', 'Voting is already closed. ' +\
                                  'You can start it with #startvote.')

        test.M.config.manage_agenda = False
        test.answer_should_match('20:13:50 <x> #endmeeting', 'Meeting ended ' +\
                                  '.*\nMinutes:.*\nMinutes \(text\):.*\nLog:.*')

        assert(test.votes() == {'first item': {u'x': 'opt2', u'z': 'opt1'}, 'second item': {}, 'third item': {}})

    def test_agenda_close_voting_after_last_vote(self):
        test = self.get_simple_agenda_test()
        test.answer_should_match('20:13:50 <x> #startvote', 'Voting started\. ' +\
                                  'Available voting options are:\n0. opt1\n1. opt2\nVote ' +\
                                  '#vote <option number>.\nEnd voting with #endvote.')
        test.answer_should_match('20:13:50 <x> #startvote', 'Voting is already open. ' +\
                                  'You can end it with #endvote.')
        test.answer_should_match('20:13:50 <x> #vote 0', 'You voted for #0 - opt1')
        test.answer_should_match('20:13:50 <z> #vote 0', 'You voted for #0 - opt1. Voting closed.')

    def test_agenda_time_limit_adding(self):
        test = self.get_simple_agenda_test()
        test.answer_should_match('20:13:50 <x> #timelimit', test.M.do_timelimit.__doc__)
        test.answer_should_match('20:13:50 <x> #timelimit add 0:1 some other message',
                                  'Added "some other message" reminder in 0:1')
        test.answer_should_match('20:13:50 <x> #timelimit add 1:0 some message',
                                  'Added "some message" reminder in 1:0')
        time.sleep(2)
        last_message = test.log[-1]
        assert(last_message == 'some other message')
        reminders = test.M.config.agenda.reminders
        assert(len(reminders) == 2)
        for reminder in reminders.values():
          assert(reminder.__class__ == threading._Timer)

        test.process('20:13:50 <x> #nextitem')

    def test_agenda_time_limit_removing_when_changing_item(self):
        test = self.get_simple_agenda_test()

        test.process('20:13:50 <x> #timelimit add 0:1 message')
        assert(len(test.M.config.agenda.reminders) == 1)
        test.process('20:13:50 <x> #nextitem')
        assert(len(test.M.config.agenda.reminders) == 0)
        test.process('20:13:50 <x> #timelimit add 0:1 message')
        assert(len(test.M.config.agenda.reminders) == 1)
        test.process('20:13:50 <x> #previtem')
        assert(len(test.M.config.agenda.reminders) == 0)

    def test_agenda_time_limit_manual_removing(self):
        test = self.get_simple_agenda_test()

        test.process('20:13:50 <x> #timelimit add 0:1 message')
        test.process('20:13:50 <x> #timelimit add 0:1 other message')
        keys = test.M.config.agenda.reminders.keys()
        keys.sort()
        assert(keys == ['message', 'other message'])

        test.answer_should_match('20:13:50 <x> #timelimit remove other message', 'Reminder "other message" removed')
        keys = test.M.config.agenda.reminders.keys()
        assert(keys == ['message'])

    def test_agenda_time_limit_listing(self):
        test = self.get_simple_agenda_test()
        test.process('20:13:50 <x> #timelimit add 0:1 message')
        test.process('20:13:50 <x> #timelimit add 0:1 other message')
        test.process('20:13:50 <x> #timelimit add 0:1 yet another message')
        keys = test.M.config.agenda.reminders.keys()
        test.answer_should_match('20:13:50 <x> #timelimit list',
                                  'Set reminders: "' + '", "'.join(keys) + '"')

    def test_preset_agenda_time_limits(self):
        test = self.get_simple_agenda_test()
        test.M.config.agenda._agenda[0][2] = '1:0 message'
        test.M.config.agenda._agenda[1][2] = '1:0 another message\n0:10 some other message'

        test.process('20:13:50 <x> #nextitem')
        keys = test.M.config.agenda.reminders.keys()
        keys.sort()
        assert(keys == ['another message', 'some other message'])

        test.process('20:13:50 <x> #previtem')
        keys = test.M.config.agenda.reminders.keys()
        keys.sort()
        assert(keys == ['message'])

        test.process('20:13:50 <x> #nextitem')

    def test_multiple_reminders(self):
        test = self.get_simple_agenda_test()
        test.process('20:13:50 <x> #timelimit add 0:1 message')
        test.process('20:13:50 <x> #timelimit add 0:2 other message')
        test.process('20:13:50 <x> #timelimit add 0:3 yet another message')
        test.log = []
        time.sleep(4)
        expected_messages = ['message', 'other message', 'yet another message']
        messages_match = (expected_messages == test.log)
        error_msg = 'Received messages ' + str(test.log) + \
                    ' didn\'t match expected ' + str(expected_messages)
        assert messages_match, error_msg
    def test_command_help(self):
        test = self.get_simple_agenda_test()
        commands = ['startmeeting', 'startvote', 'vote', 'endvote',
                    'nextitem', 'previtem', 'changeitem', 'option',
                    'timelimit', 'endmeeting']
        for command in commands:
          desc = getattr(test.M, 'do_' + command).__doc__
          if desc is None:
            desc = ''
          test.answer_should_match('20:13:50 <x> #command ' + command, desc)

if __name__ == '__main__':
    os.chdir(os.path.join(os.path.dirname(__file__), '.'))

    if len(sys.argv) <= 1:
        unittest.main()
    else:
        for testname in sys.argv[1:]:
            print testname
            if hasattr(MeetBotTest, testname):
                MeetBotTest(methodName=testname).debug()
            else:
                MeetBotTest(methodName='test_'+testname).debug()