File: test.py

package info (click to toggle)
limnoria 2026.1.16-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 6,584 kB
  • sloc: python: 50,436; makefile: 49; sh: 14
file content (295 lines) | stat: -rw-r--r-- 13,078 bytes parent folder | download | duplicates (4)
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
###
# Copyright (c) 2002-2004, Jeremiah Fincher
# Copyright (c) 2010-2021, Valentin Lorentz
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
#   * Redistributions of source code must retain the above copyright notice,
#     this list of conditions, and the following disclaimer.
#   * Redistributions in binary form must reproduce the above copyright notice,
#     this list of conditions, and the following disclaimer in the
#     documentation and/or other materials provided with the distribution.
#   * Neither the name of the author of this software nor the name of
#     contributors to this software may be used to endorse or promote products
#     derived from this software without specific prior written consent.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
###

from supybot.test import *

class TopicTestCase(ChannelPluginTestCase):
    plugins = ('Topic','User',)
    def testRemove(self):
        self.assertError('topic remove 1')
        _ = self.getMsg('topic add foo')
        _ = self.getMsg('topic add bar')
        _ = self.getMsg('topic add baz')
        self.assertError('topic remove 0')
        self.assertNotError('topic remove 3')
        self.assertNotError('topic remove 2')
        self.assertNotError('topic remove 1')
        self.assertError('topic remove 1')

    def testRemoveMultiple(self):
        self.assertError('topic remove 1 2')
        _ = self.getMsg('topic add foo')
        _ = self.getMsg('topic add bar')
        _ = self.getMsg('topic add baz')
        _ = self.getMsg('topic add derp')
        _ = self.getMsg('topic add cheese')
        self.assertNotError('topic remove 1 2')
        self.assertNotError('topic remove -1 1')
        self.assertError('topic remove -99 1')

    def testReplace(self):
        _ = self.getMsg('topic add foo')
        _ = self.getMsg('topic add bar')
        _ = self.getMsg('topic add baz')
        self.assertRegexp('topic replace 1 oof', 'oof.*bar.*baz')
        self.assertRegexp('topic replace -1 zab', 'oof.*bar.*zab')
        self.assertRegexp('topic replace 2 lorem ipsum',
                          'oof.*lorem ipsum.*zab')
        self.assertRegexp('topic replace 2 rab', 'oof.*rab.*zab')

    def testGet(self):
        self.assertError('topic get 1')
        _ = self.getMsg('topic add foo')
        _ = self.getMsg('topic add bar')
        _ = self.getMsg('topic add baz')
        self.assertRegexp('topic get 1', '^foo')
        self.assertError('topic get 0')

    def testAdd(self):
        self.assertError('topic add #floorgle')
        m = self.getMsg('topic add foo')
        self.assertEqual(m.command, 'TOPIC')
        self.assertEqual(m.args[0], self.channel)
        self.assertEqual(m.args[1], 'foo')
        m = self.getMsg('topic add bar')
        self.assertEqual(m.command, 'TOPIC')
        self.assertEqual(m.args[0], self.channel)
        self.assertEqual(m.args[1], 'foo | bar')

    def testManageCapabilities(self):
        try:
            self.irc.feedMsg(ircmsgs.mode(self.channel, args=('+o', self.nick),
                                      prefix=self.prefix))
            self.irc.feedMsg(ircmsgs.mode(self.channel, args=('+t'),
                                      prefix=self.prefix))
            world.testing = False
            origuser = self.prefix
            self.prefix = 'stuff!stuff@stuff'
            self.assertNotError('register nottester stuff', private=True)

            self.assertError('topic add foo')
            origconf = conf.supybot.plugins.Topic.requireManageCapability()
            conf.supybot.plugins.Topic.requireManageCapability.setValue('')
            self.assertNotError('topic add foo')
        finally:
            world.testing = True
            self.prefix = origuser
            conf.supybot.plugins.Topic.requireManageCapability.setValue(origconf)

    def testInsert(self):
        m = self.getMsg('topic add foo')
        self.assertEqual(m.args[1], 'foo')
        m = self.getMsg('topic insert bar')
        self.assertEqual(m.args[1], 'bar | foo')

    def testChange(self):
        _ = self.getMsg('topic add foo')
        _ = self.getMsg('topic add bar')
        _ = self.getMsg('topic add baz')
        self.assertRegexp('topic change -1 s/baz/biff/',
                          r'foo.*bar.*biff')
        self.assertRegexp('topic change 2 s/bar/baz/',
                          r'foo.*baz.*biff')
        self.assertRegexp('topic change 1 s/foo/bar/',
                          r'bar.*baz.*biff')
        self.assertRegexp('topic change -2 s/baz/bazz/',
                          r'bar.*bazz.*biff')
        self.assertError('topic change 0 s/baz/biff/')

    def testConfig(self):
        try:
            original = conf.supybot.plugins.Topic.separator()
            conf.supybot.plugins.Topic.separator.setValue(' <==> ')
            _ = self.getMsg('topic add foo')
            m = self.getMsg('topic add bar')
            self.assertIn('<==>', m.args[1])
        finally:
            conf.supybot.plugins.Topic.separator.setValue(original)

    def testReorder(self):
        _ = self.getMsg('topic add foo')
        _ = self.getMsg('topic add bar')
        _ = self.getMsg('topic add baz')
        self.assertRegexp('topic reorder 2 1 3', r'bar.*foo.*baz')
        self.assertRegexp('topic reorder 3 -2 1', r'baz.*foo.*bar')
        self.assertError('topic reorder 0 1 2')
        self.assertError('topic reorder 1 -2 2')
        self.assertError('topic reorder 1 2')
        self.assertError('topic reorder 2 3 4')
        self.assertError('topic reorder 1 2 2')
        self.assertError('topic reorder 1 1 2 3')
        _ = self.getMsg('topic remove 1')
        _ = self.getMsg('topic remove 1')
        self.assertError('topic reorder 1')
        _ = self.getMsg('topic remove 1')
        self.assertError('topic reorder 0')

    def testList(self):
        _ = self.getMsg('topic add foo')
        self.assertRegexp('topic list', '1: foo')
        _ = self.getMsg('topic add bar')
        self.assertRegexp('topic list', '1: foo.*2: bar')
        _ = self.getMsg('topic add baz')
        self.assertRegexp('topic list', '1: foo.* 2: bar.* and 3: baz')

    def testSet(self):
        _ = self.getMsg('topic add foo')
        self.assertRegexp('topic set -1 bar', 'bar')
        self.assertNotRegexp('topic set -1 baz', 'bar')
        self.assertResponse('topic set foo bar baz', 'foo bar baz')
        # Catch a bug we had where setting topic 1 would reset the whole topic
        orig = conf.supybot.plugins.Topic.format()
        sep = conf.supybot.plugins.Topic.separator()
        try:
            conf.supybot.plugins.Topic.format.setValue('$topic')
            self.assertResponse('topic add baz', 'foo bar baz%sbaz' % sep)
            self.assertResponse('topic set 1 bar', 'bar%sbaz' % sep)
        finally:
            conf.supybot.plugins.Topic.format.setValue(orig)

    def testRestore(self):
        self.getMsg('topic set foo')
        self.assertResponse('topic restore', 'foo')
        self.getMsg('topic remove 1')
        restoreError = 'Error: I haven\'t yet set the topic in #test.'
        self.assertResponse('topic restore', restoreError)

    def testRefresh(self):
        self.getMsg('topic set foo')
        self.assertResponse('topic refresh', 'foo')
        self.getMsg('topic remove 1')
        refreshError = 'Error: I haven\'t yet set the topic in #test.'
        self.assertResponse('topic refresh', refreshError)

    def testUndo(self):
        try:
            original = conf.supybot.plugins.Topic.format()
            conf.supybot.plugins.Topic.format.setValue('$topic')
            self.assertResponse('topic set ""', '')
            self.assertResponse('topic add foo', 'foo')
            self.assertResponse('topic add bar', 'foo | bar')
            self.assertResponse('topic add baz', 'foo | bar | baz')
            self.assertResponse('topic undo', 'foo | bar')
            self.assertResponse('topic undo', 'foo')
            self.assertResponse('topic undo', '')
        finally:
            conf.supybot.plugins.Topic.format.setValue(original)

    def testUndoRedo(self):
        try:
            original = conf.supybot.plugins.Topic.format()
            conf.supybot.plugins.Topic.format.setValue('$topic')
            self.assertResponse('topic set ""', '')
            self.assertResponse('topic add foo', 'foo')
            self.assertResponse('topic add bar', 'foo | bar')
            self.assertResponse('topic add baz', 'foo | bar | baz')
            self.assertResponse('topic undo', 'foo | bar')
            self.assertResponse('topic undo', 'foo')
            self.assertResponse('topic undo', '')
            self.assertResponse('topic redo', 'foo')
            self.assertResponse('topic redo', 'foo | bar')
            self.assertResponse('topic redo', 'foo | bar | baz')
            self.assertResponse('topic undo', 'foo | bar')
            self.assertResponse('topic undo', 'foo')
            self.assertResponse('topic redo', 'foo | bar')
            self.assertResponse('topic undo', 'foo')
            self.assertResponse('topic redo', 'foo | bar')
        finally:
            conf.supybot.plugins.Topic.format.setValue(original)

    def testSwap(self):
        original = conf.supybot.plugins.Topic.format()
        try:
            conf.supybot.plugins.Topic.format.setValue('$topic')
            self.assertResponse('topic set ""', '')
            self.assertResponse('topic add foo', 'foo')
            self.assertResponse('topic add bar', 'foo | bar')
            self.assertResponse('topic add baz', 'foo | bar | baz')
            self.assertResponse('topic swap 1 2', 'bar | foo | baz')
            self.assertResponse('topic swap 1 -1', 'baz | foo | bar')
            self.assertError('topic swap -1 -1')
            self.assertError('topic swap 2 -2')
            self.assertError('topic swap 1 -3')
            self.assertError('topic swap -2 2')
            self.assertError('topic swap -3 1')
        finally:
            conf.supybot.plugins.Topic.format.setValue(original)

    def testDefault(self):
        self.assertError('topic default')
        try:
            original = conf.supybot.plugins.Topic.default()
            conf.supybot.plugins.Topic.default.setValue('foo bar baz')
            self.assertResponse('topic default', 'foo bar baz')
        finally:
            conf.supybot.plugins.Topic.default.setValue(original)


    def testTopic(self):
        original = conf.supybot.plugins.Topic.format()
        try:
            conf.supybot.plugins.Topic.format.setValue('$topic')
            self.assertError('topic addd') # Error to send too many args.
            self.assertResponse('topic add foo', 'foo')
            self.assertResponse('topic add bar', 'foo | bar')
            self.assertResponse('topic', 'foo | bar')
        finally:
            conf.supybot.plugins.Topic.format.setValue(original)

    def testSeparator(self):
        original = conf.supybot.plugins.Topic.format()
        try:
            conf.supybot.plugins.Topic.format.setValue('$topic')
            self.assertResponse('topic add foo', 'foo')
            self.assertResponse('topic add bar', 'foo | bar')
            self.assertResponse('topic add baz', 'foo | bar | baz')
            self.assertResponse('topic separator ::', 'foo :: bar :: baz')
            self.assertResponse('topic separator ||', 'foo || bar || baz')
            self.assertResponse('topic separator |', 'foo | bar | baz')

        finally:
            conf.supybot.plugins.Topic.format.setValue(original)

    def testFit(self):
        original = conf.supybot.plugins.Topic.format()
        try:
            conf.supybot.plugins.Topic.format.setValue('$topic')
            self.irc.state.supported['TOPICLEN'] = 20
            self.assertResponse('topic fit foo', 'foo')
            self.assertResponse('topic fit bar', 'foo | bar')
            self.assertResponse('topic fit baz', 'foo | bar | baz')
            self.assertResponse('topic fit qux', 'bar | baz | qux')
        finally:
            conf.supybot.plugins.Topic.format.setValue(original)
            self.irc.state.supported.pop('TOPICLEN', None)


# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: