Skip to content

Commit 0cf8786

Browse files
committed
fix: fix code to make tests of session and otks databases pass on windows
The existing code had a few issues: sessions_dbm.py: detect dumbdbm when used on windows python and properly delete session/otks databases so clear() works. make sure the Session/Otks.cache_db_type() is called even when the database is newly created. test/session_common.py: close session and otks database in teardown before deleting database directory to prevent errors from deleting open files on windows. test/test_sqlite.py: close the session and otks databases opened by SessionTest.setUp(self) so the salite session/otks database are closed before the new anydbm sessions databases are opened for testing the sqlite main db and anydbm as session/otks db. Again this causes deletion of database test directory to fail on windows as you can't delete open files.
1 parent 09ceb7d commit 0cf8786

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

roundup/backends/sessions_dbm.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ def clear(self):
4242
os.remove(path)
4343
elif os.path.exists(path+'.db'): # dbm appends .db
4444
os.remove(path+'.db')
45+
elif os.path.exists(path+".dir"): # dumb dbm
46+
os.remove(path+".dir")
47+
os.remove(path+".dat")
4548

4649
def cache_db_type(self, path):
4750
''' determine which DB wrote the class file, and cache it as an
@@ -142,7 +145,9 @@ def opendb(self, mode):
142145

143146
# new database? let anydbm pick the best dbm
144147
if not db_type:
145-
return anydbm.open(path, 'c')
148+
db = anydbm.open(path, 'c')
149+
self.cache_db_type(path)
150+
return db
146151

147152
# open the database with the correct module
148153
dbm = __import__(db_type)

test/session_common.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ def setUp(self):
4949
def tearDown(self):
5050
if hasattr(self, 'db'):
5151
self.db.close()
52+
if hasattr(self, 'sessions'):
53+
self.sessions.close()
54+
if hasattr(self, 'otks'):
55+
self.otks.close()
5256
if os.path.exists(config.DATABASE):
5357
shutil.rmtree(config.DATABASE)
5458

test/test_sqlite.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,10 @@ class anydbmSessionTest(sqliteOpener, SessionTest, unittest.TestCase):
229229
def setUp(self):
230230
SessionTest.setUp(self)
231231

232-
# redefine the session db's as redis.
232+
# redefine the session db's as anydbm
233+
# close the existing session databases before opening new ones.
234+
self.db.Session.close()
235+
self.db.Otk.close()
233236
self.db.config.SESSIONDB_BACKEND = "anydbm"
234237
self.db.Session = None
235238
self.db.Otk = None

0 commit comments

Comments
 (0)