Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tests/run_test.py
blob: f4738e27f9bb72951b4d8fcc2576b176749ffac5 (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
# Richard Darst, 2009

import os
import sys
import tempfile
import unittest

import meeting
import writers

running_tests = True
os.environ['MEETBOT_RUNNING_TESTS'] = '1'

class MeetBotTest(unittest.TestCase):

    def test_replay(self):
        """Replay of a meeting, using __meeting__.
        """
        sys.argv[1:] = ["replay", "test-script-1.log.txt"]
        sys.path.insert(0, "..")
        try:
            execfile("../meeting.py", globals())
        finally:
            del sys.path[0]

    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")
        try:
            output = os.popen("supybot-test ./MeetBot 2>&1").read()
            print output
            assert 'FAILED' not in output, "supybot-based tests failed."
            assert '\nOK\n'     in output, "supybot-based tests failed."
        finally:
            os.unlink("MeetBot")

    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,
        }

    def M_trivial(self, contents=None, extraConfig={}):
        if contents is None:
            contents = self.trivial_contents
        return meeting.process_meeting(contents=contents,
                                       channel="#none",
                                       filename='/dev/null',
                                       dontSave=True,
                                       extraConfig=extraConfig,
                                       safeMode=False)

    def test_script_1(self):
        meeting.process_meeting(contents=file('test-script-1.log.txt').read(),
                                channel="#none",  filename='/dev/null',
                                dontSave=True, safeMode=False,
                                extraConfig={
                                         'writer_map':self.full_writer_map})
    #def test_script_3(self):
    #   meeting.process_meeting(contents=file('test-script-3.log.txt').read(),
    #                            channel="#none",  filename='/dev/null',
    #                            dontSave=True, safeMode=False,
    #                            extraConfig={
    #                                     'writer_map':self.full_writer_map})

    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'])



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()