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 $
22
33import unittest , os , shutil
44
5- from roundup .backends import anydbm
65from roundup .hyperdb import String , Link , Multilink , Date , Interval , Class , \
76 DatabaseError
87
@@ -18,21 +17,35 @@ def setupSchema(db, create):
1817 Class (db , "issue" , title = String (), status = Link ("status" ),
1918 nosy = Multilink ("user" ))
2019
21- class DBTestCase (unittest .TestCase ):
20+ #class MyTestResult(unittest._TestResult):
21+ # def addError(self, test, err):
22+ # print `err`
23+ # TestResult.addError(self, test, err)
24+ # if self.showAll:
25+ # self.stream.writeln("ERROR")
26+ # elif self.dots:
27+ # self.stream.write('E')
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 ):
2240 def setUp (self ):
23- class Database (anydbm .Database ):
24- pass
41+ from roundup .backends import anydbm
2542 # remove previous test, ignore errors
2643 if os .path .exists ('_test_dir' ):
2744 shutil .rmtree ('_test_dir' )
2845 os .mkdir ('_test_dir' )
29- self .db = Database ('_test_dir' , 'test' )
46+ self .db = anydbm . Database ('_test_dir' , 'test' )
3047 setupSchema (self .db , 1 )
3148
32- def tearDown (self ):
33- self .db .close ()
34- shutil .rmtree ('_test_dir' )
35-
3649 def testChanges (self ):
3750 self .db .issue .create (title = "spam" , status = '1' )
3851 self .db .issue .create (title = "eggs" , status = '2' )
@@ -116,29 +129,22 @@ def testExceptions(self):
116129 nosy = ['10' ])
117130
118131 def testRetire (self ):
119- ''' test retiring a node
120- '''
121132 pass
122133
123134
124- class ReadOnlyDBTestCase (unittest . TestCase ):
135+ class ReadOnlyDBTestCase (MyTestCase ):
125136 def setUp (self ):
126- class Database (anydbm .Database ):
127- pass
137+ from roundup .backends import anydbm
128138 # remove previous test, ignore errors
129139 if os .path .exists ('_test_dir' ):
130140 shutil .rmtree ('_test_dir' )
131141 os .mkdir ('_test_dir' )
132- db = Database ('_test_dir' , 'test' )
142+ db = anydbm . Database ('_test_dir' , 'test' )
133143 setupSchema (db , 1 )
134144 db .close ()
135- self .db = Database ('_test_dir' )
145+ self .db = anydbm . Database ('_test_dir' )
136146 setupSchema (self .db , 0 )
137147
138- def tearDown (self ):
139- self .db .close ()
140- shutil .rmtree ('_test_dir' )
141-
142148 def testExceptions (self ):
143149 # this tests the exceptions that should be raised
144150 ar = self .assertRaises
@@ -149,14 +155,79 @@ def testExceptions(self):
149155 ar (DatabaseError , self .db .status .retire , '1' )
150156
151157
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+
152206def suite ():
153- db = unittest .makeSuite (DBTestCase , 'test' )
154- readonlydb = unittest .makeSuite (ReadOnlyDBTestCase , 'test' )
155- return unittest .TestSuite ((db , readonlydb ))
207+ l = [unittest .makeSuite (DBTestCase , 'test' ),
208+ unittest .makeSuite (ReadOnlyDBTestCase , 'test' )]
209+
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'
156216
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 )
157225
158226#
159227# $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+ #
160231# Revision 1.2 2001/07/29 04:09:20 richard
161232# Added the fabricated property "id" to all hyperdb classes.
162233#
0 commit comments