Code

- fix mailgw list of methods -- use getattr so that a derived class will
[roundup.git] / test / test_tsearch2.py
1 #
2 # Copyright (c) 2001 Bizar Software Pty Ltd (http://www.bizarsoftware.com.au/)
3 # This module is free software, and you may redistribute it and/or modify
4 # under the same terms as Python, so long as this copyright message and
5 # disclaimer are retained in their original form.
6 #
7 # IN NO EVENT SHALL BIZAR SOFTWARE PTY LTD BE LIABLE TO ANY PARTY FOR
8 # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
9 # OUT OF THE USE OF THIS CODE, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE
10 # POSSIBILITY OF SUCH DAMAGE.
11 #
12 # BIZAR SOFTWARE PTY LTD SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
14 # FOR A PARTICULAR PURPOSE.  THE CODE PROVIDED HEREUNDER IS ON AN "AS IS"
15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
17 #
18 # $Id: test_tsearch2.py,v 1.1 2004-12-16 22:22:55 jlgijsbers Exp $
20 import unittest
22 from roundup.hyperdb import DatabaseError
24 from db_test_base import DBTest, ROTest, config, SchemaTest, ClassicInitTest
26 from roundup.backends import get_backend, have_backend
28 class tsearch2Opener:
29     if have_backend('tsearch2'):
30         module = get_backend('tsearch2')
32     def setUp(self):
33         pass
35     def tearDown(self):
36         self.nuke_database()
38     def nuke_database(self):
39         # clear out the database - easiest way is to nuke and re-create it
40         self.module.db_nuke(config)
42 class tsearch2DBTest(tsearch2Opener, DBTest):
43     def setUp(self):
44         tsearch2Opener.setUp(self)
45         DBTest.setUp(self)
47     def tearDown(self):
48         DBTest.tearDown(self)
49         tsearch2Opener.tearDown(self)
51     def testFilteringIntervalSort(self):
52         # Tsearch2 sorts NULLs differently to other databases (others
53         # treat it as lower than real values, PG treats it as higher)
54         ae, filt = self.filteringSetup()
55         # ascending should sort None, 1:10, 1d
56         ae(filt(None, {}, ('+','foo'), (None,None)), ['4', '1', '2', '3'])
57         # descending should sort 1d, 1:10, None
58         ae(filt(None, {}, ('-','foo'), (None,None)), ['3', '2', '1', '4'])
60     def testTransactions(self):
61         # XXX: in its current form, this test doesn't make sense for tsearch2.
62         # It tests the transactions mechanism by counting the number of files
63         # in the FileStorage. As tsearch2 doesn't use the FileStorage, this
64         # fails. The test should probably be rewritten with some other way of
65         # checking rollbacks/commits.
66         pass
68 class tsearch2ROTest(tsearch2Opener, ROTest):
69     def setUp(self):
70         tsearch2Opener.setUp(self)
71         ROTest.setUp(self)
73     def tearDown(self):
74         ROTest.tearDown(self)
75         tsearch2Opener.tearDown(self)
77 class tsearch2SchemaTest(tsearch2Opener, SchemaTest):
78     def setUp(self):
79         tsearch2Opener.setUp(self)
80         SchemaTest.setUp(self)
82     def tearDown(self):
83         SchemaTest.tearDown(self)
84         tsearch2Opener.tearDown(self)
86 class tsearch2ClassicInitTest(tsearch2Opener, ClassicInitTest):
87     backend = 'tsearch2'
88     def setUp(self):
89         tsearch2Opener.setUp(self)
90         ClassicInitTest.setUp(self)
92     def tearDown(self):
93         ClassicInitTest.tearDown(self)
94         tsearch2Opener.tearDown(self)
96 from session_common import RDBMSTest
97 class tsearch2SessionTest(tsearch2Opener, RDBMSTest):
98     def setUp(self):
99         tsearch2Opener.setUp(self)
100         RDBMSTest.setUp(self)
101     def tearDown(self):
102         RDBMSTest.tearDown(self)
103         tsearch2Opener.tearDown(self)
105 def test_suite():
106     suite = unittest.TestSuite()
107     if not have_backend('tsearch2'):
108         print "Skipping tsearch2 tests"
109         return suite
111     # make sure we start with a clean slate
112     if tsearch2Opener.module.db_exists(config):
113         tsearch2Opener.module.db_nuke(config, 1)
115     # TODO: Check if we can run postgresql tests
116     print 'Including tsearch2 tests'
117     suite.addTest(unittest.makeSuite(tsearch2DBTest))
118     suite.addTest(unittest.makeSuite(tsearch2ROTest))
119     suite.addTest(unittest.makeSuite(tsearch2SchemaTest))
120     suite.addTest(unittest.makeSuite(tsearch2ClassicInitTest))
121     suite.addTest(unittest.makeSuite(tsearch2SessionTest))
122     return suite
124 # vim: set et sts=4 sw=4 :