~ubuntu-ru-irc/+junk/irckit

« back to all changes in this revision

Viewing changes to ubuntuhelp/ubuntubot/plugins/Google/test.py

  • Committer: rmPIC30 at gmail
  • Date: 2010-07-13 09:08:58 UTC
  • Revision ID: rmpic30@gmail.com-20100713090858-w5kkmk093hx38cen
Добавляю бота

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
###
 
2
# Copyright (c) 2002-2004, Jeremiah Fincher
 
3
# Copyright (c) 2008, James Vega
 
4
# All rights reserved.
 
5
#
 
6
# Redistribution and use in source and binary forms, with or without
 
7
# modification, are permitted provided that the following conditions are met:
 
8
#
 
9
#   * Redistributions of source code must retain the above copyright notice,
 
10
#     this list of conditions, and the following disclaimer.
 
11
#   * Redistributions in binary form must reproduce the above copyright notice,
 
12
#     this list of conditions, and the following disclaimer in the
 
13
#     documentation and/or other materials provided with the distribution.
 
14
#   * Neither the name of the author of this software nor the name of
 
15
#     contributors to this software may be used to endorse or promote products
 
16
#     derived from this software without specific prior written consent.
 
17
#
 
18
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 
19
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 
20
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 
21
# ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 
22
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 
23
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 
24
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 
25
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 
26
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 
27
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 
28
# POSSIBILITY OF SUCH DAMAGE.
 
29
###
 
30
 
 
31
from supybot.test import *
 
32
 
 
33
class GoogleTestCase(ChannelPluginTestCase):
 
34
    plugins = ('Google',)
 
35
    if network:
 
36
        def testCalcHandlesMultiplicationSymbol(self):
 
37
            self.assertNotRegexp('google calc seconds in a century', r'215')
 
38
 
 
39
        def testCalc(self):
 
40
            self.assertNotRegexp('google calc e^(i*pi)+1', r'didn\'t')
 
41
 
 
42
        def testHtmlHandled(self):
 
43
            self.assertNotRegexp('google calc '
 
44
                                 'the speed of light '
 
45
                                 'in microns / fortnight', '<sup>')
 
46
            self.assertNotRegexp('google calc '
 
47
                                 'the speed of light '
 
48
                                 'in microns / fortnight', '&times;')
 
49
 
 
50
        def testSearch(self):
 
51
            self.assertNotError('google foo')
 
52
            self.assertRegexp('google dupa', r'dupa')
 
53
            # Unicode check
 
54
            self.assertNotError('google ae')
 
55
 
 
56
        def testFight(self):
 
57
            self.assertRegexp('fight supybot moobot', r'.*supybot.*: \d+')
 
58
 
 
59
        def testTranslate(self):
 
60
            self.assertRegexp('translate en es hello world', 'mundo')
 
61
 
 
62
        def testCalcDoesNotHaveExtraSpaces(self):
 
63
            self.assertNotRegexp('google calc 1000^2', r'\s+,\s+')
 
64
 
 
65
        def testGroupsSnarfer(self):
 
66
            orig = conf.supybot.plugins.Google.groupsSnarfer()
 
67
            try:
 
68
                conf.supybot.plugins.Google.groupsSnarfer.setValue(True)
 
69
                # This should work, and does work in practice, but is failing
 
70
                # in the tests.
 
71
                #self.assertSnarfRegexp(
 
72
                #    'http://groups.google.com/groups?dq=&hl=en&lr=lang_en&'
 
73
                #    'ie=UTF-8&oe=UTF-8&selm=698f09f8.0310132012.738e22fc'
 
74
                #    '%40posting.google.com',
 
75
                #    r'comp\.lang\.python.*question: usage of __slots__')
 
76
                self.assertSnarfRegexp(
 
77
                    'http://groups.google.com/groups?selm=ExDm.8bj.23'
 
78
                    '%40gated-at.bofh.it&oe=UTF-8&output=gplain',
 
79
                    r'linux\.kernel.*NFS client freezes')
 
80
                self.assertSnarfRegexp(
 
81
                    'http://groups.google.com/groups?q=kernel+hot-pants&'
 
82
                    'hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=1.5.4.32.199703131'
 
83
                    '70853.00674d60%40adan.kingston.net&rnum=1',
 
84
                    r'Madrid Bluegrass Ramble')
 
85
                self.assertSnarfRegexp(
 
86
                    'http://groups.google.com/groups?selm=1.5.4.32.19970'
 
87
                    '313170853.00674d60%40adan.kingston.net&oe=UTF-8&'
 
88
                    'output=gplain',
 
89
                    r'Madrid Bluegrass Ramble')
 
90
                self.assertSnarfRegexp(
 
91
                    'http://groups.google.com/groups?dq=&hl=en&lr=&'
 
92
                    'ie=UTF-8&threadm=mailman.1010.1069645289.702.'
 
93
                    'python-list%40python.org&prev=/groups%3Fhl%3Den'
 
94
                    '%26lr%3D%26ie%3DUTF-8%26group%3Dcomp.lang.python',
 
95
                    r'comp\.lang\.python.*What exactly are bound')
 
96
                # Test for Bug #1002547
 
97
                self.assertSnarfRegexp(
 
98
                    'http://groups.google.com/groups?q=supybot+is+the&'
 
99
                    'hl=en&lr=&ie=UTF-8&c2coff=1&selm=1028329672'
 
100
                    '%40freshmeat.net&rnum=9',
 
101
                    r'fm\.announce.*SupyBot')
 
102
            finally:
 
103
                conf.supybot.plugins.Google.groupsSnarfer.setValue(orig)
 
104
 
 
105
        def testConfig(self):
 
106
            orig = conf.supybot.plugins.Google.groupsSnarfer()
 
107
            try:
 
108
                conf.supybot.plugins.Google.groupsSnarfer.setValue(False)
 
109
                self.assertSnarfNoResponse(
 
110
                        'http://groups.google.com/groups?dq=&hl=en&lr=lang_en&'
 
111
                        'ie=UTF-8&oe=UTF-8&selm=698f09f8.0310132012.738e22fc'
 
112
                        '%40posting.google.com')
 
113
                conf.supybot.plugins.Google.groupsSnarfer.setValue(True)
 
114
                self.assertSnarfNotError(
 
115
                        'http://groups.google.com/groups?dq=&hl=en&lr=lang_en&'
 
116
                        'ie=UTF-8&oe=UTF-8&selm=698f09f8.0310132012.738e22fc'
 
117
                        '%40posting.google.com')
 
118
            finally:
 
119
                conf.supybot.plugins.Google.groupsSnarfer.setValue(orig)
 
120
 
 
121
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: