comparison test/test_db.py @ 158:86ebcf734a8e

Added more DB to test_db. Can skip tests where imports fail.
author Richard Jones <richard@users.sourceforge.net>
date Mon, 30 Jul 2001 03:45:56 +0000
parents 0791d13baea7
children d45384bc6420
comparison
equal deleted inserted replaced
157:1e5d95829851 158:86ebcf734a8e
1 # $Id: test_db.py,v 1.3 2001-07-29 07:01:39 richard Exp $ 1 # $Id: test_db.py,v 1.4 2001-07-30 03:45:56 richard Exp $
2 2
3 import unittest, os, shutil 3 import unittest, os, shutil
4 4
5 from roundup.backends import anydbm
6 from roundup.hyperdb import String, Link, Multilink, Date, Interval, Class, \ 5 from roundup.hyperdb import String, Link, Multilink, Date, Interval, Class, \
7 DatabaseError 6 DatabaseError
8 7
9 def setupSchema(db, create): 8 def setupSchema(db, create):
10 status = Class(db, "status", name=String()) 9 status = Class(db, "status", name=String())
16 status.create(name="resolved") 15 status.create(name="resolved")
17 Class(db, "user", username=String(), password=String()) 16 Class(db, "user", username=String(), password=String())
18 Class(db, "issue", title=String(), status=Link("status"), 17 Class(db, "issue", title=String(), status=Link("status"),
19 nosy=Multilink("user")) 18 nosy=Multilink("user"))
20 19
21 class DBTestCase(unittest.TestCase): 20 #class MyTestResult(unittest._TestResult):
22 def setUp(self): 21 # def addError(self, test, err):
23 class Database(anydbm.Database): 22 # print `err`
24 pass 23 # TestResult.addError(self, test, err)
25 # remove previous test, ignore errors 24 # if self.showAll:
26 if os.path.exists('_test_dir'): 25 # self.stream.writeln("ERROR")
27 shutil.rmtree('_test_dir') 26 # elif self.dots:
28 os.mkdir('_test_dir') 27 # self.stream.write('E')
29 self.db = Database('_test_dir', 'test') 28 # if err[0] is KeyboardInterrupt:
29 # self.shouldStop = 1
30
31 class MyTestCase(unittest.TestCase):
32 # def defaultTestResult(self):
33 # return MyTestResult()
34 def tearDown(self):
35 if self.db is not None:
36 self.db.close()
37 shutil.rmtree('_test_dir')
38
39 class DBTestCase(MyTestCase):
40 def setUp(self):
41 from roundup.backends import anydbm
42 # remove previous test, ignore errors
43 if os.path.exists('_test_dir'):
44 shutil.rmtree('_test_dir')
45 os.mkdir('_test_dir')
46 self.db = anydbm.Database('_test_dir', 'test')
30 setupSchema(self.db, 1) 47 setupSchema(self.db, 1)
31
32 def tearDown(self):
33 self.db.close()
34 shutil.rmtree('_test_dir')
35 48
36 def testChanges(self): 49 def testChanges(self):
37 self.db.issue.create(title="spam", status='1') 50 self.db.issue.create(title="spam", status='1')
38 self.db.issue.create(title="eggs", status='2') 51 self.db.issue.create(title="eggs", status='2')
39 self.db.issue.create(title="ham", status='4') 52 self.db.issue.create(title="ham", status='4')
114 # invalid multilink index 127 # invalid multilink index
115 ar(IndexError, self.db.issue.set, '1', title='foo', status='1', 128 ar(IndexError, self.db.issue.set, '1', title='foo', status='1',
116 nosy=['10']) 129 nosy=['10'])
117 130
118 def testRetire(self): 131 def testRetire(self):
119 ''' test retiring a node
120 '''
121 pass 132 pass
122 133
123 134
124 class ReadOnlyDBTestCase(unittest.TestCase): 135 class ReadOnlyDBTestCase(MyTestCase):
125 def setUp(self): 136 def setUp(self):
126 class Database(anydbm.Database): 137 from roundup.backends import anydbm
127 pass 138 # remove previous test, ignore errors
128 # remove previous test, ignore errors 139 if os.path.exists('_test_dir'):
129 if os.path.exists('_test_dir'): 140 shutil.rmtree('_test_dir')
130 shutil.rmtree('_test_dir') 141 os.mkdir('_test_dir')
131 os.mkdir('_test_dir') 142 db = anydbm.Database('_test_dir', 'test')
132 db = Database('_test_dir', 'test')
133 setupSchema(db, 1) 143 setupSchema(db, 1)
134 db.close() 144 db.close()
135 self.db = Database('_test_dir') 145 self.db = anydbm.Database('_test_dir')
136 setupSchema(self.db, 0) 146 setupSchema(self.db, 0)
137
138 def tearDown(self):
139 self.db.close()
140 shutil.rmtree('_test_dir')
141 147
142 def testExceptions(self): 148 def testExceptions(self):
143 # this tests the exceptions that should be raised 149 # this tests the exceptions that should be raised
144 ar = self.assertRaises 150 ar = self.assertRaises
145 151
147 ar(DatabaseError, self.db.status.create, name="foo") 153 ar(DatabaseError, self.db.status.create, name="foo")
148 ar(DatabaseError, self.db.status.set, '1', name="foo") 154 ar(DatabaseError, self.db.status.set, '1', name="foo")
149 ar(DatabaseError, self.db.status.retire, '1') 155 ar(DatabaseError, self.db.status.retire, '1')
150 156
151 157
158 class bsddbDBTestCase(DBTestCase):
159 def setUp(self):
160 from roundup.backends import bsddb
161 # remove previous test, ignore errors
162 if os.path.exists('_test_dir'):
163 shutil.rmtree('_test_dir')
164 os.mkdir('_test_dir')
165 self.db = bsddb.Database('_test_dir', 'test')
166 setupSchema(self.db, 1)
167
168 class bsddbReadOnlyDBTestCase(ReadOnlyDBTestCase):
169 def setUp(self):
170 from roundup.backends import bsddb
171 # remove previous test, ignore errors
172 if os.path.exists('_test_dir'):
173 shutil.rmtree('_test_dir')
174 os.mkdir('_test_dir')
175 db = bsddb.Database('_test_dir', 'test')
176 setupSchema(db, 1)
177 db.close()
178 self.db = bsddb.Database('_test_dir')
179 setupSchema(self.db, 0)
180
181
182 class bsddb3DBTestCase(DBTestCase):
183 def setUp(self):
184 from roundup.backends import bsddb3
185 # remove previous test, ignore errors
186 if os.path.exists('_test_dir'):
187 shutil.rmtree('_test_dir')
188 os.mkdir('_test_dir')
189 self.db = bsddb3.Database('_test_dir', 'test')
190 setupSchema(self.db, 1)
191
192 class bsddb3ReadOnlyDBTestCase(ReadOnlyDBTestCase):
193 def setUp(self):
194 from roundup.backends import bsddb3
195 # remove previous test, ignore errors
196 if os.path.exists('_test_dir'):
197 shutil.rmtree('_test_dir')
198 os.mkdir('_test_dir')
199 db = bsddb3.Database('_test_dir', 'test')
200 setupSchema(db, 1)
201 db.close()
202 self.db = bsddb3.Database('_test_dir')
203 setupSchema(self.db, 0)
204
205
152 def suite(): 206 def suite():
153 db = unittest.makeSuite(DBTestCase, 'test') 207 l = [unittest.makeSuite(DBTestCase, 'test'),
154 readonlydb = unittest.makeSuite(ReadOnlyDBTestCase, 'test') 208 unittest.makeSuite(ReadOnlyDBTestCase, 'test')]
155 return unittest.TestSuite((db, readonlydb)) 209
156 210 try:
211 import bsddb
212 l.append(unittest.makeSuite(bsddbDBTestCase, 'test'))
213 l.append(unittest.makeSuite(bsddbReadOnlyDBTestCase, 'test'))
214 except:
215 print 'bsddb module not found, skipping bsddb DBTestCase'
216
217 try:
218 import bsddb3
219 l.append(unittest.makeSuite(bsddb3DBTestCase, 'test'))
220 l.append(unittest.makeSuite(bsddb3ReadOnlyDBTestCase, 'test'))
221 except:
222 print 'bsddb3 module not found, skipping bsddb3 DBTestCase'
223
224 return unittest.TestSuite(l)
157 225
158 # 226 #
159 # $Log: not supported by cvs2svn $ 227 # $Log: not supported by cvs2svn $
228 # Revision 1.3 2001/07/29 07:01:39 richard
229 # Added vim command to all source so that we don't get no steenkin' tabs :)
230 #
160 # Revision 1.2 2001/07/29 04:09:20 richard 231 # Revision 1.2 2001/07/29 04:09:20 richard
161 # Added the fabricated property "id" to all hyperdb classes. 232 # Added the fabricated property "id" to all hyperdb classes.
162 # 233 #
163 # Revision 1.1 2001/07/27 06:55:07 richard 234 # Revision 1.1 2001/07/27 06:55:07 richard
164 # moving tests -> test 235 # moving tests -> test

Roundup Issue Tracker: http://roundup-tracker.org/